CentOS 7 版本
[root@gitserver ~]# uname -r
3.10.0-327.el7.x86_64
[root@gitserver ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
docker 版本
[root@gitserver /]# docker --version
Docker version 1.12.6, build 3a094bd/1.12.6
修改/etc/sysconfig/docker文件,在最后增加一行DOCKER_OPTS
# 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
DOCKER_OPTS="-H unix:///var/run/docker.sock -H 0.0.0.0:5555"
修改/usr/lib/systemd/system/docker.service
在[Service]的ExexStart=下面增加一行$DOCKER_OPTS
[Service]
Type=notify
NotifyAccess=all
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \
--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
--default-runtime=docker-runc \
--exec-opt native.cgroupdriver=systemd \
--userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
$DOCKER_OPTS \
$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY
注意:也可以直接在ExecStart后面追加-H unix:///var/run/docker.sock -H 0.0.0.0:5555
,
ExecStart=/usr/bin/dockerd-current \
--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
--default-runtime=docker-runc \
--exec-opt native.cgroupdriver=systemd \
--userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
-H unix:///var/run/docker.sock -H 0.0.0.0:5555 \
$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY systemctl dameon
让配置生效:
[root@gitserver system]# systemctl daemon-reload
[root@gitserver system]# systemctl restart docker.service
用netstat查看
[root@gitserver system]# netstat -tnlp |grep 5555
tcp6 0 0 :::5555 :::* LISTEN 2025/dockerd-curren
用curl进行测试
curl 127.0.0.1:5555/info
结果如下:
Debian 8下的配置
配置文件所在的目录与centos不一样
/etc/default/docker
/lib/systemd/system/docker.service
如果不知道目录,可以用find命令查找,find / -name ‘docker.service’ -print