====== Docker ====== https://docs.docker.com/storage/volumes/ ===== Main install ===== apt-get -y install curl unzip dialog curl -fSSL get.docker.com | sh ===== Show logs ===== docker logs --follow ===== Build image ===== To build the docker image based on a Dockerfile in the current directory, use: docker build . ===== Update container ===== Update docker container to latest version via docker compose: #Single container: docker compose pull calibre-web docker compose up -d calibre-web docker image prune #Update all containers: docker compose pull docker compose up -d docker image prune ===== Health Checks ===== Docker compose health checks: https://medium.com/geekculture/how-to-successfully-implement-a-healthcheck-in-docker-compose-efced60bc08e https://stefanjarina.gitbooks.io/docker/content/swarm-mode/healthchecks.html ===== Copying files to/from containers ===== Copying files from/to containers docker cp dockerimage:/bla ./bla docker cp ./bla dockerimage:/bla ===== Flatten docker image layers ===== Flatten docker image layers: FROM yourbuildimage as build # your existing build steps here FROM scratch COPY --from=build / / CMD ["/your/start/script"] ===== Change mount points of containers ===== Change mount points of existing docker containers; e.g. mount /home/ folder of host to the /mnt folder of the existing (not running) container. - stop docker container or whole docker engine systemctl stop docker.service - Open configuration file corresponding to the stopped container, which can be found at /var/lib/docker/containers/99d...1fb/config.v2.json (may be config.json for older versions of docker). For pretty print use vi <(jq . /var/lib/docker/containers//config.v2.json) Save updates to a file: :w config.v2.json Exit vim: :q! Update existing file: jq -c . config.v2.json > /var/lib/docker/containers//config.v2.json - Find MountPoints section: "MountPoints":{}. - Replace the contents with something like this (you can copy proper contents from another container with proper settings): "MountPoints":{"/mnt":{"Source":"/home/","Destination":"/mnt","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/home/","Target":"/mnt"},"SkipMountpointCreation":false}} or the same (formatted): "MountPoints": { "/mnt": { "Source": "/home/", "Destination": "/mnt", "RW": true, "Name": "", "Driver": "", "Type": "bind", "Propagation": "rprivate", "Spec": { "Type": "bind", "Source": "/home/", "Target": "/mnt" }, "SkipMountpointCreation": false } } - Start or restart the docker service: systemctl start docker.service service docker restart - Start the container if necessary: docker start ===== PHP&NGINX image ===== Containerised PHP & NGINX on Alpine, image size ~60MB: https://levelup.gitconnected.com/containerizing-nginx-php-fpm-on-alpine-linux-953430ea6dbc https://github.com/johnathanesanders/docker-nginx-fpm Log nginx to stdout in Dockerfile: # forward request and error logs to docker log collector RUN ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log ===== Rename/Retag image files ===== docker tag current/image:tag new/image:tag ===== cmd shell of container ===== docker exec -it bash docker exec -it /bin/sh ===== GPU hardware acceleration ===== Make sure the relevant GPU drivers are installed on the base system, then pass through the device via docker compose. Check devices are available, there should be a device per GPU starting at renderD128 for the first GPU: ls -la /dev/dri devices: - /dev/dri:/dev/dri ===== docker ps short ===== Short form of docker ps to only get the container names: docker ps | sed 's/ */#/g' | cut -d "#" -f 7 ===== docker running out of network addresses ===== Error response from daemon: all predefined address pools have been fully subnetted { "default-address-pools":[ {"base":"169.254.2.0/23","size":28}, {"base":"169.254.4.0/22","size":28}, {"base":"169.254.8.0/21","size":28}, {"base":"169.254.16.0/20","size":28}, {"base":"169.254.32.0/19","size":28}, {"base":"169.254.64.0/18","size":28}, {"base":"169.254.128.0/18","size":28}, {"base":"169.254.192.0/19","size":28}, {"base":"169.254.224.0/20","size":28}, {"base":"169.254.240.0/21","size":28}, {"base":"169.254.248.0/22","size":28} ] } docker restart docker network prune