Getting started with Docker

Now that Docker is properly installed and configured, let's see how to use it. First, Docker manages all Linux distribution images that can be run. They are stored locally on the computer that runs these images. Retrieving a new image is done with the pull command, as can be seen in the following example:

$ docker pull hello-world

This will retrieve the hello-world image from the public Docker image registry (https://hub.docker.com/). The list of images available locally now contains the hello-world image, as can be seen in the following code:

$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 2cb0d9787c4d 2 weeks ago 1.85kB

This image can now be executed. A running image is called an instance. A Docker image can be instantiated several times, making several instances of the application able to run at the same time. As can be seen in the following example, an image is started with the run command:

$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. 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

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

The hello-world image was executed, and completed. The following list of running instances can be seen with the ps command:

$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e955b00349ff hello-world "/hello" About a minute ago
Exited (0) About a minute ago stoic_leavitt

The -a option displays the instances that are running, and also those that are not running anymore. This allows it to display the hello-world instance that is now completed. When instances are started without providing an explicit name, Docker generates one for us. This is why the instance was named stoic_leavitt. This stopped instance can be restarted with the start command. Should this instance run a daemon, it could be stopped with the stop command.

As can be seen in the following example, removing a stopped instance from the ps list is done with the rm command:

$ docker rm stoic_leavitt
stoic_leavitt

Now the ps command does not list stoic_leavitt anymore. However, the images command still contains the hello-world image: an instance has been removed, but not its image. Images can be removed with the rmi command (remove image), as demonstrated by the following code:

$ docker rmi 2cb0d9787c4d

The rmi command takes the image ID as a parameter, not the image name. From that point, executing another images command does not list the hello-world image anymore.

These few commands (pull, run, start, stop, rm, rmi) are enough to enable us to use Docker for many situations. Let's now start an S3 service running on Docker.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.151.220