Compilation of all Docker info that I have come to rely on. To serve as a quick reference when troubleshooting issues with Docker.
- Setup Docker
- Build Docker Image
- Run Docker Container from Image
- Access a Running Container
- Monitoring
Click to expand
-
Install NVIDIA Container Toolkit for GPU support.
*Recommend to use WSL 2.
-
Enable 'Use the WSL 2 based engine' in Docker Desktop >> Settings >> General.
-
'Enable integration with my default WSL distro' and additional distros in Docker Desktop >> Settings >> Resources >> WSL Integration.
-
Remove need for
sudo
for docker.In WSL2 shell,
sudo groupadd docker sudo usermod -aG docker $USER
-
[OPTIONAL] Change docker storage location in Windows. Reference: stackoverflow.
Requires Dockerfile.
docker build -f <path to dockerfile> -t <docker image name> .
- List of
docker build
flags: Official Documentation.
-
Include following snippet in Dockerfile to avoid ownership and permission issues for files/folders created within the docker container.
ARG USERNAME=user ARG USER_UID=1000 ARG USER_GID=$USER_UID # Create the user RUN groupadd --gid $USER_GID $USERNAME \ && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ # # [Optional] Add sudo support. Omit if you don't need to install software after connecting. && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME
Requires docker image.
docker run -it <FLAGS> <image name>
*Assumes user interaction with the container is required after starting the container.
Reference: stackoverflow
From WSL (i.e. Ubuntu Distro in Windows) - Works in Ubuntu app terminal or Powershell after ubuntu
command.
docker run -it \
-v /tmp/.X11-unix:/tmp/.X11-unix -v /mnt/wslg:/mnt/wslg -e DISPLAY=:0 -e WAYLAND_DISPLAY=wayland-0 -e XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir -e PULSE_SERVER=/mnt/wslg/PulseServer \
<image name>
Not tested.
-
List of
docker run
flags: Official Documentation. -
Enable GPU support.
--gpus=all
-
Specify name for running container. Makes it easier to
docker exec
into the desired container.--name <container name>
-
Automatically remove container after it is stopped.
--rm
-
Bind mount a volume from host to the container.
-v <path>/<to>/<host>/<volume>:<path>/<to>/<container>/<volume>
Alternatively,
--mount type=bind,source=<host PATH>,target=<container PATH>
-
Volume mount a volume (managed only by Docker) from host to container. Recommended for sharing data between containers.
--mount source=<VOLUME NAME>,target=<container PATH>
-
Connect the container to a network. (Official Documentation)
--network <network name>
-
Default if none specified is
--network bridge
. Containers are on bridge network, isolated from host. -
--network host
for host and containers to be connected. -
--network none
to isolate the container from all other containers and the host.
-
-
Launch bash in a new terminal in a running container. "Enter" a running container.
docker exec -it <container name> bash