Configure Docker Container



Estimated reading time: 8 minutes

Docker includes multiple logging mechanisms to help youget information from running containers and services.These mechanisms are called logging drivers. Each Docker daemon has a defaultlogging driver, which each container uses unless you configure it to use adifferent logging driver, or “log-driver” for short.

As a default, Docker uses the json-file logging driver, whichcaches container logs as JSON internally. In addition to using the logging driversincluded with Docker, you can also implement and use logging driver plugins.

Tip: use the “local” logging driver to prevent disk-exhaustion

Configure Docker Container

Docker includes multiple logging mechanisms to help you get information from running containers and services. These mechanisms are called logging drivers. Each Docker daemon has a default logging driver, which each container uses unless you configure it to use a different logging driver, or “log-driver” for short. Once you have the image, move on to deploying a new MySQL container with: docker run -name=containername -d mysql/mysql-server:latest. Replace containername with the name of your choice. If you do not provide a name, Docker generates a random one. The -d option instructs Docker to run the container as a service in the background.

By default, no log-rotation is performed. As a result, log-files stored by thedefault json-file logging driver logging driver can cause a significant amount of disk space to be used for containers that generate muchoutput, which can lead to disk space exhaustion.

Once you have the image, move on to deploying a new MySQL container with: docker run -name=containername -d mysql/mysql-server:latest. Replace containername with the name of your choice. If you do not provide a name, Docker generates a random one. The -d option instructs Docker to run the container as a service in the background. Official Jenkins Docker image. Change the Docker image of a custom container. To change an existing custom container app from the current Docker image to a new image, use the following command: az webapp config container set -name -resource-group -docker-custom-image-name docker-hub-repo/ Use an image from a private registry.

Docker keeps the json-file logging driver (without log-rotation) as a defaultto remain backward compatibility with older versions of Docker, and for situationswhere Docker is used as runtime for Kubernetes.

Configure Docker Container

For other situations, the “local” logging driver is recommended as it performslog-rotation by default, and uses a more efficient file format. Refer to theConfigure the default logging driversection below to learn how to configure the “local” logging driver as a default,and the local file logging driver page for more details about the“local” logging driver.

Configure the default logging driver

To configure the Docker daemon to default to a specific logging driver, set thevalue of log-driver to the name of the logging driver in the daemon.jsonconfiguration file. Refer to the “daemon configuration file” section in thedockerd reference manualfor details.

Docker

The default logging driver is json-file. The following example sets the defaultlogging driver to the local log driver:

If the logging driver has configurable options, you can set them in thedaemon.json file as a JSON object with the key log-opts. The followingexample sets two configurable options on the json-file logging driver:

Restart Docker for the changes to take effect for newly created containers.Existing containers do not use the new logging configuration.

Note

log-opts configuration options in the daemon.json configuration file mustbe provided as strings. Boolean and numeric values (such as the value formax-file in the example above) must therefore be enclosed in quotes (').

Configure Docker Container

If you do not specify a logging driver, the default is json-file.To find the current default logging driver for the Docker daemon, rundocker info and search for Logging Driver. You can use the followingcommand on Linux, macOS, or PowerShell on Windows:

Note

Changing the default logging driver or logging driver options in the daemonconfiguration only affects containers that are created after the configurationis changed. Existing containers retain the logging driver options that wereused when they were created. To update the logging driver for a container, thecontainer has to be re-created with the desired options.Refer to the configure the logging driver for a containersection below to learn how to find the logging-driver configuration of acontainer.

Configure the logging driver for a container

When you start a container, you can configure it to use a different loggingdriver than the Docker daemon’s default, using the --log-driver flag. If thelogging driver has configurable options, you can set them using one or moreinstances of the --log-opt <NAME>=<VALUE> flag. Even if the container uses thedefault logging driver, it can use different configurable options.

The following example starts an Alpine container with the none logging driver.

To find the current logging driver for a running container, if the daemonis using the json-file logging driver, run the following docker inspectcommand, substituting the container name or ID for <CONTAINER>:

Configure the delivery mode of log messages from container to log driver

Docker provides two modes for delivering messages from the container to the logdriver:

  • (default) direct, blocking delivery from container to driver
  • non-blocking delivery that stores log messages in an intermediate per-containerring buffer for consumption by driver

The non-blocking message delivery mode prevents applications from blocking dueto logging back pressure. Applications are likely to fail in unexpected ways whenSTDERR or STDOUT streams block.

Warning

When the buffer is full and a new message is enqueued, the oldest message inmemory is dropped. Dropping messages is often preferred to blocking thelog-writing process of an application.

The mode log option controls whether to use the blocking (default) ornon-blocking message delivery.

The max-buffer-size log option controls the size of the ring buffer used forintermediate message storage when mode is set to non-blocking. max-buffer-sizedefaults to 1 megabyte.

The following example starts an Alpine container with log output in non-blockingmode and a 4 megabyte buffer:

Use environment variables or labels with logging drivers

Some logging drivers add the value of a container’s --env|-e or --labelflags to the container’s logs. This example starts a container using the Dockerdaemon’s default logging driver (let’s assume json-file) but sets theenvironment variable os=ubuntu.

If the logging driver supports it, this adds additional fields to the loggingoutput. The following output is generated by the json-file logging driver:

Supported logging drivers

The following logging drivers are supported. See the link to each driver’sdocumentation for its configurable options, if applicable. If you are usinglogging driver plugins, you maysee more options.

DriverDescription
noneNo logs are available for the container and docker logs does not return any output.
localLogs are stored in a custom format designed for minimal overhead.
json-fileThe logs are formatted as JSON. The default logging driver for Docker.
syslogWrites logging messages to the syslog facility. The syslog daemon must be running on the host machine.
journaldWrites log messages to journald. The journald daemon must be running on the host machine.
gelfWrites log messages to a Graylog Extended Log Format (GELF) endpoint such as Graylog or Logstash.
fluentdWrites log messages to fluentd (forward input). The fluentd daemon must be running on the host machine.
awslogsWrites log messages to Amazon CloudWatch Logs.
splunkWrites log messages to splunk using the HTTP Event Collector.
etwlogsWrites log messages as Event Tracing for Windows (ETW) events. Only available on Windows platforms.
gcplogsWrites log messages to Google Cloud Platform (GCP) Logging.
logentriesWrites log messages to Rapid7 Logentries.

Note

When using Docker Engine 19.03 or older, the docker logs commandis only functional for the local, json-file and journald logging drivers.Docker 20.10 and up introduces “dual logging”, which uses a local buffer thatallows you to use the docker logs command for any logging driver. Refer toreading logs when using remote logging drivers for details.

Limitations of logging drivers

  • Reading log information requires decompressing rotated log files, which causesa temporary increase in disk usage (until the log entries from the rotatedfiles are read) and an increased CPU usage while decompressing.
  • The capacity of the host storage where the Docker data directory residesdetermines the maximum size of the log file information.
docker, logging, driver-->

The Docker Engine and client aren't included with Windows and need to be installed and configured individually. Furthermore, the Docker Engine can accept many custom configurations. Some examples include configuring how the daemon accepts incoming requests, default networking options, and debug/log settings. On Windows, these configurations can be specified in a configuration file or by using Windows Service control manager. This document details how to install and configure the Docker Engine, and also provides some examples of commonly used configurations.

Install Docker

You need Docker in order to work with Windows Containers. Docker consists of the Docker Engine (dockerd.exe), and the Docker client (docker.exe). The easiest way to get everything installed is in the quickstart guide, which will help you get everything set up and run your first container.

For scripted installations, see Use a script to install Docker EE.

Before you can use Docker, you'll need to install the container images. For more information, see docs for our container base images.

Configure Docker with a configuration file

The preferred method for configuring the Docker Engine on Windows is using a configuration file. The configuration file can be found at 'C:ProgramDataDockerconfigdaemon.json'. You can create this file if it doesn't already exist.

Note

Not every available Docker configuration option applies to Docker on Windows. The following example shows the configuration options that do apply. For more information about Docker Engine configuration, see Docker daemon configuration file.

You only need to add the desired configuration changes to the configuration file. For example, the following sample configures the Docker Engine to accept incoming connections on port 2375. All other configuration options will use default values.

Likewise, the following sample configures the Docker daemon to keep images and containers in an alternate path. If not specified, thedefault is c:programdatadocker.

The following sample configures the Docker daemon to only accept secured connections over port 2376.

Configure Docker on the Docker service

The Docker Engine can also be configured by modifying the Docker service with sc config. Using this method, Docker Engine flags are set directly on the Docker service. Run the following command in a command prompt (cmd.exe not PowerShell):

Note

You don't need to run this command if your daemon.json file already contains the 'hosts': ['tcp://0.0.0.0:2375'] entry.

Common configuration

The following configuration file examples show common Docker configurations. These can be combined into a single configuration file.

Default network creation

To configure the Docker Engine so that it doesn't create a default NAT network, use the following configuration.

For more information, see Manage Docker Networks.

Set Docker security group

When you've signed in to the Docker host and are locally running Docker commands, these commands are run through a named pipe. By default, only members of the Administrators group can access the Docker Engine through the named pipe. To specify a security group that has this access, use the group flag.

Proxy configuration

To set proxy information for docker search and docker pull, create a Windows environment variable with the name HTTP_PROXY or HTTPS_PROXY, and a value of the proxy information. This can be completed with PowerShell using a command similar to this:

Once the variable has been set, restart the Docker service.

For more information, see Windows Configuration File on Docker.com.

How to uninstall Docker

This section will tell you how to uninstall Docker and perform a full cleanup of Docker system components from your Windows 10 or Windows Server 2016 system.

Note

You must run all commands in these instructions from an elevated PowerShell session.

Prepare your system for Docker's removal

Before you uninstall Docker, make sure no containers are running on your system.

Run the following cmdlets to check for running containers:

It's also good practice to remove all containers, container images, networks, and volumes from your system before removing Docker. You can do this by running the following cmdlet:

Uninstall Docker

Next, you'll need to actually uninstall Docker.

To uninstall Docker on Windows 10

  • Go to Settings > Apps on your Windows 10 machine
  • Under Apps & Features, find Docker for Windows
  • Go to Docker for Windows > Uninstall

To uninstall Docker on Windows Server 2016:

From an elevated PowerShell session, use the Uninstall-Package and Uninstall-Module cmdlets to remove the Docker module and its corresponding Package Management Provider from your system, as shown in the following example:

Tip

You can find the Package Provider that you used to install Docker with PS C:> Get-PackageProvider -Name *Docker*

Clean up Docker data and system components

After you uninstall Docker, you'll need to remove Docker's default networks so their configuration won't remain on your system after Docker is gone. You can do this by running the following cmdlet:

Configure Docker Container Windows 10

To remove Docker's default networks on Windows Server 2016.

Run the following cmdlet to remove Docker's program data from your system:

You may also want to remove the Windows optional features associated with Docker/containers on Windows.

This includes the 'Containers' feature, which is automatically enabled on any Windows 10 or Windows Server 2016 when Docker is installed. It may also include the 'Hyper-V' feature, which is automatically enabled on Windows 10 when Docker is installed, but must be explicitly enabled on Windows Server 2016.

Important

The Hyper-V feature is a general virtualization feature that enables much more than just containers. Before disabling the Hyper-V feature, make sure there are no other virtualized components on your system that require Hyper-V.

Configure Docker Container Model

To remove Windows features on Windows 10:

  • Go to Control Panel > Programs > Programs and Features > Turn Windows features on or off.
  • Find the name of the feature or features you want to disable—in this case, Containers and (optionally) Hyper-V.
  • Uncheck the box next to the name of the feature you want to disable.
  • Select 'OK'

To remove Windows features on Windows Server 2016:

Configure Docker Container Box

From an elevated PowerShell session, run the following cmdlets to disable the Containers and (optionally) Hyper-V features from your system:

Reboot your system

To finish uninstallation and cleanup, run the following cmdlet from an elevated PowerShell session to reboot your system: