Installing docker on ubuntu (NEVER use SNAP version, it has lots of problems with dockers)
11sudo apt install docker.io
Docker must work without sudo
11sudo chmod a+wrx /var/run/docker.sock
Connect to docker bash
11docker exec -it asya_backend bash
Copy files into docker
21docker cp foo.txt container_id:/foo.txt2docker cp ./logs.bag ros-apple-silicon_ros_1:/logs.bag
Run docker mounting local file system folder and TCP port forwarding
11docker run --privileged -it -v /local/ui_2022_Q1:/remote/ui_2022_Q1 -p 6080:80 --shm-size=512m alarm-container:latest
Docker build from Dockerfile in root dir
11docker build --no-cache --platform=linux/amd64 -t tag_name .
Docker see logs in CMD (-f follow)
11docker container logs -f asya_backend
Docker list images
11docker image ls
Docker list containers
xxxxxxxxxx11docker container ls -a
Docker start container
xxxxxxxxxx11docker start container_id
Docker create container from image
xxxxxxxxxx11docker run myimage
Docker lkill container
xxxxxxxxxx11docker kill container_id
Docker remove images
xxxxxxxxxx11docker image rm image_name
Docker remove container
xxxxxxxxxx11docker rm <container_id_or_name>
Docker save image
xxxxxxxxxx11docker save -o ./dockers/env.tar env
Docker load
xxxxxxxxxx11docker load < myimage.tar
RUN - shell commands executed in sequence, better to combine as many as possible to have option to cache data
COPY - coppies files and directories to target image, executed in sequence, ⚠️ Very important to use with .dockerignore , because docker will include all files in ./Dockerfile root without it regardless of COPY commands
CMD - startup script shell
there can only be one CMD instruction in a Dockerfile. If more than one CMD instruction is listed, only the last CMD will take effect only single last CMD will be executed in
Cleanup as much as you can in docker image to reduce size
xxxxxxxxxx21RUN apt-get clean && \2rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Mofiyable parameters
x1# we need to specify default values2ENV ENVIRONMENT=production3ENV CLUSTER=14
5# there is no need to use parameters array6CMD node server.js ${CLUSTER} ${ENVIRONMENT}then wehn running can pass with -e
xxxxxxxxxx11$ docker run -d -p 9000:9000 -e ENVIRONMENT=dev -e CLUSTER=0 -me/appImportant to have .dockerignore, othewise will copy ALL files from directory in container
xxxxxxxxxx131*2!Dockerfile3!controllers/**4!models/**5!denoiser/**6!modules/**7!keys/**8!modules_core/**9!modules_ext/**10!./*.py11!./*.sh12!./*.json13!./*.yaml
Sometimes can use docker-slim to reduce size of already built docker images
Dockerfile in root directory, then build using
xxxxxxxxxx11docker build -t docker_image_name .
On MacOS ARM can also build Linux x64 dockers
xxxxxxxxxx11docker build --platform=linux/amd64 -t docker_image_name .
Discard cached scripts
xxxxxxxxxx11docker build --no-cache -t docker_image_name .
Start, restart, stop, status
xxxxxxxxxx41sudo systemctl start docker2sudo systemctl restart docker3sudo systemctl stop docker4sudo systemctl status docker
Docker for using ROS under MacOS 2023-03-28
xxxxxxxxxx21docker pull tiryoh/ros-desktop-vnc2docker run -p 6080:80 --shm-size=512m tiryoh/ros-desktop-vnc:melodic