github.com/nf/docker@v1.8.1/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 `-d` option. 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/cli/#daemon)
    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/),
    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/cli/#daemon)
   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/)/[Red Hat Enterprise Linux]
   154  (/installation/rhel/)/[Fedora](/installation/fedora), you can check the running status in this way:
   155  
   156      $ sudo systemctl status docker
   157  
   158  ### Running Docker
   159  
   160  You can start/stop/restart the `docker` daemon using
   161  
   162      $ sudo systemctl start docker
   163  
   164      $ sudo systemctl stop docker
   165  
   166      $ sudo systemctl restart docker
   167  
   168  If you want Docker to start at boot, you should also:
   169  
   170      $ sudo systemctl enable docker
   171  
   172  ### Configuring Docker
   173  
   174  You configure the `docker` daemon in the `/etc/sysconfig/docker` file on your
   175  host. You do this by specifying values in a variable. For CentOS 7.x and RHEL 7.x, the name
   176  of the variable is `OPTIONS` and for CentOS 6.x and RHEL 6.x, the name of the variable is
   177  `other_args`. For this section, we will use CentOS 7.x as an example to configure the `docker`
   178  daemon.
   179  
   180  By default, systemd services are located either in `/etc/systemd/service`, `/lib/systemd/system`
   181  or `/usr/lib/systemd/system`. The `docker.service` file can be found in either of these three
   182  directories depending on your host.
   183  
   184  To configure Docker options:
   185  
   186  1. Log into your host as a user with `sudo` or `root` privileges.
   187  
   188  2. If you don't have one, create the `/etc/sysconfig/docker` file on your host. Depending on how
   189  you installed Docker, you may already have this file.
   190  
   191  3. Open the file with your favorite editor.
   192  
   193      ```
   194      $ sudo vi /etc/sysconfig/docker
   195      ```
   196  
   197  4. Add a `OPTIONS` variable with the following options. These options are appended to the
   198  command that starts the `docker` daemon.
   199  
   200  ```
   201      OPTIONS="-D --tls=true --tlscert=/var/docker/server.pem --tlskey=/var/docker/serverkey.pem -H tcp://192.168.59.3:2376"
   202  ```
   203  
   204  These options :
   205  
   206  - Enable `-D` (debug) mode
   207  - Set `tls` to true with the server certificate and key specified using `--tlscert` and `--tlskey` respectively
   208  - Listen for connections on `tcp://192.168.59.3:2376`
   209  
   210  The command line reference has the [complete list of daemon flags](/reference/commandline/cli/#daemon)
   211  with explanations.
   212  
   213  5. Save and close the file.
   214  
   215  6. Restart the `docker` daemon.
   216  
   217      ```
   218      $ sudo service docker restart
   219      ```
   220  
   221  7. Verify that the `docker` daemon is running as specified with the `ps` command.
   222  
   223      ```
   224      $ ps aux | grep docker | grep -v grep
   225      ```
   226  
   227  ### Logs
   228  
   229  systemd has its own logging system called the journal. The logs for the `docker` daemon can
   230  be viewed using `journalctl -u docker`
   231  
   232      $ sudo journalctl -u docker
   233      May 06 00:22:05 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
   234      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)"
   235      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)"
   236      May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="+job init_networkdriver()"
   237      May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="-job init_networkdriver() = OK (0)"
   238      May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="Loading containers: start."
   239      May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="Loading containers: done."
   240      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"
   241      May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="+job acceptconnections()"
   242      May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="-job acceptconnections() = OK (0)"
   243  
   244  _Note: Using and configuring journal is an advanced topic and is beyond the scope of this article._