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