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