linux:docker
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:docker [2023/06/04 13:07] – Wulf Rajek | linux:docker [2025/09/04 00:12] (current) – [GPU hardware acceleration] Wulf Rajek | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| https:// | https:// | ||
| + | |||
| + | ===== Main install ===== | ||
| + | < | ||
| + | apt-get -y install curl unzip dialog | ||
| + | curl -fSSL get.docker.com | sh | ||
| + | </ | ||
| + | |||
| + | Useful alias to exclude container overlays from the df command for use in .bashrc or .profile: | ||
| + | < | ||
| + | alias df='/ | ||
| + | </ | ||
| + | |||
| + | ===== 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: | Update docker container to latest version via docker compose: | ||
| Line 15: | Line 42: | ||
| docker image prune | docker image prune | ||
| </ | </ | ||
| + | |||
| + | ===== Health Checks ===== | ||
| Docker compose health checks: | Docker compose health checks: | ||
| https:// | https:// | ||
| - | Copying files from/ | + | https:// |
| + | ===== Copying files to/from containers ===== | ||
| + | |||
| + | Copying files from/ | ||
| < | < | ||
| docker cp dockerimage:/ | docker cp dockerimage:/ | ||
| Line 25: | Line 57: | ||
| </ | </ | ||
| + | ===== Flatten docker image layers ===== | ||
| + | Flatten docker image layers: | ||
| + | < | ||
| + | FROM yourbuildimage as build | ||
| + | # your existing build steps here | ||
| + | FROM scratch | ||
| + | COPY --from=build / / | ||
| + | CMD ["/ | ||
| + | </ | ||
| + | |||
| + | ===== Change mount points of containers ===== | ||
| Change mount points of existing docker containers; | Change mount points of existing docker containers; | ||
| Line 59: | Line 102: | ||
| - Start the container if necessary: < | - Start the container if necessary: < | ||
| + | |||
| + | ===== PHP& | ||
| Containerised PHP & NGINX on Alpine, image size ~60MB: | Containerised PHP & NGINX on Alpine, image size ~60MB: | ||
| https:// | https:// | ||
| https:// | https:// | ||
| + | |||
| + | Log nginx to stdout in Dockerfile: | ||
| + | < | ||
| + | # forward request and error logs to docker log collector | ||
| + | RUN ln -sf /dev/stdout / | ||
| + | && ln -sf /dev/stderr / | ||
| + | </ | ||
| + | |||
| + | ===== Rename/ | ||
| + | |||
| + | < | ||
| + | docker tag current/ | ||
| + | </ | ||
| + | |||
| + | ===== cmd shell of container ===== | ||
| + | < | ||
| + | docker exec -it < | ||
| + | docker exec -it < | ||
| + | </ | ||
| + | |||
| + | ===== 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: | ||
| + | - / | ||
| + | </ | ||
| + | |||
| + | for AMD: | ||
| + | https:// | ||
| + | https:// | ||
| + | < | ||
| + | mkdir --parents --mode=0755 / | ||
| + | wget https:// | ||
| + | echo "deb [arch=amd64 signed-by=/ | ||
| + | echo -e ' | ||
| + | apt update | ||
| + | apt install rocm | ||
| + | </ | ||
| + | Then add to the docker containers: | ||
| + | < | ||
| + | devices: | ||
| + | - /dev/kfd | ||
| + | - /dev/dri | ||
| + | security_opt: | ||
| + | - seccomp=unconfined | ||
| + | environment: | ||
| + | - LIBVA_DRIVER_NAME=radeonsi | ||
| + | </ | ||
| + | |||
| + | Alpine Linux docker images may require libva to be installed: | ||
| + | < | ||
| + | post_start: | ||
| + | # for 13th gen Iris Xe GPUs use intel-media-driver for older gens libva-intel-driver | ||
| + | # - command: apk add libva-intel-driver intel-media-driver | ||
| + | # user: root | ||
| + | # For AMD | ||
| + | - command: apk add libva libva-utils mesa-va-gallium | ||
| + | user: root | ||
| + | </ | ||
| + | |||
| + | nvtop can be used for AMD and NVidia gpus to see if the gpu is being used. | ||
| + | On Debian, nvtop is in the contrib repositories which need to be added. | ||
| + | < | ||
| + | #bookworm | ||
| + | sed -r ' | ||
| + | |||
| + | #new deb822 sources format | ||
| + | sed -i ' | ||
| + | |||
| + | apt update | ||
| + | </ | ||
| + | On Ubuntu systems, nvtop is in the default repositories. | ||
| + | < | ||
| + | apt-get install nvtop | ||
| + | </ | ||
| + | ===== docker ps short ===== | ||
| + | Short form of docker ps to only get the container names: | ||
| + | < | ||
| + | docker ps | sed ' | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== docker command template ===== | ||
| + | https:// | ||
| + | ===== docker running out of network addresses ===== | ||
| + | |||
| + | Error response from daemon: all predefined address pools have been fully subnetted | ||
| + | |||
| + | <code json / | ||
| + | { | ||
| + | " | ||
| + | {" | ||
| + | {" | ||
| + | {" | ||
| + | {" | ||
| + | {" | ||
| + | {" | ||
| + | {" | ||
| + | {" | ||
| + | {" | ||
| + | {" | ||
| + | {" | ||
| + | ] | ||
| + | } | ||
| + | </ | ||
| + | < | ||
| + | docker restart | ||
| + | docker network prune | ||
| + | </ | ||
linux/docker.1685880470.txt.gz · Last modified: by Wulf Rajek