- check that docker is working:
docker run hello-world
- prune images:
docker image prune -a
- prune containers:
docker container prune
- check
nvidia-docker2
is working (with CUDA 10.0 in base):docker run --rm --gpus all nvidia/cuda:10.0-runtime nvidia-smi
- build with
Dockerfile
:docker build -t your_image_name .
- run built image as container:
docker run --name your_container_name your_image_name
(for extra options see here) - kill running container:
docker kill your_container_name
use the -v
flag, You need to give the absolute local path or a volume name and map it to a directory within the container -v <source>:<target>
. See this stackoverflow post or this article on freecodecamp for more details.
docker run -it --rm -v $(pwd)/dir/to/share:/container/path/to/shared/dir --name your_container_name your_container_id
and instead of mounting your local directory, we can use docker volume, which is fully managed by docker... see this guide for more details
docker run --restart=always
Note that with this you cannot use the option --rm
. Credit to this stackoverflow post and the official doc
once in interactive mode it's kind of hard to exit without killing the container. The best way to watch a container is actually by combining watch
and docker logs
. For example:
watch -n 0.1 "docker logs --tail 30 your_container_name_or_id"
best to just run the base image interactively and try the command in bash:
docker run -it --rm {image:tag} /bin/bash
or to override an image's entry point:
docker run -it --rm --entrypoint /bin/bash {image:tag|image_id}