Docker create and start command

Docker image basically consists of two thing:

  • A File system snapshot
  • A Startup Command

What is docker create command?

Docker create command is responsible for creating a filesystem snapshot for a container. Example:

docker create hello-world

What is a docker start command?

Docker start command runs a startup command and starts a container. Example:

# create a container with file system snapshot
# and output a container id
docker create hello-world

# start existing container with id
docker start 997497e3241226c004b946a3aede06d03894ca279a18549c1e9a5347e7e63efe

Docker start command options:

Option Description
-a Start a container and attach input and output stream

If you run docker start command with -a option it attaches stdin and stdout to our container so that it can display the output of the container process.

Let's take an example:

# create a container with file system snapshot
# and output a container id
docker create hello-world

# start existing container with id
docker start -a 997497e3241226c004b946a3aede06d03894ca279a18549c1e9a5347e7e63efe

This time when you run above commands you will be able to see container output on your terminal.

What is docker run command?

Docker run is basically combination of following two commands:

  • docker start <image-name>
  • docker start -a <container-id>

To learn more in depth about this command checkout my following tutorial:

Docker Run Command