Docker
Commands
basic:
- build an image from
Dockerfile:docker build -t <tag> . - run a container from image:
docker run -d --name <name> <tag> - save container as an image:
docker commit <container> <tag> - save image as tar:
docker save <tag> > /path/file.tar - load from tar:
docker load -i /path/file.tar - tag an image:
docker tag <image> <tag> - stop container:
docker stop <name> - start container and attach to it:
docker start -ai <name> - detach from container:
ctrl-p ctrl-q
clean up containers:
docker ps -a -q | xargs -n 1 -I {} docker rm {}clean up images:
docker rmi $( docker images | grep '<none>' | tr -s ' ' | cut -d ' ' -f 3)from 1.3:
docker exec [container] [command]from 1.4:
docker cp [container]:[path] [local-path]
Dockerfiles
always use dockerfile to build images, the build cache is very useful and super easy to make changes.
No Supervisord
each service should be in a standalone container, single responsibility principle.
Tips
- use docker virtual interface ip to access host (
ip addr show docker0) - when using
ufw, make sure to bind host port with explicit ip address (-p 172.17.42.1:3000:3000) - since
v1.2.0, use--restartflag to specify a restart policy (run --restart=always)