Docker cheatsheet
Main ideas and docker file commands (based on this blog post).
Dockerfile commands
FROM ubuntu:18.04
: build image upon ubuntu base imageLABEL maintainer="Firstname Lastname email
: optioal metadataENV LANG=C.UTF-8 LC_ALL=C.UTF-8
: Environment variablesRUN apt-get update && apt-get install -y python-pip
: shell commands to runEXPOSE 7745
: open a port (e.g. for jupyter). Publises only if used-p
or-P
withrun
VOLUME /ds
:- mount externally mounted volumes (need to specify the mountpoint at container run/creation)
- data inside this won't be saved, but outide of it will
WORKDIR /ds
: starting point for relative file referencesCOPY hom* /mydir/
: copies new files and add them to the container's filesystem at a destination pathCMD ['/bin/bash']
:- run a bash shell to prevent closing the container
- only the last
CMD
will be executed
Build a Docker container from an Image
docker run -it --name container1 --net=host -v ~/docker_files/:/ds tutorial
-it
: interactive run--net=host
: bind ports to host-v /docker_files/:/ds
: Mount host directory to you as a volume : the mount detinationtutorial
: image name
Container-related commands
Open a terminal iteractively in the container1
container.
docker exec -it container1 bash
Save current state of container as new image (username is e.g. for DockerHub)
docker commit container1 username/image2name:tagname
List running containers
docker ps -a -f status=running
List images
docker images
Push image to registry
docker push username/image2name:tagname