Reputation: 4968
I'm trying to automate a creation of a development Docker image using docker build
command with appropriate Dockerfile
. One of the scripts that I need to run in a RUN
command wants the user to click through and read their license agreement. Thus there are two questions:
RUN
commands in a Dockerfile
?docker build
command just gets stuck asking user for input in an infinite loop.Upvotes: 36
Views: 72126
Reputation: 9576
You could use a tool like expect
to automate the user interaction.
expect
to your image (preferably a build step because you will not need it later). E.g.RUN apt update && apt install -yq expect
#!/usr/bin/env expect
set timeout 10
spawn some_program_that_requires_interaction.sh
expect "Some string that we want to wait for"
# send newline, simulating pressing enter:
send -- "\r"
expect eof
COPY my_expect_script .
RUN sh my_expect_script
This is totally untested, and it's difficult to know how well it'll work with your specific scenario. Expect
doesn't work so well when curses is involved (or any kind of CLI UI that plays around with cursor position), so your mileage may vary.
Upvotes: 2
Reputation: 2842
To see output of all commands during build, if they are not showing up in enough detail for you, try:
docker build --progress=plain --no-cache -t yourTag .
Upvotes: 1
Reputation: 670
You can use the technique here:
(echo "initial command" && cat) | some_tool
Or, if multiple stages use printf
and concat with \n
:
(printf "cmd1\ncmd2" && cat) | some_tool
Upvotes: 5
Reputation: 32216
You can also do it in several steps, begin with a Dockerfile with instructions until before the interactive part. Then
docker build -t image1 .
Now just
docker run -it --name image2 image1 /bin/bash
you have a shell inside, you can do your interactive commands, then do something like
docker commit image2 myuser/myimage:2.1
The doc for docker commit
https://docs.docker.com/engine/reference/commandline/commit/
you may need to specify a new CMD or ENTRYPOINT, as stated in the doc
Commit a container with new CMD and EXPOSE instructions
For example some docker images using wine do it in several steps, install wine, then launch and configure the software launched in wine, then docker commit
Upvotes: 27
Reputation: 18976
The output of RUN
commands is shown in your terminal during the build. The Docker build process is completely non-interactive, so you must find some way of either auto-accepting the terms (almost every piece of software allows this, think apt-get install -y...
) or using some shell wizardry to echo the acceptance back to the process or whatever (Expect maybe?).
Upvotes: 16