This is the first article in a series about Docker and Docker tooling with the aim to give a foundation of developing with Docker.
This is a quick guide on how to get set up locally to develop with Docker. It assumes you have a basic understanding of what Docker and containerization is.
Concepts for Running Docker
There are a couple concepts important to understand that helped me a lot in getting up to speed:
Docker has two sides to it: a Docker client that can send commands to a Docker server (also referred to as the Docker host). The server is running the Docker daemon that will actually do the work. The daemon cannot run on Windows or Mac: it's Linux only. So to develop locally, you need a virtual machine (VM)1 to run the daemon and act as the server, and your Mac (or Windows)2 machine will act as the client, sending commands to build and run containers.
Here's an image taken from the Docker OSX installation docs that illustrates it well:
So for development, you need Docker (the client) installed on your computer and a VM to act as the server. Then you set some environment variables to point to the Docker server (the daemon runs on TCP port 2376 by default), and commands run on the client will be sent to the server. When you build, the build context is sent to the server, and then the server does all the building.
Fortunately, Docker has provided some tools to help you do all this: Docker Machine can provision a VM for you, and Docker Toolbox will install Docker, Docker Machine, VirtualBox (which can run VMs) and a few other tools.
After you download and install all those tools with the Toolbox, you can create a VM with Machine:
docker-machine -d virtualbox create default
default is the name you want to give the VM, and can be anything you want.)
That will set up a VM appropriate for Docker development and then you can run a command to set up your environment so the client will use the VM as the server:
eval $(docker-machine env default)
To test that it's working correctly, you can run the Docker
docker run hello-world
It will pull (download) the
hello world image if it isn't already downloaded on the server (which if you just set up a new Machine, it won't be) and if everything's working, print something like:
Hello from Docker. This message shows that your installation appears to be working correctly. (more content)...
Hopefully this will serve as a foundation to understand what's going on in subsequent articles, and to hopefully better follow along.