开启Docker管理端口

针对yum命令安装的Docker,修改方式如下

vi /etc/sysconfig/docker

在OPTIONS参数的后面加入

-H unix:///var/run/docker.sock -H 0.0.0.0:2375

修改之后的文件内容:

# /etc/sysconfig/docker
# Modify these options if you want to change the way the docker daemon runs 

OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false -H unix:///var/run/docker.sock -H 0.0.0.0:2375'

if [ -z "${DOCKER_CERT_PATH}" ]; then
    DOCKER_CERT_PATH=/etc/docker
fi 
# Do not add registries in this file anymore. Use /etc/containers/registries.conf 

# instead. For more information reference the registries.conf(5) man page. 
# Location used for temporary files, such as those created by 
# docker load and build operations. Default is /var/lib/docker/tmp 
# Can be overriden by setting the following environment variable. 
# DOCKER_TMPDIR=/var/tmp 
# Controls the /etc/cron.daily/docker-logrotate cron job status. 
# To disable, uncomment the line below. 
# LOGROTATE=false 
# docker-latest daemon can be used by starting the docker-latest unitfile. 
# To use docker-latest client, uncomment below lines 
#DOCKERBINARY=/usr/bin/docker-latest
#DOCKERDBINARY=/usr/bin/dockerd-latest 
#DOCKER_CONTAINERD_BINARY=/usr/bin/docker-containerd-latest 
#DOCKER_CONTAINERD_SHIM_BINARY=/usr/bin/docker-containerd-shim-latest

对于官方方式安装的,操作如下:

vi /usr/lib/systemd/system/docker.service

修改ExecStart参数,增加

-H unix:///var/run/docker.sock -H 0.0.0.0:2375

修改之后的文件内容

[Unit]
Description=Docker Application Container Engine 
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target
firewalld.service 
Wants=network-online.target 
Requires=docker.socket
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H 0.0.0.0:2375 -H fd:// ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 RestartSec=2 Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd. 
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd. 
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting. 
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this option. 
TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup 
KillMode=process
[Install]
WantedBy=multi-user.target

修改完之后

#重新加载配置文件
systemctl daemon-reload
#重启服务
systemctl restart docker.service
#查看端口是否开启
netstat -nptl
#直接curl看是否生效
curl http://127.0.0.1:2375/info

评论