Skip to content

shumailaahmed/Docker_example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Docker_example

practicing docker tutorial

Installation

How to install 'Docker-ce'

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
## Ubuntu 16.04
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
## Ubuntu 18.04
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce

### check the installation
docker --version

### temperary solution
sudo chmod 666 /var/run/docker.sock
### permanent solution
sudo usermod -a -G docker $USER
sudo service docker restart

How to install nvidia-docker to use nvidia setting in dockers

distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker

### check the installation
docker run --rm --gpus all nvidia/cuda:10.1-base nvidia-smi

How to install 'ROS docker image'

docker pull ros:kinetic-ros-base-xenial

How to install 'pyTorch 1.3 docker image'

docker pull pytorch/pytorch:1.3-cuda10.1-cudnn7-devel

Command Practice

easy tutorial with docker (1), easy tutorial with docker (2)

docker images

  • check installed images
docker images

docker pull

docker search ubuntu
docker pull ubuntu  # default tag: latest
## OR other version of ubuntu
docker pull ubuntu:xenial

docker ps

  • check existing containers
docker ps -a
  • check only running containers
docker ps

docker run

  • launch new container with image
# docker run <options> <image> <command>
docker run -it --rm ubuntu /bin/bash

# in another host terminal
docker ps -a
docker ps

docker run -it --name hello ubuntu /bin/bash

docker start/stop/attach/restart

  • docker can be run in back/foreground
# docker start/stop/attach/restart <container>
docker start hello   ## if you run this command, you can run docker container in background
docker attach hello  ## connecting standard input(stdin) and standard output(stdout) to a running container

docker exec

  • it can execute a command inside a container from outside
  • typically used to connect another terminal to a container
docker exec -it hello /bin/bash

docker inspect

  • check container information (ip, port, etc.)
# docker inspect <container>
docker inspect hello

docker cp

  • Copy file to/from container
touch hello.txt
# docker cp <container>:<docker-path> <host-path>
# docker cp <host-path> <container>:<docker-path>
docker cp ./hello.txt hello:/home
docker cp hello:/home/hello.txt ../

docker commit

  • create an image of changes made to a container
# docker commit <container> <repository>/<image>:<tag>
docker commit hello jjimin/ubuntu:1.0

Examples and Tips

Example of docker run command

### (1)
docker run -it --rm -p 2000-2002:2000-2002 --gpus all -e NVIDIA_VISIBLE_DEVICES=0 \
-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY \
--name ros-carla-01 \
carla-ros-bridge:custom-01 \
/bin/bash

### (2)
docker run -it --rm -p 2000:2000 --gpus all -e NVIDIA_VISIBLE_DEVICES=0 \
-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY \
--name pytorch-docker \
pytorch/pytorch:1.3-cuda10.1-cudnn7-devel \
/bin/bash

### (3)
docker run -it --rm -p 2000:2000 --gpus all -e NVIDIA_VISIBLE_DEVICES=0 \
-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY \
--name pytorch-docker \
pytorch/pytorch:1.3-custom \
/bin/bash

### (4)
docker run -it -p 2000:2000 --gpus all -e NVIDIA_VISIBLE_DEVICES=0 \
-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY \
-v $(pwd):/data \
--name pytorch-docker \
pytorch/pytorch:1.3-custom \
/bin/bash

### (5)
docker run -it -p 2000:2000 --gpus all -e NVIDIA_VISIBLE_DEVICES=0 \
-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY \
-v $(pwd)/home/pytorch-home:/home/torch -v $(pwd)/dataset/data_odometry_velodyne:/data \
--name pytorch-docker-01 \
jjimin/pytorch:1.3-5.0 \
/bin/bash

Delete 'none' docker image

 docker rmi $(docker images -f "dangling=true" -q)

About

practicing docker tutorial

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Dockerfile 100.0%