Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify in Dockerfile that the image is interactive?

I have created a docker container that runs a command line tool. The container is supposed to be interactive. Am I somehow able to specify in the Dockerfile that the container is always started in interactive mode?

For reference this is the dockerfile:

FROM ubuntu:latest

RUN apt-get update && apt-get -y install curl

RUN mkdir adr-tools && \
    cd adr-tools && \
    curl -L https://github.com/npryce/adr-tools/archive/2.2.0.tar.gz --output adr-tools.tar.gz && \
    tar -xvzf adr-tools.tar.gz && \
    cp */src/* /usr/bin && \
    rm -rf adr-tools

CMD ["/bin/bash"]

EDIT: I know of the -it options for the run command. I'm explicitly asking for a way to do this in the docker file.

EDIT2: This is not a duplicate of Interactive command in Dockerfile since my question addresses an issue with how arguments specified to docker run can be avoided in favor of specifying them in the Dockerfile whereas the supposed duplicate addresses an issue of interactive input during the build of the image by docker itself.

like image 707
SpaceTrucker Avatar asked Jul 17 '18 11:07

SpaceTrucker


People also ask

How do I run docker image in interactive mode?

Docker Container Interactive Mode for Redis Container We can first start a Redis Docker container in background using the below command. This will basically pull the Redis Docker image from Docker Hub and start up a container running the same. Next, we can get the id of the running container using the below command.

How do I specify the image tag in Dockerfile?

When you are trying to build an image using the docker build command, you can specify the tag along with the image name to build the image with that specific tag. You can use the −t flag to do so.

What keyword in a Dockerfile is used to specify the base image?

Most official Docker images have an ENTRYPOINT of /bin/sh or /bin/bash . Even if you do not specify ENTRYPOINT , you may inherit it from the base image that you specify using the FROM keyword in your Dockerfile.


2 Answers

Many of the docker run options can only be specified at the command line or via higher-level wrappers (shell scripts, Docker Compose, Kubernetes, &c.). Along with port mappings and network settings, the “interactive” and “tty” options can only be set at run time, and you can’t force these in the Dockerfile.

like image 147
David Maze Avatar answered Sep 30 '22 11:09

David Maze


You can use the docker run command.

docker build -t curly .
docker run -it curly curl https://stackoverflow.com

The convention is:

docker run -it IMAGE_NAME [COMMAND] [ARG...]

Where [COMMAND] is curl and [ARG...] are the curl arguments, which is https://stackoverflow.com in my example.

-i enables interactive process mode. You can't specify this in the Dockerfile.
-t allocates a pseudo-TTY for the container.

like image 26
Alexander Zeitler Avatar answered Sep 30 '22 11:09

Alexander Zeitler