Set Docker_Opts in centos Set Docker_Opts in centos docker docker

Set Docker_Opts in centos


In RHEL7, instead of modifying your docker.service unit file, you can also just edit your /etc/sysconfig/docker file:

# /etc/sysconfig/docker# Modify these options if you want to change the way the docker daemon runsOPTIONS=--selinux-enabled -H unix:///var/run/docker.sock -H tcp://0.0.0.0:4243

and then restart your docker service.

To me, this is more reliable than modifying the service script.


For CentOS 7 (RHEL 7):

Find the systemd docker.service unit file. Mine is located at: /usr/lib/systemd/system/docker.service

In this file, edit the line in the [Service] section beginning with ExecStart=. Add the "-H tcp://0.0.0.0:4243" into the line. (notice there's no "=" between the -H and the IP address as in your example DOCKER_OPTS line above.)

On my system, the entire contents of docker.service then looks like:

[Unit]Description=Docker Application Container EngineDocumentation=http://docs.docker.comAfter=network.target docker.socketRequires=docker.socket[Service]Type=notifyEnvironmentFile=-/etc/sysconfig/dockerExecStart=/usr/bin/docker -d -H tcp://127.0.0.1:4243 -H fd:// $OPTIONSLimitNOFILE=1048576LimitNPROC=1048576[Install]Also=docker.socket

(I only need Docker to listen on the loopback, instead of all IP addresses.)

After making this edit to the systemd unit file and restarting the Docker service via systemctl restart docker, I see the following process:

root 8574 0.0 0.2 321708 10564 ? Ssl 00:42 0:00 /usr/bin/docker -d -H tcp://127.0.0.1:4243 -H fd:// --selinux-enabled

As you can see, it does now listen on the configured TCP address, and will persist over reboots and service stop/starts.


I cannot believe how many answers there are for this. So here is another one for:

  • CentOS 7.3
  • Docker Version = 17.03.1-ce, API Version = 1.27

This answer is built upon an unbelievable playing around combination of this answer and this one and this one.

  1. sudo vim /usr/lib/systemd/system/docker.service
  2. insert " -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock"enter image description here
  3. sudo systemctl daemon-reload //refresh your file changes above
  4. sudo systemctl restart docker
  5. netstat -l | grep 4243 //verify port is open
  6. connect to your docker host from somewhere, like Jenkins Docker Plugin, i.e. tcp://[server_ip]:4243