Skip to content

filkovsp/docker-caching

Repository files navigation

Docker Caching and image layering

Docker:

docker buildx build --platform linux/arm64 \
-t docker-caching:latest \
-t "docker-caching:$(date +"%Y.%m.%d-%H.%M.%S")" \
-f Dockerfile.blah .

Podman:

Install and start:

https://podman.io/docs/installation

brew install podman

podman machine init
podman machine start

podman info

# To start Podman after reboot:
service podman enable

Build:

https://docs.podman.io/en/latest/markdown/podman-build.1.html

podman build --platform linux/arm64 \
-t "docker-caching:latest" \
-t "docker-caching:$(date +"%Y.%m.%d-%H.%M.%S")" \
-f Dockerfile.blah .

Run

https://docs.podman.io/en/latest/markdown/podman-run.1.html

podman run --rm -it \
--workdir="/docker-caching" \
--env BLAH=blah.blah.blah \
--volume="$(pwd):/docker-caching" \
--volume="venv:/docker-caching/.venv" \
--volume="node_modules:/docker-caching/tests/node_modules" \
docker-caching:latest /bin/bash

alternatively, more verbose way to mount volumes:

podman run --rm -it \
--workdir=/docker-caching \
--env BLAH=blah.blah.blah \
--mount type=bind,src="$(pwd)",target=/docker-caching \
--mount type=volume,src=venv,target=/docker-caching/.venv \
--mount type=volume,src=node_modules,target=/docker-caching/tests/node_modules \
docker-caching:latest /bin/bash

if we want to isolate host's filesystem from container then we should add COPY . . as the last step in Dockerfile and start container without bind mount, as example below:

podman run --rm -it \
--workdir=/docker-caching \
--env BLAH=blah.blah.blah \
--mount type=volume,src=venv,target=/docker-caching/.venv \
--mount type=volume,src=node_modules,target=/docker-caching/tests/node_modules \
docker-caching:latest /bin/bash

Clean up builds:

podman image prune -a
# !!! ACHTUNG !!!
# this removes all images that are currently not use by any containers

Test everyting is working as expected

Once connected to image run cmd:

bash dummy-test.sh 

About

Dummy project illustrating how to effectively use docker layering and caching principles

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors