ID: S202604232031
Status: school
Tags: Docker, Promptus Imperii, Docker Compose

docker workshop PI readme

Here are some commands as used during the workshop.

For more information, check

Check your Docker Desktop installation

docker run hello-world

Note: docker run is an alias for docker container run.

Check Docker Desktop, page: Images.

docker run -it debian:12-slim /bin/bash

Check Docker Desktop, page: Images, Containers

Quit the ‘bash’ terminal.

Build a simple Debian container

In the ‘02-building’ directory:

docker build -f dockerfile .

Check Docker Desktop, page: Images. (And/Or docker image ls)

Build an image with a name.

docker build -f dockerfile -t my-first-image .

Check Docker Desktop, page: Images. (And/Or docker image ls)

Build an image with a name and tag.

docker build -f dockerfile -t my-first-image:1.0 .

Check Docker Desktop, page: Images. (And/Or docker image ls)

Run a bash shell in the container:

docker run -it my-first-image /bin/bash

Exit the container:

exit

Data in a container

docker run -it --name my-first-container my-first-image /bin/bash

Make some changes to files in the container and exit.

Restart the container

docker start -i my-first-container

A simple webserver

In the ‘03-webserver’ directory:

Build the image.

docker build -f dockerfile -t 03-webserver-demo .

Run the image.

docker run -t 03-webserver-demo

Check if you can reach the webserver. (Start a webbrowser and connect to http://localhost:8000)

Use volumes i.s.o. copying files into the image

In the ‘04-volumes’ directory:

Build and run the image.

docker build -f dockerfile -t 04-webserver-demo .

To re-use this image at a later stage, tag the image:

docker tag 04-webserver-demo 04-webserver-demo:1.0

Rust development (build)

In the ‘05-compilation’ directory:

docker build -t rust-dev:1.0 .

Run a Rust build on a given project.

docker run --rm --volume ./hello-world:/workdir -t rust-dev:1.0

Run the rust program

./hello-world/target/debug/hello-world

Make this a cross compiler

Used: https://sysdev.me/2025/11/27/cross-compiling-rust-for-raspberry-pi/#building-a-custom-cross-image

Add this to the dockerfile, after setting the path:

RUN rustup target add armv7-unknown-linux-gnueabihf
RUN apt install -y gcc-arm-linux-gnueabihf

Change ‘CMD’ to:

CMD [ "cargo", "build", "--target=armv7-unknown-linux-gnueabihf"]

Build the image. Note the name!

docker build -t rust-rpi-dev:1.0 .

Build the application for RPI

docker run --rm --volume ./hello-world:/workdir -v ./cargo_config_rpi:/root/.cargo/config.toml -t rust-rpi-dev:1.0

Multi stage

In the ‘06-multistage’ directory:

Build the large image:

docker build -t calculator-large -f dockerfile-large .

Check the size of the image:

docker images | grep calculator

Build the multi-stage image(s):

docker build -t calculator-multi -f dockerfile-multi .

Recheck the size

Docker Compose

In the ‘07-compose’ directory:

docker-compose up

Networking

In the ‘08-networking’ directory:

docker-compose up

“De-attach”

Build a small network-inspector

docker build -f dockerfile_debian-networktools -t debian-network .

Connect to ‘between_containers’ network

docker run -it --network 08-networking_between_containers debian-network /bin/bash

Check the connection between “debian-network” and the webserver (from within the “bash” shell):

ping web

Connect to ‘to_host’ network

docker run -it --network 08-networking_to_host debian-network /bin/bash

Check the connection between “debian-network” and the webserver (from within the “bash” shell):

ping web
ping <ip-address>
ping proxy

Publishing

To push an image to a registry, in this case Docker Hub is used, the following commands give an example. It uses the name space “idorf79”.

docker login
docker image tag rust-rpi-dev:1.0 idorf79/rust-rpi-dev:1.0
docker image push idorf79/rust-rpi-dev:1.0

If you want to use a local registry, check: https://hub.docker.com/_/registry

Tips

Windows mounts

Needs to be tested: //$(PWD)/folder:/folder

Keep the container as little as possible

  • Only add functionality you really need
  • Only for the platform which will be running it
  • Only assign resources which are needed

Think before doing

Write down expectations (in words and/or drawings)

Running and automatically removing a container

Use ‘—rm’ like:

docker run --rm -it --network my-net debian-network /bin/bash

This will remove the container after it’s finished running.

Write used commands down

“Reconnect” to an already running container (start a new process ‘/bin/bash’ inside it):

docker container exec -it <running container name or ID> /bin/bash

Try to reuse images

Keep dynamic data out of the containers

  • use volumes or mounts

In production use tags, not ‘latest’/‘stable’

Name your containers

docker run -it --name my-web-server -p 8000:8000 04-webserver-demo:1.0

Restart/continue:

docker start my-web-server
docker rm my-web-server

Don’t be scared to make mistakes

Clean-up

Use the following commands to check and clean-up:

docker container ls -a
docker image ls -a
docker system df
docker image prune
docker rmi $(docker images -q)
docker volume ls
docker system prune
docker network ls
docker network prune
docker system prune
docker buildx history ls | tail -n +2 | awk '{print $1}' | xargs -r docker buildx history rm

References