|
| 1 | +# Docker Containers BKMs |
| 2 | + |
| 3 | +## Installation |
| 4 | + |
| 5 | +Follow the [official guide](https://docs.docker.com/engine/install/) for your |
| 6 | +OS or distro. |
| 7 | + |
| 8 | +### Change location of the images on the system |
| 9 | + |
| 10 | +By default Docker stores images in `/var/lib/docker`, but that can be changed. |
| 11 | + |
| 12 | +Create a new file called `/etc/docker/daemon.json` and put the following |
| 13 | +content: |
| 14 | + |
| 15 | +``` |
| 16 | +{ |
| 17 | + "data-root": "/path/to/data/root", |
| 18 | + "exec-root": "/path/to/exec/root" |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +### Running Docker without sudo |
| 23 | + |
| 24 | +Add your local user to `docker` group to be able to run docker commands without |
| 25 | +sudo. |
| 26 | + |
| 27 | + |
| 28 | +### Docker vs Podman |
| 29 | + |
| 30 | +Docker and Podman are very similar tools, that allow you to manage and run |
| 31 | +container images. Unlike Docker, Podman runs without a daemon and allows you |
| 32 | +to run containers without root permissions. The command line syntax is mostly |
| 33 | +identical for Docker and Podman. Choose whatever is available on your system. |
| 34 | + |
| 35 | +## SYCL Containers overview |
| 36 | + |
| 37 | +The following containers are publicly available for DPC++ compiler development: |
| 38 | + |
| 39 | +- `ghcr.io/intel/llvm/ubuntu2004_base`: contains basic environment setup for |
| 40 | + building DPC++ compiler from source. |
| 41 | +- `ghcr.io/intel/llvm/ubuntu2004_intel_drivers`: contains everything from the |
| 42 | + base container + pre-installed Intel drivers. |
| 43 | +- `ghcr.io/intel/llvm/sycl_ubuntu2004_nightly`: contains the latest successfully |
| 44 | + built nightly build of DPC++ compiler. The image comes in two flavors: |
| 45 | + with pre-installed Intel drivers (`latest`) and without them (`no-drivers`). |
| 46 | + |
| 47 | +## Running Docker container interactively |
| 48 | + |
| 49 | +The main application of Docker is containerizing services. But it also allows |
| 50 | +you to run containers interactively, so that you can use them as you would use a |
| 51 | +terminal or SSH session. The following command allows you to do that: |
| 52 | + |
| 53 | +``` |
| 54 | +docker run --name <friendly_name> -it <image_name>[:<tag>] /bin/bash |
| 55 | +``` |
| 56 | + |
| 57 | +This command will download an image if it does not exist locally. If you've |
| 58 | +downloaded an image previously, and you want to update it, use |
| 59 | +`docker pull <image_name>` command. |
| 60 | + |
| 61 | +## Persisting data |
| 62 | + |
| 63 | +### Persisting data with volumes |
| 64 | + |
| 65 | +Docker container images are read-only. When container is destroyed, all its data |
| 66 | +is lost. To persist data when working with containers (i.e. when upgrading |
| 67 | +container version) one can use Docker volumes. |
| 68 | + |
| 69 | +Creating a volume: |
| 70 | + |
| 71 | +``` |
| 72 | +docker volume create <volume name> |
| 73 | +``` |
| 74 | + |
| 75 | +Listing all volumes: |
| 76 | + |
| 77 | +``` |
| 78 | +docker volume list |
| 79 | +``` |
| 80 | + |
| 81 | +Mounting volume to the container: |
| 82 | + |
| 83 | +``` |
| 84 | +docker run <options> -v <volume_name>:/path/inside/container <image_name> bash |
| 85 | +``` |
| 86 | + |
| 87 | +Deleting a volume: |
| 88 | + |
| 89 | +``` |
| 90 | +docker volume rm <image_name> |
| 91 | +``` |
| 92 | + |
| 93 | +See [official documentation](https://docs.docker.com/storage/volumes/) for more |
| 94 | +info. |
| 95 | + |
| 96 | +### Passthrough a directory to a container |
| 97 | + |
| 98 | +Use `-v path/on/host:path/in/container` argument for `run` command to |
| 99 | +passthrough a host directory or a file. |
| 100 | + |
| 101 | +## GPU passthrough |
| 102 | + |
| 103 | +### Intel |
| 104 | + |
| 105 | +Add `--device=/dev/dri` argument to `run` command to passthrough you Intel GPU. |
| 106 | +Make sure you're a member of `video` group to be able to access GPU. |
| 107 | + |
| 108 | +### AMD |
| 109 | + |
| 110 | +Follow the [official guide](https://rocmdocs.amd.com/en/latest/ROCm_Virtualization_Containers/ROCm-Virtualization-&-Containers.html). |
| 111 | + |
| 112 | +### Nvidia |
| 113 | + |
| 114 | +Follow [these](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/user-guide.html) |
| 115 | +instructions. |
| 116 | + |
| 117 | +## Changing Docker user |
| 118 | + |
| 119 | +By default all processes inside Docker run as root. Some LLVM or Clang tests |
| 120 | +expect your user to be anything but root. You can change the user by specifying |
| 121 | +`-u <username or uid>` option. All Docker containers come with user `sycl` |
| 122 | +created. |
| 123 | + |
| 124 | +## Managing downloaded Docker images |
| 125 | + |
| 126 | +List local images: |
| 127 | +``` |
| 128 | +docker image ls |
| 129 | +``` |
| 130 | + |
| 131 | +Remove local image: |
| 132 | +``` |
| 133 | +docker image rm <image_name_or_id> |
| 134 | +``` |
| 135 | + |
| 136 | +## Managing disk usage |
| 137 | + |
| 138 | +See how much space is taken by docker: |
| 139 | + |
| 140 | +``` |
| 141 | +docker system df |
| 142 | +``` |
| 143 | + |
| 144 | +Cleaning unused data: |
| 145 | + |
| 146 | +``` |
| 147 | +docker system prune |
| 148 | +``` |
| 149 | + |
| 150 | +See [official documentation](https://docs.docker.com/engine/reference/commandline/system_prune/) |
| 151 | +for more info. |
| 152 | + |
| 153 | +## Building a Docker Container from scratch |
| 154 | + |
| 155 | +Docker containers can be built with the following command: |
| 156 | + |
| 157 | +``` |
| 158 | +docker build -f path/to/devops/containers/file.Dockerfile path/to/devops/ |
| 159 | +``` |
| 160 | + |
| 161 | +The `ubuntu2004_preinstalled.Dockerfile` script expects `llvm_sycl.tar.xz` file |
| 162 | +to be present in `devops/` directory. |
| 163 | + |
| 164 | +Containers other than base provide several configurable arguments, the most |
| 165 | +commonly used are `base_image` and `base_tag`, which specify the base Docker |
| 166 | +image and its tag. You can set additional arguments with `--build-arg ARG=value` |
| 167 | +argument. |
| 168 | + |
0 commit comments