Set Docker_Opts in centos

后端 未结 12 1675
我在风中等你
我在风中等你 2021-01-31 04:44

I need to set docker to listen to tcp://0.0.0.0/4243 on my host machine running amazon linux (centos). All the documentation I have seen has told me to run the following command

相关标签:
12条回答
  • 2021-01-31 05:29

    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 Engine
    Documentation=http://docs.docker.com
    After=network.target docker.socket
    Requires=docker.socket
    
    [Service]
    Type=notify
    EnvironmentFile=-/etc/sysconfig/docker
    ExecStart=/usr/bin/docker -d -H tcp://127.0.0.1:4243 -H fd:// $OPTIONS
    LimitNOFILE=1048576
    LimitNPROC=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.

    0 讨论(0)
  • 2021-01-31 05:33

    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 runs
    OPTIONS=--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.

    0 讨论(0)
  • 2021-01-31 05:35

    Editing /etc/docker/daemon.json seems to be the new, supported way.

    0 讨论(0)
  • 2021-01-31 05:37

    I needed to change the default bridge interface docker0 to use my own bridge interface br0 and putting the following content in that file solved my issue:

    CentOS 7.2 and docker 1.10.3

    /usr/lib/systemd/system/docker.service.d/docker.conf

    [Service] 
    ExecStart=
    ExecStart=/usr/bin/docker daemon --bridge=br0 -H fd://
    

    and of course the following need to be performed after:

    sudo systemctl daemon-reload
    
    sudo systemctl restart docker 
    
    ip link del docker0
    
    0 讨论(0)
  • 2021-01-31 05:44

    With Docker 1.7.1 on CentOS 7 neither modifying /usr/lib/systemd/system/docker.service or /etc/sysconfig/docker worked for me. It seems that in systemd sets up the socket, so in order to change the group you have to edit SocketGroup in /usr/lib/systemd/system/docker.socket

    [Unit]
    Description=Docker Socket for the API
    PartOf=docker.service
    
    [Socket]
    ListenStream=/var/run/docker.sock
    SocketMode=0660
    SocketUser=root
    SocketGroup=jenkins
    
    [Install]
    WantedBy=sockets.target
    
    0 讨论(0)
  • 2021-01-31 05:44

    I believe things have changed now, this answer by Brian Ogden had worked for me earlier but didn't work on my environment today, probably with the updated versions of the docker, kernel, and OS.

    CentOS 7.4.1708 (on AWS)
    Docker 17.03.2-ce
    API 1.27
    

    This is what worked after few hit and trials. I could not find it documented anywhere.

    In file /etc/systemd/system/docker.service.d/execstart.conf, replace the last ExecStart (there are two) with below

    ExecStart=/usr/bin/dockerd --graph=/var/lib/docker --storage-driver=overlay -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
    

    Now, my files looks like this

    # cat /etc/systemd/system/docker.service.d/execstart.conf
    [Service]
    Restart=always
    StartLimitInterval=0
    RestartSec=15
    ExecStartPre=-/sbin/ip link del docker0
    ExecStart=
    ExecStart=/usr/bin/dockerd --graph=/var/lib/docker --storage-driver=overlay -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
    #
    

    Once, the above file is changed just the run the below command to activate the changes.

    # systemctl daemon-reload && systemctl stop docker && rm -f /var/run/docker.sock && systemctl start docker
    

    To verify if everything is working fine, you can run any (or all) of below commands

    # systemctl status docker.service | grep tcp
               ├─21812 /usr/bin/dockerd --graph=/var/lib/docker --storage-driver=overlay -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
    #
    # netstat -an | grep 4243
    tcp6       0      0 :::4243                 :::*                    LISTEN
    #
    # ps aux | grep [4]243
    root     21812  1.0  0.8 1017512 67876 ?       Ssl  15:11   0:06 /usr/bin/dockerd --graph=/var/lib/docker --storage-driver=overlay -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
    #
    # docker -H :4243 info
    
    0 讨论(0)
提交回复
热议问题