github.com/slene/docker@v1.8.0-rc1/docs/articles/systemd.md (about) 1 <!--[metadata]> 2 +++ 3 title = "Control and configure Docker with systemd" 4 description = "Controlling and configuring Docker using systemd" 5 keywords = ["docker, daemon, systemd, configuration"] 6 [menu.main] 7 parent = "smn_administrate" 8 weight = 7 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 customise 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 If the `docker.service` file is set to use an `EnvironmentFile` 37 (often pointing to `/etc/sysconfig/docker`) then you can modify the 38 referenced file. 39 40 Check if the `docker.service` uses an `EnvironmentFile`: 41 42 $ sudo systemctl show docker | grep EnvironmentFile 43 EnvironmentFile=-/etc/sysconfig/docker (ignore_errors=yes) 44 45 Alternatively, find out where the service file is located, and look for the 46 property: 47 48 $ sudo systemctl status docker | grep Loaded 49 Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled) 50 $ sudo grep EnvironmentFile /usr/lib/systemd/system/docker.service 51 EnvironmentFile=-/etc/sysconfig/docker 52 53 You can customize the Docker daemon options using override files as explained in the 54 [HTTP Proxy example](#http-proxy) below. The files located in `/usr/lib/systemd/system` 55 or `/lib/systemd/system` contain the default options and should not be edited. 56 57 ### Runtime directory and storage driver 58 59 You may want to control the disk space used for Docker images, containers 60 and volumes by moving it to a separate partition. 61 62 In this example, we'll assume that your `docker.service` file looks something like: 63 64 [Unit] 65 Description=Docker Application Container Engine 66 Documentation=https://docs.docker.com 67 After=network.target docker.socket 68 Requires=docker.socket 69 70 [Service] 71 Type=notify 72 EnvironmentFile=-/etc/sysconfig/docker 73 ExecStart=/usr/bin/docker daemon -H fd:// $OPTIONS 74 LimitNOFILE=1048576 75 LimitNPROC=1048576 76 77 [Install] 78 Also=docker.socket 79 80 This will allow us to add extra flags to the `/etc/sysconfig/docker` file by 81 setting `OPTIONS`: 82 83 OPTIONS="--graph /mnt/docker-data --storage-driver btrfs" 84 85 You can also set other environment variables in this file, for example, the 86 `HTTP_PROXY` environment variables described below. 87 88 ### HTTP proxy 89 90 This example overrides the default `docker.service` file. 91 92 If you are behind a HTTP proxy server, for example in corporate settings, 93 you will need to add this configuration in the Docker systemd service file. 94 95 First, create a systemd drop-in directory for the docker service: 96 97 mkdir /etc/systemd/system/docker.service.d 98 99 Now create a file called `/etc/systemd/system/docker.service.d/http-proxy.conf` 100 that adds the `HTTP_PROXY` environment variable: 101 102 [Service] 103 Environment="HTTP_PROXY=http://proxy.example.com:80/" 104 105 If you have internal Docker registries that you need to contact without 106 proxying you can specify them via the `NO_PROXY` environment variable: 107 108 Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.0/8,docker-registry.somecorporation.com" 109 110 Flush changes: 111 112 $ sudo systemctl daemon-reload 113 114 Verify that the configuration has been loaded: 115 116 $ sudo systemctl show docker --property Environment 117 Environment=HTTP_PROXY=http://proxy.example.com:80/ 118 119 Restart Docker: 120 121 $ sudo systemctl restart docker 122 123 ## Manually creating the systemd unit files 124 125 When installing the binary without a package, you may want 126 to integrate Docker with systemd. For this, simply install the two unit files 127 (service and socket) from [the github 128 repository](https://github.com/docker/docker/tree/master/contrib/init/systemd) 129 to `/etc/systemd/system`. 130 131