1. Links
  2. Setup and Installation
  3. Quickstart
  4. Running Containers
  5. Connect to a running Container
  6. Disconnect
  7. Map local drive to volume
  8. X11 Forwarding OSX


Visualizing Docker Containers and Images

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 .

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