github.com/feiyang21687/docker@v1.5.0/docs/sources/articles/systemd.md (about)

     1  page_title: Controlling and configuring Docker using Systemd
     2  page_description: Controlling and configuring Docker using Systemd
     3  page_keywords: docker, daemon, systemd, configuration
     4  
     5  # Controlling and configuring Docker using Systemd
     6  
     7  Many Linux distributions use systemd to start the Docker daemon. This document
     8  shows a few examples of how to customise Docker's settings.
     9  
    10  ## Starting the Docker daemon
    11  
    12  Once Docker is installed, you will need to start the Docker daemon.
    13  
    14      $ sudo systemctl start docker
    15      # or on older distributions, you may need to use
    16      $ sudo service docker start
    17  
    18  If you want Docker to start at boot, you should also:
    19  
    20      $ sudo systemctl enable docker
    21      # or on older distributions, you may need to use
    22      $ sudo chkconfig docker on
    23  
    24  ## Custom Docker daemon options
    25  
    26  There are a number of ways to configure the daemon flags and environment variables
    27  for your Docker daemon. 
    28  
    29  If the `docker.service` file is set to use an `EnvironmentFile`
    30  (often pointing to `/etc/sysconfig/docker`) then you can modify the
    31  referenced file.
    32  
    33  Or, you may need to edit the `docker.service` file, which can be in `/usr/lib/systemd/system`
    34  or `/etc/systemd/service`.
    35  
    36  ### Runtime directory and storage driver
    37  
    38  You may want to control the disk space used for Docker images, containers
    39  and volumes by moving it to a separate partition.
    40  
    41  In this example, we'll assume that your `docker.service` file looks something like:
    42  
    43      [Unit]
    44      Description=Docker Application Container Engine
    45      Documentation=http://docs.docker.com
    46      After=network.target docker.socket
    47      Requires=docker.socket
    48  
    49      [Service]
    50      Type=notify
    51      EnvironmentFile=-/etc/sysconfig/docker
    52      ExecStart=/usr/bin/docker -d -H fd:// $OPTIONS
    53      LimitNOFILE=1048576
    54      LimitNPROC=1048576
    55  
    56      [Install]
    57      Also=docker.socket
    58  
    59  This will allow us to add extra flags to the `/etc/sysconfig/docker` file by
    60  setting `OPTIONS`:
    61  
    62      OPTIONS="--graph /mnt/docker-data --storage-driver btrfs"
    63  
    64  You can also set other environment variables in this file, for example, the
    65  `HTTP_PROXY` environment variables described below.
    66  
    67  ### HTTP Proxy
    68  
    69  This example overrides the default `docker.service` file.
    70  
    71  If you are behind a HTTP proxy server, for example in corporate settings,
    72  you will need to add this configuration in the Docker systemd service file.
    73  
    74  First, create a systemd drop-in directory for the docker service:
    75  
    76      mkdir /etc/systemd/system/docker.service.d
    77  
    78  Now create a file called `/etc/systemd/system/docker.service.d/http-proxy.conf`
    79  that adds the `HTTP_PROXY` environment variable:
    80  
    81      [Service]
    82      Environment="HTTP_PROXY=http://proxy.example.com:80/"
    83  
    84  If you have internal Docker registries that you need to contact without
    85  proxying you can specify them via the `NO_PROXY` environment variable:
    86  
    87      Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.0/8,docker-registry.somecorporation.com"
    88  
    89  Flush changes:
    90  
    91      $ sudo systemctl daemon-reload
    92  
    93  Restart Docker:
    94  
    95      $ sudo systemctl restart docker
    96  
    97  ## Manually creating the systemd unit files
    98  
    99  When installing the binary without a package, you may want
   100  to integrate Docker with systemd. For this, simply install the two unit files
   101  (service and socket) from [the github
   102  repository](https://github.com/docker/docker/tree/master/contrib/init/systemd)
   103  to `/etc/systemd/system`.
   104  
   105