How to answer install question in dockerfile?

2020-06-25 04:43发布

问题:

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?

回答1:

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"