Created
March 28, 2017 06:25
-
-
Save alexcpn/d051558552f8fe4b267c7d1e1461065f to your computer and use it in GitHub Desktop.
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
Good Reference | |
https://blog.jayway.com/2015/03/21/a-not-very-short-introduction-to-docker/ | |
Whats with Images and Containers | |
docker images | |
REPOSITORY TAG IMAGE ID CREATED SIZE | |
nvidia-cuda-8 small 291c10e49fa1 18 hours ago 2.077 GB | |
nvidia-cuda-8 latest 2dd3d3d2a864 46 hours ago 2.077 GB | |
registry 2 047218491f8c 2 weeks ago 33.2 MB | |
nvidia/cuda latest 1cce8839a2c5 3 weeks ago 1.622 GB | |
ubuntu 16.04 0ef2e08ed3fa 3 weeks ago 130 MB | |
START a container | |
alex@alex-Lenovo-G400s-Touch:~$ docker run -ti ubuntu:16.04 bash | |
root@dfee57fd23d4:/# | |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
dfee57fd23d4 ubuntu:16.04 bash" 25 seconds ago Up 24 seconds tiny_chandrasekhar | |
Modify a container | |
alex@alex-Lenovo-G400s-Touch:~$ docker run -ti ubuntu:16.04 bash | |
root@dfee57fd23d4:/# pwd | |
/ | |
root@dfee57fd23d4:/# mkdir alex | |
Save Container a new image | |
root@dfee57fd23d4:/# alex@alex-Lenovo-G400s-Touch:~$ docker ps -l -q | |
dfee57fd23d4 | |
alex@alex-Lenovo-G400s-Touch:~$ docker commit dfee57fd23d4 mytestubuntu:16.04 | |
sha256:9a3d7a486799514e6fdbc63792e4588459d4fde06991f6961e54b76238482695 | |
alex@alex-Lenovo-G400s-Touch:~$ | |
alex@alex-Lenovo-G400s-Touch:~$ docker images | |
REPOSITORY TAG IMAGE ID CREATED SIZE | |
mytestubuntu 16.04 9a3d7a486799 About a minute ago 130 MB | |
nvidia-cuda-8 small 291c10e49fa1 18 hours ago 2.077 GB | |
nvidia-cuda-8 latest 2dd3d3d2a864 46 hours ago 2.077 GB | |
registry 2 047218491f8c 2 weeks ago 33.2 MB | |
nvidia/cuda latest 1cce8839a2c5 3 weeks ago 1.622 GB | |
ubuntu 16.04 0ef2e08ed3fa 3 weeks ago 130 MB | |
Docker Stop a Container | |
docker stop dfee57fd23d4 | |
alex@alex-Lenovo-G400s-Touch:~$ docker diff dfee57fd23d4 | |
A /alex | |
C /root | |
A /root/.bash_history | |
Docker Start and Check | |
alex@alex-Lenovo-G400s-Touch:~$ docker run -ti mytestubuntu:16.04 bash | |
root@e97976c736a1:/# ls | |
alex bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var | |
r | |
Dokcer map a port | |
# Publish container port 80 on port 8080 on the localhost interface on the Host | |
$ docker run -p 127.0.0.1:8080:80 nginx | |
Docker map a device | |
docker --device /dev/nvidia0:/dev/nvidia0 --device /dev/nvidiactl:/dev/nvidiactl --device /dev/nvidia-uvm:/dev/nvidia-uvm nvidia-cuda-8 | |
Docker Create a Image | |
Dockerfile | |
FROM ubuntu:16.04 | |
MAINTAINER Taken from template from :Regan <http://stackoverflow.com/questions/25185405/using-gpu-from-a-docker-container> | |
RUN apt-get update && apt-get install -y build-essential && \ | |
apt-get --purge remove -y nvidia* && \ | |
apt-get install module-init-tools -y | |
ADD nvidia-installers /tmp/nvidia && \ | |
# > Get the install files you used to install CUDA and the NVIDIA drivers on your host | |
RUN /tmp/nvidia/NVIDIA-Linux-x86_64-375.39.run -s -N --no-kernel-module && \ | |
# Install the driver. | |
RUN rm -rf /tmp/selfgz7 && \ | |
# For some reason the driver installer left temp files when used during a docker build (i don't have any explanation why) and the CUDA installer will fail if there still there so we delete them. | |
RUN /tmp/nvidia/cuda_8.0.61_375.26_linux.run -silent && \ | |
# > CUDA driver installer. | |
# > Delete installer files. | |
RUN rm -rf /temp/* | |
RUN export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64 | |
# Add CUDA library into your PATH | |
RUN touch /etc/ld.so.conf.d/cuda.conf | |
# Update the ld.so.conf.d directory | |
RUN mkdir ~/object-detect-svc | |
#ADD file:///home/alex/Coding/NASProject/base_services/object-detect-svc/build/objectDetectTest ~/object-detect-svc/ | |
# To run this you need to invoke like | |
# --device /dev/nvidia0:/dev/nvidia0 --device /dev/nvidiactl:/dev/nvidiactl --device /dev/nvidia-uvm:/dev/nvidia-uvm | |
CMD nvidia-smi | |
Remember | |
Since every command in the Dockerfile creates a new layer it is often better to run similar commands together. Group the commands with and and split them over several lines for readability. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment