Computer scienceSystem administration and DevOpsDockerBasic commands

Run the "hello-world" docker container

4 minutes read

In this topic, we will launch a container with the hello-world image, one of the most popular images to start working with Docker. You can get this image from the Docker Hub and then launch it on your computer.

Check installation

To list available subcommands, run this command without parameters.

$ docker

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default
                           "/home/hyperskill/.docker")
  -c, --context string     Name of the context to use to connect to the
                           daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
...

Also, to make sure that Docker is installed on the OS you are using, you can run the command below and find out the version of Docker as well as verify the installation:

docker --version

Pull images

By default, there is no image on your computer after installation. That is, you need images to create a container. You can also pull them from various Docker repos.

With this command, you can pull any image from the Docker registry. After running the docker pull command, you can see how the chosen image is pulled from the registry to your computer. The time the pulling process takes depends on your internet speed.

$ docker pull hello-world

Using default tag: latest
latest: Pulling from library/hello-world
...

With the docker images command, you can list the docker images installed on your operating system.

$ docker images

REPOSITORY                                        TAG          IMAGE ID      CREATED        SIZE
docker.io/library/hello-world                     latest       d1165f221234  5 months ago   20.2 kB
...

Run container

Having images on the server or local computer, we can use the docker run command to create containers. All we have to do is enter the name of the image after the docker run command. This command creates a new container from the image we provided to it.

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

We can add certain parameters to the docker run command. Let's take a look at these parameters:

  • -d makes the container run in the background;
  • -w provides an execution directory inside the container.

For example, if we add the -d parameter to the command, the container will run in the background:

docker run -d hello-world

After running the docker run hello-world command, we will encounter the article specified on the image file's site, which means that we've launched a container from the hello-world Docker image.

Conclusion

In this topic, we've seen how to pull image files on Docker and run these image files. Learning these easy commands will help you with more complex commands that you will use in the future. We have taken our first step on a great adventure.

60 learners liked this piece of theory. 0 didn't like it. What about you?
Report a typo