|
| 1 | +#! /bin/sh |
| 2 | +#---------------------------------------------------------------------------- |
| 3 | +# Create a rust-cuda Docker container that will persist until explicitly |
| 4 | +# stopped, even if the host machine is rebooted. |
| 5 | +# |
| 6 | +# Useful docker commands: |
| 7 | +# - `docker ps` shows details about the running container. |
| 8 | +# - `docker stop rust-cuda` stops the running container, and `docker rm |
| 9 | +# rust-cuda` deletes the running container. This is only necessary if you |
| 10 | +# have no more use for the container. |
| 11 | +# - `docker exec -it rust-cuda bash` starts a bash shell within the container. |
| 12 | +# |
| 13 | +# Operations within the container can be performed from outside the container |
| 14 | +# with the accompanying `dex` script, e.g. `./dex cargo build`. This may be |
| 15 | +# easier than using a shell within the container, because the packages |
| 16 | +# available within the container are limited. |
| 17 | +# |
| 18 | +# Because the container name is hard-wired as `rust-cuda`, as written this |
| 19 | +# script can only work with one container at a time. |
| 20 | +#---------------------------------------------------------------------------- |
| 21 | + |
| 22 | +# Explanation |
| 23 | +# - `--restart`/`sleep infinity` keeps it running (including restarting as |
| 24 | +# necessary, e.g. after a reboot) until explicitly stopped. |
| 25 | +# - The `-e`/`-v` options for cargo and rustup means files downloaded by those |
| 26 | +# programs will persist when the container is restarted. |
| 27 | +# - The `-v`/`-w` for the workspace mean the current directory will be the |
| 28 | +# workspace, i.e. the files visible within the container. |
| 29 | +docker create \ |
| 30 | + --name rust-cuda \ |
| 31 | + --restart unless-stopped \ |
| 32 | + --entrypoint "" \ |
| 33 | + --gpus all \ |
| 34 | + -e CARGO_HOME=/cargo \ |
| 35 | + -v rust-cuda-cargo:/cargo \ |
| 36 | + -e RUSTUP_HOME=/rustup \ |
| 37 | + -v rust-cuda-rustup:/rustup \ |
| 38 | + -v "$PWD":/workspace \ |
| 39 | + -w /workspace \ |
| 40 | + ghcr.io/rust-gpu/rust-cuda-ubuntu24-cuda12:main \ |
| 41 | + sleep infinity |
| 42 | + |
| 43 | +docker start "$CONTAINER_NAME" |
0 commit comments