Installing docker on ubuntu (NEVER use SNAP version, it has lots of problems with dockers)
xxxxxxxxxx11sudo apt install docker.io
Connect to docker bash
xxxxxxxxxx11docker exec -it audio_text bash
Copy files into docker
x
41docker 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
xxxxxxxxxx1docker 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
xxxxxxxxxx11docker build --no-cache --platform=linux/amd64 -t tag_name .
Docker list containers
x1docker 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
x1docker image rm image_name
Docker remove container
xxxxxxxxxx11docker rm <container_id_or_name>
Docker save image
xxxxxxxxxx11docker save -o ./dockers/env.tar env
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
xxxxxxxxxx11RUN apt-get clean && \2rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Mofiyable parameters
1# 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
x1*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
x1docker build -t docker_image_name .
On MacOS ARM can also build Linux x64 dockers
x1docker build --platform=linux/amd64 -t docker_image_name .
Discard cached scripts
xxxxxxxxxx11docker build --no-cache -t docker_image_name .
Start, restart, stop, status
xxxxxxxxxx1sudo 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