Docker cheatsheet
fastai
Docker cheatsheet
Main ideas and docker file commands (based on this blog post).
Glossary
- Image: blueprint to build
- Container: instance of image
- Dockerfile: recipe for image, a text file
- Layer: modifications of the image
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-por-PwithrunVOLUME /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
CMDwill be executed
Build a Docker Image
docker build -t tutorial -f ./Dockerfile.gpu ./
(This builds an image not a container)
-t tutorial: name or tag-f ./Dockerfile.gpu: Dockerfile location./: context host directory, the relative path refrence point
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