Docker Hello World

What Is Docker?

According to Wikipedia, Docker is a computer program that performs operating-system-level virtualization, also known as “containerization”.

Docker images are analogous to virtual machine images, but they can be much smaller than traditional virtual machine images, because instances of Docker images (which are called “containers”) usually only need to run one particular type of service or process.

Running Docker’s Hello World

Depending on your operating system and the way you install Docker, you may need to manually launch the Docker application / service after installation, before being able to run docker commands.

Try running pulling and running Docker’s hello-world image:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest

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

Listing Docker Images Stored Locally

We can run the docker image ls command to list the Docker images stored locally:

$ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        2 months ago        1.84kB

In this case, we only have one Docker image. It was pulled from DockerHub (i.e. downloaded from DockerHub), which we could have done by typing:

$ docker pull hello-world

However the docker run command above pulled the image automatically, and then created a container (instance) of that image and ran the container, resulting in the Hello from Docker! message shown above.

Listing Running and Stopped Docker Containers

So if a container was created, is it still running? We can find out by running:

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

In this case, docker ps shows that no containers are currently running. To list all containers, included those which have stopped running, we can run:

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                         PORTS               NAMES
636651c57ab7        hello-world         "/hello"            About an hour ago   Exited (0) About an hour ago                       inspiring_goldwasser

which shows us that a container was created from the hello-world image, and that it exited with a (0) (success) status code.

As we no longer need this stopped container, we can remove it, using its CONTAINER ID:

$ docker rm 636651c57ab7

Tagging Docker Images and Pushing to DockerHub

Given an existing image, e.g. this one:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        2 months ago        1.84kB

we can create one or more new tags for it, and push the tags to DockerHub:

$ docker tag fce289e99eb9 jameswettenhall/hello-world:1.0
$ docker tag fce289e99eb9 jameswettenhall/hello-world:latest
$ docker login -u jameswettenhall
$ docker push jameswettenhall/hello-world:1.0
$ docker push jameswettenhall/hello-world:latest

Now the image tags are available on DockerHub at: https://cloud.docker.com/repository/docker/jameswettenhall/hello-world