How to setup a development environment with Docker

by Cornel, at 25 September 2015, category : Administration

Docker installation:

Docker runs natively on Linux, to use it on Mac OS or Windows you need to run it in a Virtual Machine. For this blog entry I will use running docker on Mac OS in VirtualBox. I recommend using brew to install it because it also takes care of updating it.

brew install docker docker-compose docker-machine
brew cask install virtualbox

If you want to do it by hand instead, follow the Tutorial at or

Start Docker:

After you installed docker-machine you need to create a Virtual Machine that runs the docker daemon inside a tiny Linux guest:

docker-machine create --driver=virtualbox --virtualbox-memory 2048 --virtualbox-cpu-count 2 dev

The output will look like:

Creating CA: /Users/cornel/.docker/machine/certs/ca.pem
Creating client certificate: /Users/cornel/.docker/machine/certs/cert.pem
Image cache does not exist, creating it at /Users/cornel/.docker/machine/cache...
No default boot2docker iso found locally, downloading the latest release...
Downloading to /Users/cornel/.docker/machine/cache/boot2docker.iso...
Creating VirtualBox VM...
Creating SSH key...
Starting VirtualBox VM...
Starting VM...
To see how to connect Docker to this machine, run: docker-machine env dev

Verify that the Virtual Machine is running:

docker-machine ls

The output of the command should show the generated Virtual Machine:

NAME   ACTIVE   DRIVER       STATE     URL                         SWARM
dev             virtualbox   Running   tcp://

Configure shell environment:

The local docker client that will access the docker daemon inside the Virtual Machine needs to know how it should access it. docker-machine can show you the needed configuration, execute:

docker-machine env dev

The command output depends on the detected shell that you used to execute the command:

set -x DOCKER_HOST "tcp://";
set -x DOCKER_CERT_PATH "/Users/cornel/.docker/machine/machines/dev";
# Run this command to configure your shell:
# eval (docker-machine env dev)

You can execute the given commands by hand or output the configuration file of your shell:

  • bash shell: ~/.bash_profile
  • fish shell: ~/.config/fish/

To test the setup, list all running docker containers with the command:

docker ps

Working with docker containers:

To see which docker containers are currently running:

docker ps

To connect into a container, use the container name shown by docker ps and the following command. Press enter after the command is executed once to see the actual shell. You have to exit the shell by pressing Ctrl+P+Q or closing the terminal, using Ctrl+D or exit as a command will shut down the container.

docker attach <containername>

A different way to attach to a container where you can exit the shell in a normal way:

docker exec -it <containername> /bin/bash

To see the log output from a container:

docker logs <containername>

You can watch the log output of a container with:

docker logs --tail=10 -f <containername>


Mounting a directory from outside into the docker container has performance issues on Mac OS:

comments powered by Disqus