Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to answer install question in dockerfile?

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?

like image 648
jimmy Avatar asked Sep 10 '18 12:09

jimmy


Video Answer


2 Answers

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"

like image 138
giankotarola Avatar answered Sep 21 '22 10:09

giankotarola


If you have multiple questions to answer :

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

The individual answers are separated by a \n character.

like image 32
Binita Bharati Avatar answered Sep 21 '22 10:09

Binita Bharati