Skip to content

Instantly share code, notes, and snippets.

@StevenPuttemans
Last active May 31, 2018 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenPuttemans/67f85e34e288787d2a25c3e54b3a7fde to your computer and use it in GitHub Desktop.
Save StevenPuttemans/67f85e34e288787d2a25c3e54b3a7fde to your computer and use it in GitHub Desktop.
docker-commands

Overview of frequently used docker command

Running dockers

Run your docker with a specific executable and then shut down: sudo nvidia-docker run --rm nvidia/cuda nvidia-smi

Keep running your docker with bash access: sudo nvidia-docker run -ti --rm nvidia/cuda /bin/bash

Building your own docker file

  1. Start by creating a Dockerfile inside a folder where you want to build your docker image
  2. Go to NVIDIA docker hub: https://hub.docker.com/r/nvidia/cuda/ and select yourself a useful configuration
  3. Open up your Dockerfile to the one side and a terminal on the other side
  4. In the Dockerfile, start by
  • Adding the first line: FROM nvidia/cuda:8.0-cudnn5-devel where you replace the flavour after : with your choice
  • Make sure it ends with: CMD /bin/bash
  • Each command that works in your terminal (see below), can be added, with RUN before it
  • The cd-command is replaced by WORKDIR prefix
  1. Start up a basis docker in your terminal using the command above, starting from an NVIDIA config
  2. Experiment and fill in your Dockerfile
  3. Once you are done, run in the folder with your file: sudo docker build . -t name:flavour

Making a folder accessible inside your docker

  1. Create a shell script
#!/bin/bash

sudo nvidia-docker run -ti --rm \
-v /home/eavise-3frog/Desktop/test/data:/data \
name:flavor /bin/bash
  1. Make sure that the -v option links an external location to an internal mount point where you can edit with sudo rights

Delete redundant docker content

Removing specific docker images

  • See all images: sudo docker images
  • Remove images: sudo docker rmi imageID

Look at the running containers

  • sudo docker ps -a
  • sudo docker rm containerID

Delete all containers that have been exited sudo docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs sudo docker rm

Add your user with sude rights for docker, so that you do not need sudo rights

sudo addgroup eavise-3frog docker

Visualize the output of your docker container --> X11 support

Make a bash script that containts the following lines of code

#!/bin/bash

xhost +SI:localuser:root

nvidia-docker run -ti --rm  \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
container:flavor /bin/bash

xhost -SI:localuser:root

And then all graphical output will not render issues.

@StevenPuttemans
Copy link
Author

For the OpenCV docker I am creating

-WITH_TBB=ON -CUDA_ARCH_BIN=6.1 -CUDA_ARCH_PTX=6.1 -ENABLE_IMPL_COLLECTION=ON

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment