Docker: Difference between revisions

Pigs (talk | contribs)
m Remove configurations that are already enabled by default in the system setup. Usage is shown in basic and advanced configuration
Raboof (talk | contribs)
Exposing sockets from the host: note exposing the socket folder may break
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<!--T:1-->
[https://www.docker.com/ Docker] is a platform for building, packaging, and distributing applications inside containers. Containers bundle an application's code, configurations, and dependencies into a single object that runs consistently across different computing environments. Docker works well with NixOS through the virtualization module.<ref>https://www.docker.com/resources/what-container/</ref>
[https://www.docker.com/ Docker] is a platform for building, packaging, and distributing applications inside containers. Containers bundle an application's code, configurations, and dependencies into a single object that runs consistently across different computing environments. Docker works well with NixOS through the virtualization module.<ref>https://www.docker.com/resources/what-container/</ref>
</translate>


== Installation ==
<translate>
== Installation == <!--T:2-->
</translate>


==== Shell ====
<translate>
==== Shell ==== <!--T:3-->
</translate>


<translate>
<!--T:4-->
To temporarily use Docker in a shell environment, you can run:
To temporarily use Docker in a shell environment, you can run:
</translate>
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
nix-shell -p docker
nix-shell -p docker
</syntaxhighlight>
</syntaxhighlight>
 
<translate>
<!--T:5-->
This will provide a shell with Docker CLI available, but note that the Docker daemon will not be running. For full functionality, you'll need a system-level installation.
This will provide a shell with Docker CLI available, but note that the Docker daemon will not be running. For full functionality, you'll need a system-level installation.
</translate>


==== System setup ====
<translate>
==== System setup ==== <!--T:6-->
</translate>


<translate>
<!--T:7-->
To install Docker on NixOS, add the virtualization.docker module to your system configuration at <code>/etc/nixos/configuration.nix</code>:<ref>https://nixos.org/manual/nixos/stable/options#opt-virtualisation.docker.enable</ref>
To install Docker on NixOS, add the virtualization.docker module to your system configuration at <code>/etc/nixos/configuration.nix</code>:<ref>https://nixos.org/manual/nixos/stable/options#opt-virtualisation.docker.enable</ref>
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# In /etc/nixos/configuration.nix
# In /etc/nixos/configuration.nix
Line 29: Line 46:
{{evaluate}}
{{evaluate}}


<translate>
<!--T:8-->
For a comprehensive list of configuration options, refer to the {{nixos:option|virtualisation.docker}} module options.
For a comprehensive list of configuration options, refer to the {{nixos:option|virtualisation.docker}} module options.
</translate>


== Configuration ==
<translate>
== Configuration == <!--T:9-->
</translate>


<translate>
==== Basic ==== <!--T:10-->
</translate>


==== Basic ====
<translate>
 
<!--T:11-->
The basic Docker configuration on NixOS includes several options you can set in your <code>configuration.nix</code> file:
The basic Docker configuration on NixOS includes several options you can set in your <code>configuration.nix</code> file:
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
virtualisation.docker = {
virtualisation.docker = {
Line 53: Line 79:
</syntaxhighlight>
</syntaxhighlight>


==== Advanced ====
<translate>
==== Advanced ==== <!--T:12-->
</translate>


<translate>
<!--T:13-->
For more advanced configuration, you can customize Docker daemon options and networking:
For more advanced configuration, you can customize Docker daemon options and networking:
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
virtualisation.docker = {
virtualisation.docker = {
Line 74: Line 105:
</syntaxhighlight>
</syntaxhighlight>


 
<translate>
== Docker Compose ==
== Docker Compose == <!--T:14-->
</translate>
<translate>
<!--T:15-->
Currently, there are two options to use Docker Compose with NixOS: Arion or Compose2Nix.
Currently, there are two options to use Docker Compose with NixOS: Arion or Compose2Nix.
</translate>


With Arion, you can specify most Docker Compose options in Nix Syntax, and Arion will generate a <code>docker-compose.yml</code> file internally. The result is a systemd service that starts and stops the container.  
<translate>
<!--T:16-->
With Arion, you can specify most Docker Compose options in Nix Syntax, and Arion will generate a <code>docker-compose.yml</code> file internally. The result is a systemd service that starts and stops the container.
</translate>


<translate>
<!--T:17-->
Compose2Nix, generates all necessary configs directly from the <code>docker-compose.yml</code>, which is easier when using an already existing Docker Compose project. The result is similar to that from Arion: a systemd service is created that handles starting and stopping the container.
Compose2Nix, generates all necessary configs directly from the <code>docker-compose.yml</code>, which is easier when using an already existing Docker Compose project. The result is similar to that from Arion: a systemd service is created that handles starting and stopping the container.
</translate>


=== Arion ===
<translate>
=== Arion === <!--T:18-->
</translate>
<translate>
<!--T:19-->
[https://docs.hercules-ci.com/arion/ Arion] is created for running Nix-based projects in Docker Compose. It uses the NixOS module system for configuration, it can bypass <code>docker build</code> and lets you use dockerTools or use the store directly in the containers. The images/containers can be typical dockerTools style images or full NixOS configs.
[https://docs.hercules-ci.com/arion/ Arion] is created for running Nix-based projects in Docker Compose. It uses the NixOS module system for configuration, it can bypass <code>docker build</code> and lets you use dockerTools or use the store directly in the containers. The images/containers can be typical dockerTools style images or full NixOS configs.
</translate>


<translate>
<!--T:20-->
To use Arion, you first need to add its module to your NixOS configuration:
To use Arion, you first need to add its module to your NixOS configuration:
</translate>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 91: Line 140:
</syntaxhighlight>
</syntaxhighlight>


<translate>
<!--T:21-->
After that, you can access its options under
After that, you can access its options under
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
virtualisation.arion = {}
virtualisation.arion = {}
</syntaxhighlight>
</syntaxhighlight>


<translate>
<!--T:22-->
A config for a simple container could look like this:
A config for a simple container could look like this:
</translate>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 111: Line 166:
</syntaxhighlight>
</syntaxhighlight>


=== Compose2Nix ===
<translate>
With [https://github.com/aksiksi/compose2nix compose2nix] you can generate [https://search.nixos.org/options?query=virtualisation.oci-containers oci-containers] config from a <code>docker-compose.yaml</code>.  
=== Compose2Nix === <!--T:23-->
</translate>
<translate>
<!--T:24-->
With [https://github.com/aksiksi/compose2nix compose2nix] you can generate [https://search.nixos.org/options?query=virtualisation.oci-containers oci-containers] config from a <code>docker-compose.yaml</code>.
</translate>


==== Install ====
<translate>
To use <code>compose2nix</code> with <code>nix-shell</code> you can use<syntaxhighlight lang="bash">
==== Install ==== <!--T:25-->
</translate>
<translate>
<!--T:26-->
To use <code>compose2nix</code> with <code>nix-shell</code> you can use
</translate>
<syntaxhighlight lang="bash">
nix shell github:aksiksi/compose2nix
nix shell github:aksiksi/compose2nix
compose2nix -h
compose2nix -h
</syntaxhighlight>To install <code>compose2nix</code> to NixOS, add the repo to your flake inputs<syntaxhighlight lang="nix">
</syntaxhighlight>
<translate>
<!--T:27-->
To install <code>compose2nix</code> to NixOS, add the repo to your flake inputs
</translate>
<syntaxhighlight lang="nix">
compose2nix = {
compose2nix = {
   url = "github:aksiksi/compose2nix";
   url = "github:aksiksi/compose2nix";
   inputs.nixpkgs.follows = "nixpkgs";
   inputs.nixpkgs.follows = "nixpkgs";
};
};
</syntaxhighlight>and add the package to your configuration<syntaxhighlight lang="nix">
</syntaxhighlight>
<translate>
<!--T:28-->
and add the package to your configuration
</translate>
<syntaxhighlight lang="nix">
environment.systemPackages = [
environment.systemPackages = [
   inputs.compose2nix.packages.x86_64-linux.default
   inputs.compose2nix.packages.x86_64-linux.default
Line 129: Line 205:
</syntaxhighlight>
</syntaxhighlight>


==== Usage ====
<translate>
==== Usage ==== <!--T:29-->
</translate>
<translate>
<!--T:30-->
After you have installed <code>compose2nix</code>, you can run <code>compose2nix</code> in the directory with your <code>docker-compose.yml</code>, which will output a <code>docker-compose.nix</code>.
After you have installed <code>compose2nix</code>, you can run <code>compose2nix</code> in the directory with your <code>docker-compose.yml</code>, which will output a <code>docker-compose.nix</code>.
</translate>


Alternatively, you can specify the input and output files with the following flags<syntaxhighlight lang="bash">
<translate>
<!--T:31-->
Alternatively, you can specify the input and output files with the following flags
</translate>
<syntaxhighlight lang="bash">
compose2nix -inputs input.yml -output output.nix -runtime docker
compose2nix -inputs input.yml -output output.nix -runtime docker
</syntaxhighlight>The <code>-runtime</code> flag specifies the runtime. Here, we select <code>docker</code>. Options are <code>podman</code> and <code>docker</code>. The default is <code>podman</code>
</syntaxhighlight>
 
<translate>
 
<!--T:32-->
The <code>-runtime</code> flag specifies the runtime. Here, we select <code>docker</code>. Options are <code>podman</code> and <code>docker</code>. The default is <code>podman</code>
</translate>


== Tips and tricks ==
<translate>
== Tips and tricks == <!--T:33-->
</translate>


=== Docker on btrfs ===
<translate>
=== Docker on btrfs === <!--T:34-->
</translate>


<translate>
<!--T:35-->
If you use the [[btrfs]] file system, you might need to set the {{nixos:option|virtualisation.docker.storageDriver|storageDriver}} option:
If you use the [[btrfs]] file system, you might need to set the {{nixos:option|virtualisation.docker.storageDriver|storageDriver}} option:
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
virtualisation.docker.storageDriver = "btrfs";
virtualisation.docker.storageDriver = "btrfs";
</syntaxhighlight>
</syntaxhighlight>


=== Rootless Docker ===
<translate>
=== Rootless Docker === <!--T:36-->
</translate>
 
<translate>
<!--T:37-->
[https://docs.docker.com/engine/security/rootless/ Rootless Docker] lets you run the Docker daemon as a non-root user for improved security. To do so, enable {{nixos:option|virtualisation.docker.rootless}}. This activates the user-level systemd Docker service. Additionally, the option {{nixos:option|virtualisation.docker.rootless.setSocketVariable|setSocketVariable}} configures the <code>DOCKER_HOST</code> environment variable to point to the rootless Docker instance.
</translate>


Rootless Docker lets you run the Docker daemon as a non-root user for improved security. Set the <code>rootless</code> option as shown above. The <code>setSocketVariable</code> option adds the <code>DOCKER_HOST</code> variable pointing to your rootless Docker instance.
<syntaxhighlight lang="nix">
virtualisation.docker = {
  # Consider disabling the system wide Docker daemon
  enable = false;


After enabling rootless mode, Docker can be started with:
  rootless = {
<syntaxhighlight lang="bash">
    enable = true;
$ systemctl --user enable --now docker
    setSocketVariable = true;
    # Optionally customize rootless Docker daemon settings
    daemon.settings = {
      dns = [ "1.1.1.1" "8.8.8.8" ];
      registry-mirrors = [ "https://mirror.gcr.io" ];
    };
  };
};
</syntaxhighlight>
</syntaxhighlight>


This creates the 'docker.service' file which is required to start Docker. Note that the service will not start at boot by this command. You will have to set it up in your NixOS configuration. Now the following command will work:
<translate>
<syntaxhighlight lang="bash">
<!--T:39-->
A system reboot is required for these changes to take effect. Alternatively, the environment variable can be set manually in the current shell session, and the user Docker service can be started with the following commands:
</translate>
 
<syntaxhighlight lang="console">
$ export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock
$ systemctl --user start docker
$ systemctl --user start docker
</syntaxhighlight>
</syntaxhighlight>


Check its status with:
{{note|User services do not persist after logging out by default. This will cause any Docker containers to stop if a user logs out. Set option {{nixos:option|users.users.*.linger|users.users.<name>.linger}} to true for Docker containers to persist. See [[Systemd/User Services#Keeping user services running after logout]] for more details.}}
<syntaxhighlight lang="bash">
 
<translate>
<!--T:40-->
To verify the status of the rootless Docker service:  
</translate>
<syntaxhighlight lang="console">
$ systemctl --user status docker
$ systemctl --user status docker
</syntaxhighlight>
</syntaxhighlight>


=== Creating images with Nix ===
To confirm that Docker is running in rootless mode:
 
<syntaxhighlight lang="console">
$ docker info -f "{{println .SecurityOptions}}" | grep rootless
</syntaxhighlight>
 
=== Using Privileged Ports for Rootless Docker ===
Rootless containers are not able to ports from 0 to 1023 as such port can only be used by privileged users.  This problem can be solved by using port forwarding.
 
Assume you'd like a rootless container to make use of ports 53 (DNS; TPC and UDP) and 80 (web; TCP).  We may force the container to use port 8000 while the firewall is instructed for forward traffic from port 80 to 8000.  Same logic applies for port 53.  Refer to the following example:<syntaxhighlight lang="nixos"># Firewall
networking.firewall = {
  enable = true;
  allowedTCPPorts = [ 80 8000 53 5300 ];
  allowedUDPPorts = [ 53 5300 ];
};
 
boot.kernel.sysctl = {
  "net.ipv4.conf.eth0.forwarding" = 1;    # enable port forwarding
};
   
networking = {
  firewall.extraCommands = ''
    iptables -A PREROUTING -t nat -i eth0 -p TCP --dport 80 -j REDIRECT --to-port 8000
    iptables -A PREROUTING -t nat -i eth0 -p TCP --dport 53 -j REDIRECT --to-port 5300
    iptables -A PREROUTING -t nat -i eth0 -p UDP --dport 53 -j REDIRECT --to-port 5300
  '';
};</syntaxhighlight>Whilst the docker-compose.yaml might look like this:<syntaxhighlight lang="dockerfile">
services:
  myserver:
    image: ...
    restart: always
    ports:
      - "5300:53/tcp"
      - "5300:53/udp"
      - "8000:80"
</syntaxhighlight>


==== Building a docker image with nixpkgs ====
<translate>
 
=== Creating images with Nix === <!--T:41-->
</translate>
 
<translate>
==== Building a docker image with nixpkgs ==== <!--T:42-->
</translate>
<translate>
<!--T:43-->
There is an entry for [https://nixos.org/nixpkgs/manual/#sec-pkgs-dockerTools dockerTools] in the Nixpkgs manual for reference. In the linked page, they give the following example config:
There is an entry for [https://nixos.org/nixpkgs/manual/#sec-pkgs-dockerTools dockerTools] in the Nixpkgs manual for reference. In the linked page, they give the following example config:
</translate>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 202: Line 368:
</syntaxhighlight>
</syntaxhighlight>


<translate>
<!--T:44-->
More examples can be found in the [https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/docker/examples.nix nixpkgs] repo.
More examples can be found in the [https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/docker/examples.nix nixpkgs] repo.
</translate>


<translate>
<!--T:45-->
Also check out the excellent article by [https://lucabrunox.github.io/2016/04/cheap-docker-images-with-nix_15.html lethalman] about building minimal docker images with nix.
Also check out the excellent article by [https://lucabrunox.github.io/2016/04/cheap-docker-images-with-nix_15.html lethalman] about building minimal docker images with nix.
</translate>


==== Reproducible image dates ====
<translate>
==== Reproducible image dates ==== <!--T:46-->
</translate>


<translate>
<!--T:47-->
The manual advises against using <code>created = "now"</code>, as that prevents images from being reproducible.
The manual advises against using <code>created = "now"</code>, as that prevents images from being reproducible.
</translate>


<translate>
<!--T:48-->
An alternative, if using [[flakes]], is to do <code>created = builtins.substring 0 8 self.lastModifiedDate</code>, which uses the commit date, and is therefore reproducible.
An alternative, if using [[flakes]], is to do <code>created = builtins.substring 0 8 self.lastModifiedDate</code>, which uses the commit date, and is therefore reproducible.
</translate>


==== Calculating the sha256 for a pulled Docker image ====
<translate>
==== Calculating the sha256 for a pulled Docker image ==== <!--T:49-->
</translate>


<translate>
<!--T:50-->
The <code>sha256</code> argument of the <code>dockerTools.pullImage</code> function is the checksum of the archive generated by Skopeo. Since the archive contains the name and the tag of the image, Skopeo arguments used to fetch the image have to be identical to those used by the <code>dockerTools.pullImage</code> function.
The <code>sha256</code> argument of the <code>dockerTools.pullImage</code> function is the checksum of the archive generated by Skopeo. Since the archive contains the name and the tag of the image, Skopeo arguments used to fetch the image have to be identical to those used by the <code>dockerTools.pullImage</code> function.
</translate>


<translate>
<!--T:51-->
For instance, the SHA of the following image
For instance, the SHA of the following image
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
pkgs.dockerTools.pullImage{
pkgs.dockerTools.pullImage{
Line 226: Line 414:
</syntaxhighlight>
</syntaxhighlight>


<translate>
<!--T:52-->
can be manually generated with the following shell commands
can be manually generated with the following shell commands
</translate>


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 239: Line 430:
</syntaxhighlight>
</syntaxhighlight>


==== Directly Using Nix in Image Layers ====
<translate>
==== Directly Using Nix in Image Layers ==== <!--T:53-->
</translate>


<translate>
<!--T:54-->
Instead of copying Nix packages into Docker image layers, Docker can be configured to directly utilize the <code>nix-store</code> by integrating with [https://github.com/pdtpartners/nix-snapshotter nix-snapshotter].
Instead of copying Nix packages into Docker image layers, Docker can be configured to directly utilize the <code>nix-store</code> by integrating with [https://github.com/pdtpartners/nix-snapshotter nix-snapshotter].
</translate>


<translate>
<!--T:55-->
This will significantly reduce data duplication and the time it takes to pull images.
This will significantly reduce data duplication and the time it takes to pull images.
</translate>


=== Using Podman as an alternative ===
<translate>
=== Using Podman as an alternative === <!--T:56-->
</translate>


Podman is a daemonless container engine that can run Docker containers without elevated privileges. It can be used as a drop-in replacement for Docker in many cases:<ref>https://podman.io/</ref>
<translate>
<!--T:57-->
Podman is a daemonless container engine that can run Docker containers without elevated privileges. It can be used as a drop-in replacement for Docker in many cases:
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# Enable Podman in configuration.nix
# Enable Podman in configuration.nix
Line 262: Line 466:
</syntaxhighlight>
</syntaxhighlight>


=== Changing Docker Daemon's Data Root ===
<translate>
=== Changing Docker Daemon's Data Root === <!--T:58-->
</translate>


<translate>
<!--T:59-->
By default, the Docker daemon stores images, containers, and build context on the root file system. To use a different storage location, specify a new <code>data-root</code> in your configuration:
By default, the Docker daemon stores images, containers, and build context on the root file system. To use a different storage location, specify a new <code>data-root</code> in your configuration:
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
virtualisation.docker.daemon.settings = {
virtualisation.docker.daemon.settings = {
Line 271: Line 480:
</syntaxhighlight>
</syntaxhighlight>


=== Docker Containers as systemd Services ===
<translate>
=== Docker Containers as systemd Services === <!--T:60-->
</translate>


<translate>
<!--T:61-->
You can run Docker containers as systemd services using the <code>oci-containers</code> module:
You can run Docker containers as systemd services using the <code>oci-containers</code> module:
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
virtualisation.oci-containers = {
virtualisation.oci-containers = {
Line 286: Line 500:
</syntaxhighlight>
</syntaxhighlight>


<translate>
<!--T:62-->
A more advanced example:
A more advanced example:
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{ config, pkgs, ... }:
{ config, pkgs, ... }:
Line 307: Line 524:
</syntaxhighlight>
</syntaxhighlight>


<translate>
<!--T:63-->
See [https://search.nixos.org/options?from=0&size=50&sort=alpha_asc&query=virtualisation.oci-containers oci-containers] for further options.
See [https://search.nixos.org/options?from=0&size=50&sort=alpha_asc&query=virtualisation.oci-containers oci-containers] for further options.
</translate>


==== Usage ====
<translate>
==== Usage ==== <!--T:64-->
</translate>
<translate>
<!--T:65-->
Unless otherwise specified, NixOS uses Podman to run OCI containers. Note that these are '''user-specific''', so running commands with or without sudo can change your output.
Unless otherwise specified, NixOS uses Podman to run OCI containers. Note that these are '''user-specific''', so running commands with or without sudo can change your output.
</translate>


List containers<syntaxhighlight lang="console">
<translate>
<!--T:66-->
List containers
</translate>
<syntaxhighlight lang="console">
# podman ps
# podman ps
</syntaxhighlight>Update image<syntaxhighlight lang="console">
</syntaxhighlight>
<translate>
<!--T:67-->
Update image
</translate>
<syntaxhighlight lang="console">
# podman restart hackagecompare
# podman restart hackagecompare
</syntaxhighlight>List images<syntaxhighlight lang="console">
</syntaxhighlight>
<translate>
<!--T:68-->
List images
</translate>
<syntaxhighlight lang="console">
# podman ls
# podman ls
</syntaxhighlight>Remove container<syntaxhighlight lang="console">
</syntaxhighlight>
<translate>
<!--T:69-->
Remove container
</translate>
<syntaxhighlight lang="console">
# podman rm hackagecompare
# podman rm hackagecompare
</syntaxhighlight>Remove image<syntaxhighlight lang="console">
</syntaxhighlight>
<translate>
<!--T:70-->
Remove image
</translate>
<syntaxhighlight lang="console">
# podman rmi c0d9a5f58afe
# podman rmi c0d9a5f58afe
</syntaxhighlight>Update image<syntaxhighlight lang="console">
</syntaxhighlight>
<translate>
<!--T:71-->
Update image
</translate>
<syntaxhighlight lang="console">
# podman pull chrissound/hackagecomparestats-webserver:latest
# podman pull chrissound/hackagecomparestats-webserver:latest
</syntaxhighlight>Run interactive shell in running container<syntaxhighlight lang="console">
</syntaxhighlight>
<translate>
<!--T:72-->
Run interactive shell in running container
</translate>
<syntaxhighlight lang="console">
# podman exec -ti $ContainerId /bin/sh
# podman exec -ti $ContainerId /bin/sh
</syntaxhighlight>
</syntaxhighlight>


===== Exposing ports from the host =====
<translate>
===== Exposing ports from the host ===== <!--T:73-->
</translate>
<translate>
<!--T:74-->
If you have a service running on the host that you want to connect to from the container, you could try connecting to the hostname <code>host.containers.internal</code> (or <code>host.docker.internal</code> for podman), but this might require additional networking setup
If you have a service running on the host that you want to connect to from the container, you could try connecting to the hostname <code>host.containers.internal</code> (or <code>host.docker.internal</code> for podman), but this might require additional networking setup
</translate>


===== Exposing sockets from the host =====
<translate>
===== Exposing sockets from the host ===== <!--T:75-->
</translate>
<translate>
<!--T:76-->
If you have a service running on the host that exposes a socket, such as mariadb, you can also expose that socket to the container instead. You'll want to expose the folder the socket is in as a volume - so:
If you have a service running on the host that exposes a socket, such as mariadb, you can also expose that socket to the container instead. You'll want to expose the folder the socket is in as a volume - so:
 
</translate>
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
       volumes = [
       volumes = [
Line 339: Line 607:
       ];
       ];
</syntaxhighlight>
</syntaxhighlight>
<translate>
<!--T:77-->
to provide access to <code>/var/run/mysqld/mysqld.sock</code>. Sadly, this means you'll have to restart the container when /var/run/mysqld is replaced, e.g. on an upgrade.


to provide access to <code>/var/run/mysqld/mysqld.sock</code>
</translate>


=== Running the docker daemon from nix-the-package-manager - not NixOS ===
<translate>
=== Running the docker daemon from nix-the-package-manager - not NixOS === <!--T:78-->
</translate>


<translate>
<!--T:79-->
This is not supported. You're better off installing the docker daemon [https://docs.docker.com/engine/install/ "the normal non-nix way"].
This is not supported. You're better off installing the docker daemon [https://docs.docker.com/engine/install/ "the normal non-nix way"].
</translate>


<translate>
<!--T:80-->
See the discourse discussion: [https://discourse.nixos.org/t/how-to-run-docker-daemon-from-nix-not-nixos/43413 How to run docker daemon from nix (not NixOS)] for more.
See the discourse discussion: [https://discourse.nixos.org/t/how-to-run-docker-daemon-from-nix-not-nixos/43413 How to run docker daemon from nix (not NixOS)] for more.
</translate>


== Troubleshooting ==
<translate>
== Troubleshooting == <!--T:81-->
</translate>


=== Common issues ===
<translate>
 
=== Cannot connect to the Docker daemon === <!--T:83-->
==== Cannot connect to the Docker daemon ====
</translate>


<translate>
<!--T:84-->
If you encounter errors connecting to the Docker daemon, check that:
If you encounter errors connecting to the Docker daemon, check that:
- The Docker service is running: `systemctl status docker`
</translate>
- Your user is in the docker group: `groups | grep docker`
<translate>
<!--T:85-->
- The Docker service is running: <code>systemctl status docker</code>
</translate>
<translate>
<!--T:86-->
- Your user is in the docker [[User management#Adding User to a group|group]]: <code>groups | grep docker</code>
</translate>
<translate>
<!--T:87-->
- You've logged out and back in after adding your user to the docker group
- You've logged out and back in after adding your user to the docker group
</translate>


==== Storage space issues ====
<translate>
=== Storage space issues === <!--T:88-->
</translate>


<translate>
<!--T:89-->
When Docker uses too much disk space:
When Docker uses too much disk space:
</translate>
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
# Remove unused containers, networks, images, and volumes
# Remove unused containers, networks, images, and volumes
Line 375: Line 673:
</syntaxhighlight>
</syntaxhighlight>


==== Network conflicts ====
<translate>
=== Network conflicts === <!--T:90-->
</translate>


<translate>
<!--T:91-->
Docker's default subnet (`172.17.0.0/16`) might conflict with your existing network. Configure a different subnet in your `configuration.nix`:
Docker's default subnet (`172.17.0.0/16`) might conflict with your existing network. Configure a different subnet in your `configuration.nix`:
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
virtualisation.docker.daemon.settings = {
virtualisation.docker.daemon.settings = {
Line 389: Line 692:
</syntaxhighlight>
</syntaxhighlight>


=== Cannot connect to public Wi-Fi, when using Docker ===
<translate>
=== Cannot connect to public Wi-Fi, when using Docker === <!--T:92-->
</translate>


<translate>
<!--T:93-->
When connecting to a public Wi-Fi, where the login page's IP-Address is within the Docker network range, accessing the Internet might not be possible. This has been reported when trying to connect to the WIFIonICE of the Deutsche Bahn (DB). They use the <code>172.18.x.x</code> address range.
When connecting to a public Wi-Fi, where the login page's IP-Address is within the Docker network range, accessing the Internet might not be possible. This has been reported when trying to connect to the WIFIonICE of the Deutsche Bahn (DB). They use the <code>172.18.x.x</code> address range.
</translate>


<translate>
<!--T:94-->
This can be resolved by changing the default address pool that Docker uses.
This can be resolved by changing the default address pool that Docker uses.
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
virtualisation.docker = {
virtualisation.docker = {
Line 404: Line 715:
};
};
</syntaxhighlight>
</syntaxhighlight>
<translate>
<!--T:95-->
Restarting the container or Docker might be required.
Restarting the container or Docker might be required.
</translate>
<translate>


== References ==
== References == <!--T:96-->
</translate>


<references/>
<references/>