1. Links
  2. Install on Mac/OSx
  3. Removing containers and images and cleaning up
  4. Troubleshooting
  5. AWS Setup and Installation
  6. Quickstart
  7. Running Containers
  8. Connect to a running Container
  9. Disconnect
  10. Map local drive to volume
  11. Networking
  12. X11 Forwarding OSX
  13. Images


Visualizing Docker Containers and Images

Install on Mac/OSx

Download and install the latest Docker.dmg.

Removing containers and images and cleaning up

# Cleanup volumes
docker volume ls
docker volume ls -qf dangling=true
docker volume rm $(docker volume ls -qf dangling=true)

# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)


  • no space left on device

To fix, I removed the following file, and restarted docker

ls -lah ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2

AWS Setup and Installation

The "host" machine needs to have the docker daemon running. The docker-machine tool can be used to manage docker hosts. Here are the steps I use to create a new docker host machine in Amazon AWS.

Before creating a machine, you need to create a AWS VPC and a subnet.

Then, make sure your AWS credentials are available

export AWS_ACCESS_KEY_ID=<your id>
export AWS_SECRET_ACCESS_KEY=<your secret>

Use the following to create the machine.

NOTE: there's a issue where you must use security group name rather than id.

NOTE: also, I had to restart the machine once after creating it in order to connect to the docker daemon.

docker-machine create \
    --driver amazonec2 \
    --amazonec2-access-key $AWS_ACCESS_KEY_ID \
    --amazonec2-secret-key $AWS_SECRET_ACCESS_KEY \
    --amazonec2-vpc-id <your-vpc-id> \
    --amazonec2-subnet-id <your-subnet-id> \
    --amazonec2-region <region, ex: us-east-1> \
    --amazonec2-zone <zone, for example: a,b,c,d> \
    --amazonec2-security-group <your security group name> \
    --amazonec2-iam-instance-profile docker-role \
    <whatever name you want>


A Dockerfile is a specification for an image. Containers are instances of images.

The first step is to get the image you need. You can either get pre-built images using the pull command. Or use the build command to build custom images based on a Dockerfile.

Once you have an image, use the run command to start a new container.

Running Containers

To interact with a command line program (such as a shell or repl), use docker run -i -t <etc>. For example, here's the command I used to start a Haskell Hugs environment. This maps local directory to same directory on the server:

docker run -i -t -v /Users/dparoulek/code:/Users/dparoulek/code
erasmas/hugs98 hugs

Here's another example of running minecraft server

docker run -d -p 25565:25565 --name minecraft kitematic/minecraft

Connect to a running Container

Here's a way to interactively connect to running container:

docker exec -it <container name> bash


To disconnect from interactive container, use CTRL-P CTRL-Q.

Map local drive to volume

NOTE: Use absolute paths. I saw strangeness when I tried `-v .:/remote`

Here's how to move files from the container to the host (remember, when using aws, the host is the aws ec2 instance and NOT your local laptop):

docker run -rm --volumes-from survival -v /backup:/backup debian:wheezy tar cvf /backup/world.tar /data/world

Then, you can use docker-machine to get the file to your laptop:

scp docker-minecraft:/backup/world.tar .


Docker for Mac is different than docker-machine. I think Docker for Mac is basically a user-friendlier version of docker-machine. As of version 1.13.0, you can still use docker-machine.

When using Docker for Mac, the ip address is localhost as described here in Docker For Mac Networking.

X11 Forwarding OSX

I don't understand this 100%, but in order to get x11 forwarding working between docker and OSX:

  • Install socat. I used brew install socat
  • Install and Start XQuartz. I downloaded the dmg and installed.
  • Expose XQuartz socket file on TCP port 6000.
    socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
  • Run docker run -ti --rm -e DISPLAY= firefox