First Steps With Docker

1. Install Docker Toolbox

Download and install the Docker Toolbox. This will install the Docker Quickstart Terminal, the Kitematic GUI client, the docker command, and a few other utilities.

The Docker Toolbox Installer for Mac OS X

2. Run Your First Image

Now that we’re ready to work with Docker, we can launch the Docker Quickstart Terminal and run our first image.

The Docker Quickstart Terminal greets us
$ docker run ubuntu:latest echo “hello world!”
Unable to find image ‘ubuntu:latest’ locally
latest: Pulling from library/ubuntu
d3a1f33e8a5a: Pull complete
c22013c84729: Pull complete
d74508fb6632: Pull complete
91e54dfb1179: Pull complete
library/ubuntu:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:73fbe2308f5f5cb6e343425831b8ab44f10bbd77070ecdfbe4081daa4dbe3ed1
Status: Downloaded newer image for ubuntu:latest
hello world!
$ docker run -it ubuntu:latest bash
root@0a76731e26fd:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

3. Build Your Own Image

The coolest aspect of Docker is that it lets you compose and build images at will, in order to create complex images that can be provisioned on the fly to power applications for your specific needs. The Dockerfile is the equivalent of a Makefile to build a Docker image. You can reuse existing images and specialize them, by installing applications, running commands, or deploying files.

FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
$ docker build -t docker-whale .
$ docker run -it docker-whale
The output of the docker-whale container

4. Publish Your Image

Now that we built the docker-whale image, we are ready to publish it to Docker Hub. To publish images to the Hub, we’ll have to sign up for an account first, but worry not: it can be created free of charge.

$ docker login
Username: <enter your username>
Password: <enter your password>
Email: <enter your email>
WARNING: login credentials saved in /Users/delphine/.docker/config.json
Login Succeeded
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker-whale latest cb6dccf1ca20 25 hours ago 274 MB
docker/whalesay latest fb434121fc77 3 months ago 247 MB
$ docker tag cb6dccf1ca20 claudiopro/docker-whale:latest
$ docker push claudiopro/docker-whale
Here’s our first image published on Docker Hub

Further Reading

I recommend the brilliant Self-Paced Training by Johnny Tu available on the Docker website. It is divided in three parts: Introduction, Fundamentals, and Operations. Each tutorial lasts around 1h, so they can be easily fit into a lunch break or the evening.

References

  1. Docker Docs — https://docs.docker.com/
  2. Docker Hub — https://hub.docker.com/
  3. Docker Self-Paced Training — https://training.docker.com/self-paced-training

--

--

Full stack web developer with a keen interest for the open web platform, privacy, security, and IoT. Former Amazonian, former IBMer. All views my own.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Claudio Procida

Claudio Procida

Full stack web developer with a keen interest for the open web platform, privacy, security, and IoT. Former Amazonian, former IBMer. All views my own.