Docker
Install
Install to Debian
Docker for Debian
https://docs.docker.com/engine/install/debian/
sudo apt-get update sudo apt install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] \ https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Install to Ubuntu
Docker for Ubuntu
https://docs.docker.com/engine/install/ubuntu/
sudo apt install ca-certificates curl gnupg lsb-release
sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \ https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
User Settings
https://docs.docker.com/engine/install/linux-postinstall/
If specific user(s) need to have a permission:
## Adding the current user to the docker group #sudo gpasswd -a $(whoami) docker sudo usermod -aG docker $USER
## Adding other user(s) to the docker group (as needed) sudo vigr ================================ docker:x:999:[user(s)] ================================
## Change group of docker.sock (as needed) #sudo chgrp docker /var/run/docker.sock #sudo service docker restart
## Activate the new group settings (as needed) #newgrp docker
## Restart the virtual machine for changes to take effect sudo reboot
docker ps
Example
Hello World
docker pull hello-world docker inspect hello-world:latest #docker run hello-world docker run --rm hello-world /var/lib/docker/overlay2/e61636addbfe0b209c05884fed3e1507ba97f6fd52f6f99860f52a2f636f8abc/diff/hello docker images docker ps docker ps -a docker rm 1048e687431c #docker rm -f 1048 docker rmi hello-world #docker rmi -f hello-world
Minimum Build
mkdir minimum cd minimum ldd /bin/sh cp /bin/sh . cp /lib/x86_64-linux-gnu/libc.so.6 . cp /lib64/ld-linux-x86-64.so.2 . cat << EOF > Dockerfile FROM scratch COPY ./sh /bin/sh COPY ./libc.so.6 /lib/x86_64-linux-gnu/libc.so.6 COPY ./ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 CMD ['/bin/sh'] EOF docker build -t minimum . docker images docker run -it minimum
Shell Script
mkdir shell cd shell ldd /bin/sh cp /bin/sh . cp /lib/x86_64-linux-gnu/libc.so.6 . cp /lib64/ld-linux-x86-64.so.2 . cat << EOF > hello.sh #!/bin/sh echo "Hello World!" EOF chmod 755 hello.sh cat << EOF > Dockerfile FROM scratch COPY ./sh /bin/sh COPY ./libc.so.6 /lib/x86_64-linux-gnu/libc.so.6 COPY ./ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 COPY ./hello.sh / CMD ['/hello.sh'] EOF docker build -t shell . docker images docker run --rm shell
Python
mkdir python cd python cat << EOF > hello.py #!/usr/bin/env python print("Hello World!") EOF chmod 755 hello.py cat << EOF > Dockerfile FROM python:3.10-slim COPY ./hello.py /hello.py CMD ["/hello.py"] EOF docker build -t python . docker images docker run --rm python
Python Compose (and Jupyter)
mkdir python_compose cd python_compose mkdir opt cat << EOF > ./opt/hello.py #!/usr/bin/env python print("Hello World!") EOF chmod 755 ./opt/hello.py cat << EOF > Dockerfile FROM python:3.10-slim USER root RUN apt-get update ENV LANG C RUN apt-get install -y vim less RUN pip install --upgrade pip RUN pip install --upgrade setuptools RUN python -m pip install jupyterlab EOF cat << EOF > docker-compose.yml version: '1.0' services: sample: restart: always build: . container_name: sample tty: true working_dir: '/' volumes: - ./opt:/opt/shared EOF docker compose up -d --build docker images docker ps -a #docker run -it python_compose_sample /bin/sh #docker exec -it python_compose_sample /bin/sh docker compose exec sample sh cd /opt/shared ls exit docker compose down docker compose up -d docker compose down docker run -v $PWD/opt:/opt/shared -w /opt/shared -it --rm -p 6789:8888 python_compose_sample jupyter-lab --ip 0.0.0.0 --allow-root -b localhost
Connect to Jupyter
http://192.168.123.123:6789/
Usage
Save Image
docker save python -o python.tar #docker save python -o python.tar.gz
Load Image
docker load -i python.tar #docker load -i python.tar.gz docker images docker run --rm python
Commit Image
docker ps -a docker commit c21a9e610538 python:modified
Display STDOUT
docker logs python
File Copy
docker ps -all docker cp b2ccb5822a24:/tmp/sample.txt ./
Attach to Container
docker ps -all docker attach d01d705bb1b8
Remove Build Cache
docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 1 0 8.498GB 8.498GB (100%) Containers 0 0 0B 0B Local Volumes 0 0 0B 0B Build Cache 53 0 20.6kB 20.6kB
docker builder prune
Remove docker image(s) first before cleaning up all related build caches
Mount Host Directory in Docker Container
docker run -v /mnt:/mnt [image] [command]
Tag Control
https://docs.docker.com/engine/reference/commandline/tag/
https://serverfault.com/questions/703344/how-to-remove-an-image-tag-in-docker-without-removing-the-image-itself
## Add Tag docker tag xilinx/vitis-ai:3.5.0 xilinx/vitis-ai:latest
## Remove Tag docker rmi xilinx/vitis-ai:latest
Detach from Container
[Ctrl-p][Ctrl-q]
Exit Code
https://stackoverflow.com/questions/31297616/what-is-the-authoritative-list-of-docker-run-exit-codes
https://komodor.com/learn/exit-codes-in-containers-and-kubernetes-the-complete-guide/
- Exit Code 137: Container was immediately terminated by the operating system via SIGKILL signal
References
Docker
https://www.docker.com/
Docker Hub
https://hub.docker.com/
Acknowledgments
Daiphys is a professional-service company for research and development of leading-edge technologies in science and engineering.
Get started accelerating your business through our deep expertise in R&D with AI, quantum computing, and space development; please get in touch with Daiphys today!
Daiphys Technologies LLC - https://www.daiphys.com/