-1

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.

aelesia
  • 184
  • 7
  • It seems, for a pre-existing container, once it's running, you need to add one more command: e.g. docker exec -it /bin/bash – nulldroid Nov 01 '21 at 09:19
  • Does this answer your question? [How to start a stopped Docker container with a different command?](https://stackoverflow.com/questions/32353055/how-to-start-a-stopped-docker-container-with-a-different-command) – Paolo Nov 01 '21 at 09:24
  • Why not delete and recreate the container when the process completes? – David Maze Nov 01 '21 at 11:14

1 Answers1

2

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...]

JongWon Lee
  • 145
  • 6