how to install and show examples of using various docker images
- description link (1)
- description link (2)
- what are differences between CE and EE (CE: community edition, EE: enterprise edition)
Install docker
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 -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce docker-ce-cli containerd.io
Check the installation
docker --version
Change setting to use docker without 'sudo'
### temperary solution
sudo chmod 666 /var/run/docker.sock
### permanent solution
sudo usermod -a -G docker $USER
sudo service docker restart
# After this, please restart your computer.
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 nvidia-container-toolkit
sudo apt-get install nvidia-docker2
sudo systemctl restart docker
### check the installation
docker run --rm --gpus all nvidia/cuda:11.2.2-base nvidia-smi
- check installed images
docker images
- download images from docker hub
docker search ubuntu
docker pull ubuntu # default tag: latest
## OR other version of ubuntu
docker pull ubuntu:xenial
- check existing containers
docker ps -a
- check only running containers
docker ps
- 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 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
- 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
- check container information (ip, port, etc.)
# docker inspect <container>
docker inspect hello
- 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 ../
- create an image of changes made to a container
# docker commit <container> <repository>/<image>:<tag>
docker commit hello jjimin/ubuntu:1.0
docker rmi $(docker images -f "dangling=true" -q)
# example with ROS image
# Shell (1)
docker run --rm --user root --name <container-name> ros:foxy-ros-base /bin/bash
# inside of container
apt install sudo
useradd --user-group --system --create-home --no-log-init --shell /bin/bash <user-name>
echo "<user-name>:<user-name>" | chpasswd && adduser <user-name> sudo
# Shell (2)
# outside of container
docker commit <container-name> <new-image-name>
# Shell (1)
# inside of container
exit
# outside of container
docker run --rm --user <user-name> --workdir /home/<user-name> --name <container-name> <new-image-name> /bin/bash
# Shell (2)
# outside of container
docker commit <container-name> <new-image-name>
sudo apt update
sudo apt install software-properties-common apt-transport-https wget
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
sudo apt update
sudo apt install code
docker pull ros:kinetic-ros-base-xenial
docker pull pytorch/pytorch:1.3-cuda10.1-cudnn7-devel
# download the image
docker pull jjimin/carla-ros:18.04-foxy-0.9.11_v1.0
# create a container with the image
docker run -it --rm --privileged --net=host --runtime=nvidia --gpus all -e NVIDIA_VISIBLE_DEVICES=0 -e NVIDIA_DRIVER_CAPABILITIES=all -e QT_X11_NO_MITSHM=1 -v /tmp/.X11-unix:/tmp/.X11-unix -v /dev/shm:/dev/shm -e DISPLAY=unix$DISPLAY \
-v ~/Data:/data --name test-01 jjimin/carla-ros:18.04-foxy-0.9.11_v1.0 /bin/bash