Docker Community Forums

Share and learn in the Docker community.

Dockerfile how to answer install question from application

docker

(Dingit) #1

I would like to make a docker image based on a application that during its install asks you a bunch of yes or no question in regards to how you want the application installed…

how would a answer these with the dockerfile?

like the file would say

run apt-get install application
yes
yes
yes
no
yes
no

would the above example be correct? or would you need to something else?

i hope i explained myself i found it hard to put this down in text :smile:

Best regards

Casper
Ding IT


How to pass interactive response to RUN command in Dockerfile?
(slamp) #2

You can try to pipe the yes/no to your installation script.
RUN sh -c ‘/bin/echo -e “yes\nyes\nyes\nno\nyes\nno” | your_script’

or you can try too with expect

RUN apt-get install expect
ADD install_script
RUN install_script

where install_script is
#!/usr/bin/expect
set timeout 2
spawn "./your_script"
expect “Question 1 :” { send “yes\n” }
expect “Question 2 :” { send “no\n” }
interact


(Dingit) #3

Hi slamp,

Wouldn’t it also work with me pulling a image for say centos. make a docker centos using the image login and install the application the “old fashion” way and then create a new image based on that running one?


(slamp) #4

Yes you can do that.
To detach the tty without exiting the shell, use the escape sequence Ctrl-p + Ctrl-q. The container will continue to exist in a stopped state once exited.
Then commit your change:
docker commit docker_id docker_name_application