Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interactive command in Dockerfile

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:

  1. Where is the output of all the RUN commands in a Dockerfile?
  2. What solution is possible to interact with the aforementioned command? Right now the docker build command just gets stuck asking user for input in an infinite loop.
like image 527
ilya1725 Avatar asked Nov 28 '16 22:11

ilya1725


People also ask

What is interactive in docker?

Docker allows you to run a container in interactive mode. This means you can execute commands inside the container while it is still running. By using the container interactively, you can access a command prompt inside the running container.

What is the command to enter interactive console on docker?

If you need to start an interactive shell inside a Docker Container, perhaps to explore the filesystem or debug running processes, use docker exec with the -i and -t flags. The -i flag keeps input open to the container, and the -t flag creates a pseudo-terminal that the shell can attach to.


3 Answers

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

like image 128
user2915097 Avatar answered Oct 13 '22 21:10

user2915097


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?).

like image 34
johnharris85 Avatar answered Oct 13 '22 21:10

johnharris85


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
like image 20
nikojpapa Avatar answered Oct 13 '22 23:10

nikojpapa