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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With