github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/docs/admin/systemd.md (about)

     1  <!--[metadata]>
     2  +++
     3  aliases = ["/engine/articles/systemd/"]
     4  title = "Control and configure Docker with systemd"
     5  description = "Controlling and configuring Docker using systemd"
     6  keywords = ["docker, daemon, systemd,  configuration"]
     7  [menu.main]
     8  parent = "engine_admin"
     9  +++
    10  <![end-metadata]-->
    11  
    12  # Control and configure Docker with systemd
    13  
    14  Many Linux distributions use systemd to start the Docker daemon. This document
    15  shows a few examples of how to customize Docker's settings.
    16  
    17  ## Starting the Docker daemon
    18  
    19  Once Docker is installed, you will need to start the Docker daemon.
    20  
    21      $ sudo systemctl start docker
    22      # or on older distributions, you may need to use
    23      $ sudo service docker start
    24  
    25  If you want Docker to start at boot, you should also:
    26  
    27      $ sudo systemctl enable docker
    28      # or on older distributions, you may need to use
    29      $ sudo chkconfig docker on
    30  
    31  ## Custom Docker daemon options
    32  
    33  There are a number of ways to configure the daemon flags and environment variables
    34  for your Docker daemon.
    35  
    36  The recommended way is to use a systemd drop-in file (as described in
    37  the <a target="_blank"
    38  href="https://www.freedesktop.org/software/systemd/man/systemd.unit.html">systemd.unit</a>
    39  documentation). These are local files named `<something>.conf` in the
    40  `/etc/systemd/system/docker.service.d` directory. This could also be
    41  `/etc/systemd/system/docker.service`, which also works for overriding
    42  the defaults from `/lib/systemd/system/docker.service`.
    43  
    44  However, if you had previously used a package which had an
    45  `EnvironmentFile` (often pointing to `/etc/sysconfig/docker`) then for
    46  backwards compatibility, you drop a file with a `.conf` extension into
    47  the `/etc/systemd/system/docker.service.d` directory including the
    48  following:
    49  
    50      [Service]
    51      EnvironmentFile=-/etc/sysconfig/docker
    52      EnvironmentFile=-/etc/sysconfig/docker-storage
    53      EnvironmentFile=-/etc/sysconfig/docker-network
    54      ExecStart=
    55      ExecStart=/usr/bin/docker daemon -H fd:// $OPTIONS \
    56                $DOCKER_STORAGE_OPTIONS \
    57                $DOCKER_NETWORK_OPTIONS \
    58                $BLOCK_REGISTRY \
    59                $INSECURE_REGISTRY
    60  
    61  To check if the `docker.service` uses an `EnvironmentFile`:
    62  
    63      $ systemctl show docker | grep EnvironmentFile
    64      EnvironmentFile=-/etc/sysconfig/docker (ignore_errors=yes)
    65  
    66  Alternatively, find out where the service file is located:
    67  
    68      $ systemctl show --property=FragmentPath docker
    69      FragmentPath=/usr/lib/systemd/system/docker.service
    70      $ grep EnvironmentFile /usr/lib/systemd/system/docker.service
    71      EnvironmentFile=-/etc/sysconfig/docker
    72  
    73  You can customize the Docker daemon options using override files as explained in the
    74  [HTTP Proxy example](#http-proxy) below. The files located in `/usr/lib/systemd/system`
    75  or `/lib/systemd/system` contain the default options and should not be edited.
    76  
    77  ### Runtime directory and storage driver
    78  
    79  You may want to control the disk space used for Docker images, containers
    80  and volumes by moving it to a separate partition.
    81  
    82  In this example, we'll assume that your `docker.service` file looks something like:
    83  
    84      [Unit]
    85      Description=Docker Application Container Engine
    86      Documentation=https://docs.docker.com
    87      After=network.target docker.socket
    88      Requires=docker.socket
    89  
    90      [Service]
    91      Type=notify
    92      ExecStart=/usr/bin/docker daemon -H fd://
    93      LimitNOFILE=1048576
    94      LimitNPROC=1048576
    95      TasksMax=1048576
    96  
    97      [Install]
    98      Also=docker.socket
    99  
   100  This will allow us to add extra flags via a drop-in file (mentioned above) by
   101  placing a file containing the following in the `/etc/systemd/system/docker.service.d`
   102  directory:
   103  
   104      [Service]
   105      ExecStart=
   106      ExecStart=/usr/bin/docker daemon -H fd:// --graph="/mnt/docker-data" --storage-driver=overlay
   107  
   108  You can also set other environment variables in this file, for example, the
   109  `HTTP_PROXY` environment variables described below.
   110  
   111  To modify the ExecStart configuration, specify an empty configuration followed
   112  by a new configuration as follows:
   113  
   114      [Service]
   115      ExecStart=
   116      ExecStart=/usr/bin/docker daemon -H fd:// --bip=172.17.42.1/16
   117  
   118  If you fail to specify an empty configuration, Docker reports an error such as:
   119  
   120      docker.service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.
   121  
   122  ### HTTP proxy
   123  
   124  This example overrides the default `docker.service` file.
   125  
   126  If you are behind an HTTP proxy server, for example in corporate settings,
   127  you will need to add this configuration in the Docker systemd service file.
   128  
   129  First, create a systemd drop-in directory for the docker service:
   130  
   131      mkdir /etc/systemd/system/docker.service.d
   132  
   133  Now create a file called `/etc/systemd/system/docker.service.d/http-proxy.conf`
   134  that adds the `HTTP_PROXY` environment variable:
   135  
   136      [Service]
   137      Environment="HTTP_PROXY=http://proxy.example.com:80/"
   138  
   139  If you have internal Docker registries that you need to contact without
   140  proxying you can specify them via the `NO_PROXY` environment variable:
   141  
   142      Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"
   143  
   144  Flush changes:
   145  
   146      $ sudo systemctl daemon-reload
   147  
   148  Verify that the configuration has been loaded:
   149  
   150      $ systemctl show --property=Environment docker
   151      Environment=HTTP_PROXY=http://proxy.example.com:80/
   152  
   153  Restart Docker:
   154  
   155      $ sudo systemctl restart docker
   156  
   157  ## Manually creating the systemd unit files
   158  
   159  When installing the binary without a package, you may want
   160  to integrate Docker with systemd. For this, simply install the two unit files
   161  (service and socket) from [the github
   162  repository](https://github.com/docker/docker/tree/master/contrib/init/systemd)
   163  to `/etc/systemd/system`.