ID: S202604232031
Status: school
Tags: Docker, Promptus Imperii, Docker Compose
docker workshop PI readme
- Samenvatting: Docker workshop PI
- Bijbehorende Github repo: https://github.com/idorf79/docker-workshop-sv-pi
Here are some commands as used during the workshop.
For more information, check
- Docker Cli reference page: https://docs.docker.com/reference/cli/docker/
- Docker Compose: https://docs.docker.com/compose/
Check your Docker Desktop installation
docker run hello-worldNote: docker run is an alias for docker container run.
Check Docker Desktop, page: Images.
docker run -it debian:12-slim /bin/bashCheck 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/bashExit the container:
exitData in a container
docker run -it --name my-first-container my-first-image /bin/bashMake some changes to files in the container and exit.
Restart the container
docker start -i my-first-containerA 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-demoCheck 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.0Rust 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.0Run the rust program
./hello-world/target/debug/hello-worldMake 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-gnueabihfChange â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.0Multi 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 calculatorBuild 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 upNetworking
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/bashCheck the connection between âdebian-networkâ and the webserver (from within the âbashâ shell):
ping webConnect to âto_hostâ network
docker run -it --network 08-networking_to_host debian-network /bin/bashCheck the connection between âdebian-networkâ and the webserver (from within the âbashâ shell):
ping webping <ip-address>ping proxyPublishing
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.0If 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/bashThis 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/bashTry 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.0Restart/continue:
docker start my-web-serverdocker rm my-web-serverDonât be scared to make mistakes
Clean-up
Use the following commands to check and clean-up:
docker container ls -adocker image ls -adocker system dfdocker image prunedocker rmi $(docker images -q)docker volume lsdocker system prunedocker network lsdocker network prunedocker system prunedocker buildx history ls | tail -n +2 | awk '{print $1}' | xargs -r docker buildx history rm