4.5 KiB
Docker
Docker is a virtualization software that deploys docker containers. Due to easy handling and reproducible environments it is a useful tool.
Setup
- Arch Linux: run
pacman -S dockerto install docker - Ubuntu: visit the official installation guide
Another possibility is to try the official convenience script. To get and execute it run the following in your terminal.
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Usage
This section addresses various features of Docker.
Virtualize Operating Systems
Docker is a tool that can be used to virtualize different programs and software. Especially for containerizing and virtualizing operating systems (mostly based on Linux) can be handled by Distrobox.
Run Docker as non-root user
To run docker as a non-root user you need to add your user to the docker group.
To do this, create the group docker if it doesn't exist sudo groupadd docker
and then add your user to the group using sudo usermod -aG docker $USER.
After that log back into your machine.
Then you should be able to run the following.
docker run hello-world
Tools and Visualization
The programs below are useful docker-management systems in different style.
Enable Nvidia GPUs
To use Nvidia GPUs with docker you need to install the Nvidia CUDA toolkit. There is a guide on Marmelab that focuses on that topic.
Block remote port access
If you configured a reverse proxy to a port chances
are you don't want the port to be accessed outside the proxy.
Especially if you set up an authentication over nginx the open port will avoid
the authentication.
This can be changed at the forwarded docker-service by replacing for example
-p 7000:7000 with -p 172.17.0.1:7000:7000.
This forces the docker container to only expose the port in the docker bridge
network, effectively banning remote access.
If you use Traefik it is not needed, because you don't have to publish ports to reverse proxy them.
Containerize a graphical application
A graphical application can easily be containerized using Docker and made available over both the web browser or VNC. For this jlesages baseimage-gui container can be used.
Find the Container and the Mounting Point of a Volume
Sometimes it is unclear which container a volume belongs to. This is especially the case if the volume was created automatically and not manually or explicitly during the setup.
The following command will output the container a volume with the name <volume-name> belongs to.
docker ps -a --filter volume=<volume_name>
Additionally, the mounting point is also of interest.
To display it, run the following command where <container-name> is the name of the container the
volume belongs to.
docker inspect <container-name>
Remove Unused Data
Over time Docker accumulates unused images, stopped containers, unused networks and build cache. These objects continue to consume disk space even though they are no longer needed.
To remove all unused resources, run the following command. It removes, stopped containers, unused networks, Unused images, Dangling image layers and unused build cache.
sudo docker system prune -a
Docker will ask for confirmation before deleting the resources.
Troubleshooting
This section will focus on errors and the fixing of errors of docker.
Error saving credentials: 'Cannot autolaunch D-Bus without X11 $DISPLAY'
As explained by
gotam19 in a Docker forum post
this error message only occurs on Linux when trying to log in or pulling a Docker
image.
To fix it install GPG and the pass
package.
Afterward running the following command perform the login to the Docker servers and the error
message should not come up again.
docker login