14

I tried to install something using dockerfile. But when I run the command, I have to answer the question like following:

enter

6

72

My dockfile is like following, but seems not working.

FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y expect
RUN apt-get -y install software-properties-common 
RUN apt-add-repository ppa:ondrej/php
expect “Press [ENTER] to continue or Ctrl-c to cancel adding it. ” { send “\n” }
RUN apt-get -y install php7.1 php7.1-fpm 
expect “Please select the geographic area in which you live. ” { send “6\n” }
expect “Please select the city or region corresponding to your time zone. ” { send “72\n” }
RUN -y apt-get install nginx

Anyone tell me how to answer install question in dockerfile?

jimmy
  • 1,549
  • 5
  • 21
  • 38

2 Answers2

18

I tested your Dockerfile and didn't have to answer any question, but if you want to auto answer when you run a command, you can use yes (for "y" and "n" responses) or echo.

Ex:

yes | <YOUR COMMAND>

yes n | <YOUR COMMAND> "n" response

echo | <YOUR COMMAND> echo generate a new line (enter)

echo "some response" | <YOUR COMMAND> response with "some response"

giankotarola
  • 765
  • 7
  • 13
  • You're right. Seems like I get confused with the command yesterday. I found that my problem is more like other issue, would you mind look into my new question here? https://stackoverflow.com/questions/52272495/how-to-run-command-using-docker-compose – jimmy Sep 11 '18 at 09:18
  • How to handle multiple prompts? for apache2 it is asking for region and timezone. How to handle this in dockerfile? – Polaiah Bodeddula Aug 06 '21 at 05:09
  • Missing multi responses required :( !!! – Thư Sinh Sep 27 '21 at 02:15
  • For exemple of _expect_ in a dockerfile to choose european timezone : `RUN sudo 8 echo | apt-get install -yq expect` – JPBlanc Jul 21 '23 at 09:06
5

If you have multiple questions to answer :

printf "answer1\nanswer2\nanswer3" | <your_script.sh>

The individual answers are separated by a \n character.

Binita Bharati
  • 5,239
  • 1
  • 43
  • 24