Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

interactive docker build from dockerfile?

I want to use a Dockerfile to build an image. However, commands will need user input as they run. Currently, the build is not successful because docker exits on user input. I know I can use the -i -t options on docker run command but I want to do that on a Dockerfile. How is that possible?

like image 389
Keeto Avatar asked Jun 20 '14 20:06

Keeto


People also ask

Does docker build run Dockerfile?

The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in the specified PATH or URL . The build process can refer to any of the files in the context.

Can we create container from Dockerfile?

The docker container create (or shorthand: docker create ) command creates a new container from the specified image, without starting it. When creating a container, the docker daemon creates a writeable container layer over the specified image and prepares it for running the specified command.

What is the command to build image from Dockerfile?

With Dockerfile written, you can build the image using the following command: $ docker build . We can see the image we just built using the command docker images.


1 Answers

You can try with expect or a similar tool.

The easiest way to configure it is using the autoexpect tool, which lets you run the commands interactively and creates an expect script for you.

I couldn't get the rvmsudo stuff working (I haven't used it and didn't want to spend too much time with it) so I decided to use vi instead. First run autoexpect

$ autoexpect vi test

This will open vi and you can create or edit the file and save it. After exiting the vi you'll see your file test as well as an expect script script.exp.

You can then remove the test file and execute script.exp. It will recreate the same file using the same steps.

The autoexpect tool is great, but you may have to create a script from scratch if you need to have more control over what happens. E.g. if you don't want the script to work with the exact expected input.

like image 164
ivant Avatar answered Sep 21 '22 08:09

ivant