Docker Logo

Getting Started With Docker

Prerequisites

To check if the installation was successful, open up your favorite Terminal (Mac,Linux) or the Docker Terminal (Windows) and try running

$ docker version
Client: Docker Engine - Community
Version:           19.03.5
API version:       1.40
Go version:        go1.12.12
Git commit:        633a0ea
Built:             Wed Nov 13 07:22:34 2019
OS/Arch:           darwin/amd64
Experimental:      false

Server: Docker Engine - Community
Engine:
Version:          19.03.5
API version:      1.40 (minimum version 1.12)
Go version:       go1.12.12
Git commit:       633a0ea
Built:            Wed Nov 13 07:29:19 2019
OS/Arch:          linux/amd64
Experimental:     false
containerd:
Version:          v1.2.10
GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version:          1.0.0-rc8+dev
GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version:          0.18.0
GitCommit:        fec3683

This also ensures you can access the docker daemon.

Having a Docker Hub account makes it easier to share your containers with other researchers.

Let’s login into Docker Hub to be able to push images to your repository.

$ docker login
# Enter username/password

Note

If you do not have Docker installed on your laptop, you could also use https://training.play-with-docker.com/beginner-linux/

Working with Docker Hub images

  • Say hello from Docker

Let’s run a simple hello-world container using the * docker run * command

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:5f179596a7335398b805f036f7e8561b6f0e32cd30a32f5e19d17a3cda6cc33d
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:
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.

This simple command pulls the hello-world image from Docker Hub and prints the message.

  • To pull an image off Docker Hub use the docker pull command

Let’s make this easier by first pulling the image from Docker Hub

$ docker pull hello-world:latest
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:4df8ca8a7e309c256d60d7971ea14c27672fc0d10c5f303856d7bc48f8cc17ff
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
  • To verify the images are now available on your local machine, try:
$ docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
hello-world              latest              fce289e99eb9        11 months ago       1.84kB
  • Now run the container:
$ docker run hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.

Note: As indicated in the output, if no tag is specified the “latest” tag is pulled.

You could also try:

$ docker inspect hello-world
# shows more information about container image

Docker Core Commands

Command Usage
docker login Authenticate to Docker Hub using username and password
docker run Usage: docker run -it user/imagetag
docker build Usage: docker build -t username/imagetag . Build a docker image from a Dockerfile in the current working directory. -t to tag the image
docker images List all images on the local machine
docker tag Add a new tag to an image
docker pull Download an image from Docker Hub
docker push Usage: docker push username/imagetag Upload an image to Docker Hub
docker inspect Usage: docker inspect containerID Provide detailed information on constructs controlled by Docker
docker ps -a List all containers on your system
docker rmi Delete an image
docker rm Usage: docker rm -f [container name or ID] Delete a container -f optional to remove running container
docker stop Usage: docker stop [container name or ID] Stop a container

Getting more help with Docker

  • The command line tools are very well documented:
$ docker --help
# shows all docker options and summaries
$ docker COMMAND --help
# shows options and summaries for a particular command