Home > Software engineering >  Is there any way to start a Docker container with an interactive terminal?
Is there any way to start a Docker container with an interactive terminal?

Time:11-02

Currently I start my docker container using:

docker run -it myimage

However I'm trying to create a base container then re-using the container instead of re-creating one.

docker create mycontainer:myimage
docker start --it mycontainer

I want to be able to do the above. To create it first, then start it in --it mode. However this doesn't seem to be a valid option. I've tried using -a or -i, but they both don't seem to work properly. The console gets messed up because it's trying to read from stdin but there's no input.

CodePudding user response:

Docker containers have three states.

enter image description here

docker create command creates a container from an image.

docker start command starts the container. there is no option to assign a virtual terminal(-t;-tty) for the container

To use the tty option, use the foreground mode of the docker run command or run the exec command in an already running container.

docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

  • Related