Dev Container and Docker
The development
target of the multi-stage .devcontainer\Dockerfile
is used by .devcontainer/devcontainer.json
to install mdbook
⮳ and rust tooling.
If you don't want to use Dev Container, use the following from the project's root directory to manually build the docker
⮳ image and run it.
docker build --file .devcontainer/Dockerfile --target development --tag rust_howto_dev --build-arg RUST_IMAGE_LABEL=1.75.0-slim-bookworm --build-arg MDBOOK_VERSION=0.4.36 .
docker run --rm --detach --name rust_howto_dev1 --volume $(pwd):/code rust_howto_dev
docker exec -it rust_howto_dev1 bash
To cache the crate and the target folders from run to run, add
--mount type=volume,src=rust_howto_cargo_crate_cache,dst=/usr/local/cargo/registry/
--mount type=volume,src=rust_howto_cargo_target_cache,dst=/cargo-target-rust_howto/
To connect to the (host OS) docker engine from within the container, add
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker-host.sock
Docker Compose
Test the docker compose setup used during developement (which Dev Container runs) with:
cd ./.devcontainer
docker compose build # uses compose.yaml and compose.override.yaml
docker compose up -d
# or simply
docker compose up --build -d
Deployment to GitHub Pages
The continuous integration worflow is found under .github
.
Test the docker compose setup used during CI using:
cd ./.devcontainer
docker compose -f compose.yaml -f compose-ci.yaml build
docker compose -f compose.yaml -f compose-ci.yaml run book # or simply docker compose -f compose.yaml -f compose-ci.yaml up
It uses the ci
target in .devcontainer/Dockerfile
.
To test the docker
⮳ image manually, use
docker build --file .devcontainer/Dockerfile --target ci --tag rust_howto_ci --build-arg RUST_IMAGE_LABEL=1.75.0-slim-bookworm --build-arg MDBOOK_VERSION=0.4.36 .
docker run -it --rm --name rust_howto_ci1 --volume $(pwd)/book:/code/book rust_howto_ci bash
Related Stackoverflow question⮳
Push image to Docker Hub
From the project root folder, use the following to build and push the development
image:
docker build --file .devcontainer/Dockerfile --target development --tag johncd/rust_howto_dev:latest --build-arg RUST_IMAGE_LABEL=1.75.0-slim-bookworm --build-arg MDBOOK_VERSION=0.4.36 .
# or docker tag rust_howto_dev johncd/rust_howto_dev:latest
docker login
# or docker login -u "user" -p "password" docker.io
docker push johncd/rust_howto_dev:latest
Use the following to build and push the CI image:
docker build --file .devcontainer/Dockerfile --target ci --tag johncd/rust_howto_ci --build-arg RUST_IMAGE_LABEL=1.75.0-slim-bookworm --build-arg MDBOOK_VERSION=0.4.36 .
docker login
docker push johncd/rust_howto_ci:latest