Skip to content

Instantly share code, notes, and snippets.

@hcs42
Created November 27, 2014 18:09
Show Gist options
  • Save hcs42/f6fbea4105b8cdaf1d9d to your computer and use it in GitHub Desktop.
Save hcs42/f6fbea4105b8cdaf1d9d to your computer and use it in GitHub Desktop.
Docker notes
Container states
non-existant
running
stopped
paused
Image info
docker images # list images
Image operations
docker pull IMAGE
docker rmi IMAGE
docker build --rm -t hcs42/myproject:v1 . # new image
Container info
docker ps [-a] # list containers
docker top CONTAINER
docker logs [-f] CONTAINER
docker port CONTAINER PRIVATE_PORT
Container operations
docker run IMAGE CMD... # non-existant -> running (image -> container)
docker stop CONTAINER # running -> stopped
docker start CONTAINER # stopped -> running
docker pause CONTAINER # running -> paused
docker unpause CONTAINER # paused -> running
docker rm CONTAINER # stopped -> non-existant
docker commit CONTAINER IMAGE # container -> image
docker run parameters
--name NAME
-a # Attach
-d # Detached
-e ENVVAR=VALUE
-p 127.0.0.1:5000:5000
-u USER
docker run examples
docker run ubuntu:14.04 /bin/echo 'Hello World'
docker run -t -i ubuntu:14.04 /bin/bash
docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello; sleep 1; done"
docker run -d -P training/webapp python app.py
docker run -d -p 5000:5000 training/webapp python app.py
docker run -d -p 127.0.0.1:5000:5000 training/webapp python app.py
docker run -d -p 127.0.0.1:5000:5000/udp training/webapp python app.py
Check disk space used by images:
sudo sh -c "du -sm /var/lib/docker/aufs/diff/*"
Dockerfile: https://docs.docker.com/reference/builder/
FROM ubuntu:14.04
RUN apt-get -qq update
ADD <file> <path_in_container>
EXPOSE <port>
USER <username>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment