Customizing Docker
The Docker systemd unit can be customized by overriding the unit that ships with the default Flatcar Container Linux settings or through a drop-in unit. Common use-cases for doing this are covered below.
For switching to using containerd with Kubernetes, there is an extra guide .
Use a custom containerd configuration
The default configuration under /usr/share/containerd/config.toml can’t be changed but you can copy it to /etc/containerd/config.toml and modify it.
Create a /etc/systemd/system/containerd.service.d/10-use-custom-config.conf unit drop-in file to select the new configuration:
|
|
On a running system, execute systemctl daemon-reload ; systemctl restart containerd for it to take effect.
Enable the remote API on a new socket
Create a file called /etc/systemd/system/docker-tcp.socket to make Docker available on a TCP socket on port 2375.
|
|
Then enable this new socket:
|
|
Test that it’s working:
|
|
Butane Config
To enable the remote API on every Flatcar Container Linux machine in a cluster, use a Butane Config . We need to provide the new socket file and Docker’s socket activation support will automatically start using the socket:
|
|
To keep access to the port local, replace the ListenStream configuration above with:
|
|
Enable the remote API with TLS authentication
Docker TLS configuration consists of three parts: keys creation, configuring new systemd socket unit and systemd drop-in configuration.
TLS keys creation
Please follow the
instruction
to know how to create self-signed certificates and private keys. Then copy the following files into /etc/docker Flatcar Container Linux’s directory and fix their permissions:
|
|
On your local host copy certificates into ~/.docker:
|
|
Enable the secure remote API on a new socket
Create a file called /etc/systemd/system/docker-tls-tcp.socket to make Docker available on a secured TCP socket on port 2376.
|
|
Then enable this new socket:
|
|
Drop-in configuration
Create /etc/systemd/system/docker.service.d/10-tls-verify.conf
drop-in
for systemd Docker service:
|
|
Reload systemd config files and restart docker service:
|
|
Now you can access your Docker’s API through TLS secured connection:
|
|
If you’ve experienceed problems connection to remote Docker API using TLS connection, you can debug it with curl:
|
|
Or on your Flatcar Container Linux host:
|
|
In addition you can export environment variables and use docker client without additional options:
|
|
Butane Config (TLS)
A Butane Config for Docker TLS authentication will look like:
|
|
Use attached storage for Docker images
Docker containers can be very large and debugging a build process makes it easy to accumulate hundreds of containers. It’s advantageous to use attached storage to expand your capacity for container images. Check out the guide to
mounting storage to your Flatcar Container Linux machine
for an example of how to bind mount storage into /var/lib/docker.
Enabling the Docker debug flag
Set the --debug (-D) flag in the DOCKER_OPTS environment variable by using a drop-in file. For example, the following could be written to /etc/systemd/system/docker.service.d/10-debug.conf:
|
|
Now tell systemd about the new configuration and restart Docker:
|
|
To test our debugging stream, run a Docker command and then read the systemd journal, which should contain the output:
|
|
Butane Config (flags)
If you need to modify a flag across many machines, you can add the flag with a Butane Config:
|
|
Use an HTTP proxy
If you’re operating in a locked down networking environment, you can specify an HTTP proxy for Docker to use via an environment variable. First, create a directory for drop-in configuration for Docker:
|
|
Now, create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the environment variable:
|
|
To apply the change, reload the unit and restart Docker:
|
|
Proxy environment variables can also be set system-wide .
Butane Config (proxy)
The easiest way to use this proxy on all of your machines is via a Butane Config:
|
|
Increase ulimits
If you need to increase certain ulimits that are too low for your application by default, like memlock, you will need to modify the Docker service to increase the limit. First, create a directory for drop-in configuration for Docker:
|
|
Now, create a file called /etc/systemd/system/docker.service.d/increase-ulimit.conf that adds increased limit:
|
|
To apply the change, reload the unit and restart Docker:
|
|
Butane Config (ulimits)
The easiest way to use these new ulimits on all of your machines is via a Butane Config:
|
|
Using a dockercfg file for authentication
A json file .dockercfg can be created in your home directory that holds authentication information for a public or private Docker registry.