github.com/walkingsparrow/docker@v1.4.2-0.20151218153551-b708a2249bfa/docs/articles/configuring.md (about) 1 <!--[metadata]> 2 +++ 3 title = "Configuring and running Docker" 4 description = "Configuring and running the Docker daemon on various distributions" 5 keywords = ["docker, daemon, configuration, running, process managers"] 6 [menu.main] 7 parent = "smn_administrate" 8 weight = 3 9 +++ 10 <![end-metadata]--> 11 12 # Configuring and running Docker on various distributions 13 14 After successfully installing Docker, the `docker` daemon runs with its default 15 configuration. 16 17 In a production environment, system administrators typically configure the 18 `docker` daemon to start and stop according to an organization's requirements. In most 19 cases, the system administrator configures a process manager such as `SysVinit`, `Upstart`, 20 or `systemd` to manage the `docker` daemon's start and stop. 21 22 ### Running the docker daemon directly 23 24 The `docker` daemon can be run directly using the `docker daemon` command. By default it listens on 25 the Unix socket `unix:///var/run/docker.sock` 26 27 $ docker daemon 28 29 INFO[0000] +job init_networkdriver() 30 INFO[0000] +job serveapi(unix:///var/run/docker.sock) 31 INFO[0000] Listening for HTTP on unix (/var/run/docker.sock) 32 ... 33 ... 34 35 ### Configuring the docker daemon directly 36 37 If you're running the `docker` daemon directly by running `docker daemon` instead 38 of using a process manager, you can append the configuration options to the `docker` run 39 command directly. Other options can be passed to the `docker` daemon to configure it. 40 41 Some of the daemon's options are: 42 43 | Flag | Description | 44 |-----------------------|-----------------------------------------------------------| 45 | `-D`, `--debug=false` | Enable or disable debug mode. By default, this is false. | 46 | `-H`,`--host=[]` | Daemon socket(s) to connect to. | 47 | `--tls=false` | Enable or disable TLS. By default, this is false. | 48 49 50 Here is a an example of running the `docker` daemon with configuration options: 51 52 $ docker daemon -D --tls=true --tlscert=/var/docker/server.pem --tlskey=/var/docker/serverkey.pem -H tcp://192.168.59.3:2376 53 54 These options : 55 56 - Enable `-D` (debug) mode 57 - Set `tls` to true with the server certificate and key specified using `--tlscert` and `--tlskey` respectively 58 - Listen for connections on `tcp://192.168.59.3:2376` 59 60 The command line reference has the [complete list of daemon flags](../reference/commandline/daemon.md) 61 with explanations. 62 63 ## Ubuntu 64 65 As of `14.04`, Ubuntu uses Upstart as a process manager. By default, Upstart jobs 66 are located in `/etc/init` and the `docker` Upstart job can be found at `/etc/init/docker.conf`. 67 68 After successfully [installing Docker for Ubuntu](../installation/ubuntulinux.md), 69 you can check the running status using Upstart in this way: 70 71 $ sudo status docker 72 73 docker start/running, process 989 74 75 ### Running Docker 76 77 You can start/stop/restart the `docker` daemon using 78 79 $ sudo start docker 80 81 $ sudo stop docker 82 83 $ sudo restart docker 84 85 86 ### Configuring Docker 87 88 You configure the `docker` daemon in the `/etc/default/docker` file on your 89 system. You do this by specifying values in a `DOCKER_OPTS` variable. 90 91 To configure Docker options: 92 93 1. Log into your host as a user with `sudo` or `root` privileges. 94 95 2. If you don't have one, create the `/etc/default/docker` file on your host. Depending on how 96 you installed Docker, you may already have this file. 97 98 3. Open the file with your favorite editor. 99 100 ``` 101 $ sudo vi /etc/default/docker 102 ``` 103 104 4. Add a `DOCKER_OPTS` variable with the following options. These options are appended to the 105 `docker` daemon's run command. 106 107 ``` 108 DOCKER_OPTS="-D --tls=true --tlscert=/var/docker/server.pem --tlskey=/var/docker/serverkey.pem -H tcp://192.168.59.3:2376" 109 ``` 110 111 These options : 112 113 - Enable `-D` (debug) mode 114 - Set `tls` to true with the server certificate and key specified using `--tlscert` and `--tlskey` respectively 115 - Listen for connections on `tcp://192.168.59.3:2376` 116 117 The command line reference has the [complete list of daemon flags](../reference/commandline/daemon.md) 118 with explanations. 119 120 121 5. Save and close the file. 122 123 6. Restart the `docker` daemon. 124 125 ``` 126 $ sudo restart docker 127 ``` 128 129 7. Verify that the `docker` daemon is running as specified with the `ps` command. 130 131 ``` 132 $ ps aux | grep docker | grep -v grep 133 ``` 134 135 ### Logs 136 137 By default logs for Upstart jobs are located in `/var/log/upstart` and the logs for `docker` daemon 138 can be located at `/var/log/upstart/docker.log` 139 140 $ tail -f /var/log/upstart/docker.log 141 INFO[0000] Loading containers: done. 142 INFO[0000] docker daemon: 1.6.0 4749651; execdriver: native-0.2; graphdriver: aufs 143 INFO[0000] +job acceptconnections() 144 INFO[0000] -job acceptconnections() = OK (0) 145 INFO[0000] Daemon has completed initialization 146 147 148 ## CentOS / Red Hat Enterprise Linux / Fedora 149 150 As of `7.x`, CentOS and RHEL use `systemd` as the process manager. As of `21`, Fedora uses 151 `systemd` as its process manager. 152 153 After successfully installing Docker for [CentOS](../installation/centos.md)/[Red Hat Enterprise Linux](../installation/rhel.md)/[Fedora](../installation/fedora.md), you can check the running status in this way: 154 155 $ sudo systemctl status docker 156 157 ### Running Docker 158 159 You can start/stop/restart the `docker` daemon using 160 161 $ sudo systemctl start docker 162 163 $ sudo systemctl stop docker 164 165 $ sudo systemctl restart docker 166 167 If you want Docker to start at boot, you should also: 168 169 $ sudo systemctl enable docker 170 171 ### Configuring Docker 172 173 For CentOS 7.x and RHEL 7.x you can [control and configure Docker with systemd](systemd.md). 174 175 Previously, for CentOS 6.x and RHEL 6.x you would configure the `docker` daemon in 176 the `/etc/sysconfig/docker` file on your system. You would do this by specifying 177 values in a `other_args` variable. For a short time in CentOS 7.x and RHEL 7.x you 178 would specify values in a `OPTIONS` variable. This is no longer recommended in favor 179 of using systemd directly. 180 181 For this section, we will use CentOS 7.x as an example to configure the `docker` daemon. 182 183 To configure Docker options: 184 185 1. Log into your host as a user with `sudo` or `root` privileges. 186 187 2. Create the `/etc/systemd/system/docker.service.d` directory. 188 189 ``` 190 $ sudo mkdir /etc/systemd/system/docker.service.d 191 ``` 192 193 3. Create a `/etc/systemd/system/docker.service.d/docker.conf` file. 194 195 4. Open the file with your favorite editor. 196 197 ``` 198 $ sudo vi /etc/systemd/system/docker.service.d/docker.conf 199 ``` 200 201 5. Override the `ExecStart` configuration from your `docker.service` file to customize 202 the `docker` daemon. To modify the `ExecStart` configuration you have to specify 203 an empty configuration followed by a new one as follows: 204 205 ``` 206 [Service] 207 ExecStart= 208 ExecStart=/usr/bin/docker daemon -H fd:// -D --tls=true --tlscert=/var/docker/server.pem --tlskey=/var/docker/serverkey.pem -H tcp://192.168.59.3:2376 209 ``` 210 211 These options : 212 213 - Enable `-D` (debug) mode 214 - Set `tls` to true with the server certificate and key specified using `--tlscert` and `--tlskey` respectively 215 - Listen for connections on `tcp://192.168.59.3:2376` 216 217 The command line reference has the [complete list of daemon flags](../reference/commandline/daemon.md) 218 with explanations. 219 220 6. Save and close the file. 221 222 7. Flush changes. 223 224 ``` 225 $ sudo systemctl daemon-reload 226 ``` 227 228 8. Restart the `docker` daemon. 229 230 ``` 231 $ sudo systemctl restart docker 232 ``` 233 234 9. Verify that the `docker` daemon is running as specified with the `ps` command. 235 236 ``` 237 $ ps aux | grep docker | grep -v grep 238 ``` 239 240 ### Logs 241 242 systemd has its own logging system called the journal. The logs for the `docker` daemon can 243 be viewed using `journalctl -u docker` 244 245 $ sudo journalctl -u docker 246 May 06 00:22:05 localhost.localdomain systemd[1]: Starting Docker Application Container Engine... 247 May 06 00:22:05 localhost.localdomain docker[2495]: time="2015-05-06T00:22:05Z" level="info" msg="+job serveapi(unix:///var/run/docker.sock)" 248 May 06 00:22:05 localhost.localdomain docker[2495]: time="2015-05-06T00:22:05Z" level="info" msg="Listening for HTTP on unix (/var/run/docker.sock)" 249 May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="+job init_networkdriver()" 250 May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="-job init_networkdriver() = OK (0)" 251 May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="Loading containers: start." 252 May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="Loading containers: done." 253 May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="docker daemon: 1.5.0-dev fc0329b/1.5.0; execdriver: native-0.2; graphdriver: devicemapper" 254 May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="+job acceptconnections()" 255 May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="-job acceptconnections() = OK (0)" 256 257 _Note: Using and configuring journal is an advanced topic and is beyond the scope of this article._