Docker Cheat Sheet

Commands

docker ps                           # List running instances
docker ps -a                        # List all instances
docker inspect <id>                 # Instance details
docker top     <id>                 # Instance processes
docker logs    <id>                 # Instance console log

docker run -i -t ubuntu /bin/bash   # New instance from image

docker start   <id>
docker restart <id>
docker stop    <id>
docker attach  <id>
docker rm      <id>

docker cp '<id>':/data/file .       # Copy file out of container

docker images                       # List locally stored images

Dockerfile Examples

Installing packages

FROM debian:wheezy
RUN apt-get update
RUN apt-get -y install python git

Adding users

RUN useradd jsmith -u 1001 -s /bin/bash

Defining work directories and environment

WORKDIR /home/jsmith/
ENV HOME /home/jsmith

Mounts

VOLUME ["/home"]

Opening ports

EXPOSE 22
EXPOSE 80

Start command

USER jsmith
WORKDIR /home/jsmith/
ENTRYPOINT bin/my-start-script.sh

Misc