Last active
July 19, 2018 11:56
-
-
Save victorhcm/378b98feb23759ac1f30 to your computer and use it in GitHub Desktop.
(small) docker cheat sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################# | |
# Authors: Keiller Nogueira, Victor de Melo | |
################################################################################# | |
# nvidia-docker seems more stable now and several images are starting to adopt it (including | |
# [kaixhin](https://github.com/NVIDIA/nvidia-docker/issues/85). | |
# hence, we suggest to use it instead, as it solves a few issues with gpu passthrough. | |
# usage: it is only required when creating a container, i.e, with `run` and related arguments | |
# you're not required to provide $DOCKER_NVIDIA_DEVICES as it will find the devices itself | |
#================================================================================ | |
# PARA CRIAR UM NOVO CONTAINER DOCKER | |
# Versões mais recentes do nvidia-docker: | |
docker run --runtime=nvidia --rm -it cmupcl/openpose:gpu /bin/bash | |
# Antigo: USANDO nvidia-docker (automatically exports GPU devices) | |
nvidia-docker run --name NOME_DO_CONTAINER -v /mnt/user:/home/ -ti kaixhin/cuda-caffe /bin/bash | |
# --name será o nome do container que irá criar | |
# -v é o mapeamento de diretório, para acessar pastas do host no container | |
# OU, definindo manualmente | |
# PARA DEFINIR OS DEVICES (GPUs) | |
# DEVE SER EXECUTADO SOMENTE A PRIMEIRA VEZ!!!!!!!!!!! VALIDAR (echo $DOCKER_NVIDIA_DEVICES) SE JÁ EXISTE NO SISTEMA, ANTES DE EXECUTAR!! | |
DOCKER_NVIDIA_DEVICES=" | |
--device /dev/nvidia0:/dev/nvidia0 | |
--device /dev/nvidia1:/dev/nvidia1 | |
--device /dev/nvidia2:/dev/nvidia2 | |
--device /dev/nvidiactl:/dev/nvidiactl | |
--device /dev/nvidia-uvm:/dev/nvidia-uvm" | |
# IF SOME INTERFACES /dev/nvidia* ARE MISSING, run nvidia-smi and deviceQuery, then they will appear | |
# NO CASO, A IMAGEM tleyden5iwx/caffe-gpu JÁ TEM O CAFFE INSTALADO (/opt/caffe/). LOGO, É SÓ USAR | |
docker run --name NOME_DO_CONTAINER -v /mnt/user:/home/ -ti $DOCKER_NVIDIA_DEVICES kaixhin/cuda-caffe /bin/bash | |
# GUI RUDIMENTARY SUPPORT, add the following exports when instantiating (docker run) a container | |
-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY | |
# source: http://stackoverflow.com/a/27162721/957997 | |
#OR | |
touch /tmp/.docker.xauth | |
XSOCK=/tmp/.X11-unix | |
XAUTH=/tmp/.docker.xauth | |
xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - | |
docker run -ti -v $XSOCK:$XSOCK -v $XAUTH:$XAUTH -e XAUTHORITY=$XAUTH xeyes | |
docker run --rm -v $XSOCK:$XSOCK -v $XAUTH:$XAUTH -e DISPLAY=unix$DISPLAY -e XAUTHORITY=$XAUTH -ti victorhcm/opencv /bin/bash | |
# http://stackoverflow.com/a/25280523/957997 | |
# check this one too: http://stackoverflow.com/a/25334301/957997 | |
# seems simpler | |
# ==================================================================== | |
#PARA INICIAR UM CONTAINER | |
docker start NOME_DO_CONTAINER | |
#PARA DAR ATTACH A UM CONTAINER (SE DEMORAR MUITO, DÊ UM CTRL+C) | |
docker attach NOME_DO_CONTAINER | |
#VALIDAR QUAIS CONTAINERS ESTÃO ATIVOS | |
docker ps | |
#LISTAR TODOS OS CONTAINERS | |
docker ps -a | |
#PARA SAIR DO CONTAINER E DEIXA-LO EM EXECUCAO | |
ctrl+p ctrl+q | |
# JUPYTER PASSTHROUGH | |
$ sudo docker run \ | |
-it \ | |
-p 0.0.0.0:80:8888 \ | |
-e "USE_HTTP=1" -e "PASSWORD=" \ | |
-v /home/ganon/Downloads/host_folder:/docker_folder \ | |
ipython/scipyserver | |
# or | |
docker run -d -p 8888:8888 -v /notebook:/notebook xblaster/tensorflow-jupyter | |
############################################################################### | |
# Matlab docker container | |
############################################################################### | |
nvidia-docker run --name raphael-matlab -v /usr/local/MATLAB/MATLAB_Production_Server/R2015a:/usr/local/MATLAB/from-host -v ~/matlab-logs:/var/log/matlab --mac-address="host:mac:address" -ti --entrypoint=/bin/bash $DOCKER_NVIDIA_DEVICES ninjaben/matlab-support -i | |
############################################################################### | |
# CONFIGURING JUPYTER | |
############################################################################### | |
# Dockerfile | |
FROM foo/bar | |
RUN pip install jupyter && \ | |
mkdir -p -m 700 /root/.jupyter/ && \ | |
echo "c.NotebookApp.ip = '*'" >> /root/.jupyter/jupyter_notebook_config.py | |
# Add Tini. Tini operates as a process subreaper for jupyter. This prevents | |
# kernel crashes. | |
ENV TINI_VERSION v0.6.0 | |
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini | |
RUN chmod +x /usr/bin/tini | |
ENTRYPOINT ["/usr/bin/tini", "--"] | |
EXPOSE 8888 | |
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0"] | |
# End Dockerfile | |
# Now, access it through the ip (didn't work using the hostname) | |
# REFERENCES: | |
# Also, need to add (https://hub.docker.com/r/jupyter/notebook/~/dockerfile/) to bind to any IP: | |
mkdir -p -m 700 /root/.jupyter/ && \ | |
echo "c.NotebookApp.ip = '*'" >> /root/.jupyter/jupyter_notebook_config.py | |
## Jupyter crashing | |
# Using jupyter notebook as a Docker CMD results in kernels repeatedly crashing, likely due to a lack of PID reaping. To avoid this, use the tini init as your Dockerfile ENTRYPOINT: | |
# Add Tini. Tini operates as a process subreaper for jupyter. This prevents | |
# kernel crashes. | |
ENV TINI_VERSION v0.6.0 | |
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini | |
RUN chmod +x /usr/bin/tini | |
ENTRYPOINT ["/usr/bin/tini", "--"] | |
EXPOSE 8888 | |
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0"] | |
# http://jupyter-notebook.readthedocs.io/en/latest/public_server.html | |
# Adding password and enabling https | |
# https://github.com/jupyter/docker-stacks/blob/master/base-notebook/jupyter_notebook_config.py | |
# (404) https://github.com/jupyter/docker-stacks/blob/master/minimal-notebook/jupyter_notebook_config.py | |
############################################################################### | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment