Some of my notes about how I use Docker.

Create a Dockerfile:

FROM ubuntu

# Install whatever you need.
RUN apt-get update
RUN apt-get -y install apache2 php
# ...etc.

WORKDIR "/work"

# Start services that you need when you run the container. The last should be bash if you want to log in.
ENTRYPOINT service mysql start \
   && apachectl graceful \
   && /bin/bash

Create an image (tagged myimage):

docker build -t myimage .

View it and any others:

docker images

Remove an image:

docker rmi <leading-unique-part-of-image-id>

Run an image, mounting the current directory as /work (note that you can't specify the host-dir of the volume in the Dockerfile, so it has to be done at run-time). The port mapping is <host-port>:<container-port>

docker run -it --rm -v $PWD:/work -p81:80 myimage

Show existing containers:

docker ps -a

Remove a container:

docker rm <leading-unique-part-of-container-id>


Start a new MySQL container, which can be accessed at and which has its data in a local volume:

docker run -it -e MYSQL_ROOT_PASSWORD=pwd123 -p3305:3306 -v$PWD/mysqldata:/var/lib/mysql mysql

Note that because we're keeping local data, root's password is only set on the first set-up, and so can be left off in future commands.