There are a few ways to launch a container. You may
have noticed that the create, start, and run commands
seem very similar. The create command is used to
instantiate a container from an image but does not start
the container. Think of it as preloading a container that
you can run later. The start command starts up the
loaded container and allows it to execute. The run
command, on the other hand, creates and starts the
container as a single command. Example 13-3 provides a
quick example of how to launch a sample container with
the run command.
Example 13-3 Docker Hello World
Click here to view code image
$ docker run hello-world
Unable to find image 'hello-world:latest'
locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest:
sha256:4df8ca8a7e309c256d60d7971ea14c27672fc0d10c5f303856d7bc48f8cc17ff
Status: Downloaded newer image for hello-
world:latest
Hello from Docker!
This message shows that your installation
appears to be working correctly.
To generate this message, Docker took the
following steps:
- The Docker client contacted the Docker
daemon. - The Docker daemon pulled the "hello-world"
image from the Docker Hub.
(amd64) - The Docker daemon created a new container
from that image which runs the
executable that produces the output you are
currently reading. - The Docker daemon streamed that output to
the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an
Ubuntu container with:
$ docker run -it ubuntu bash