在contanier访问docker守护进程远程api

时间:2017-11-02 06:05:17

标签: docker centos7

我在centos7使用正式版的docker-ce,在容器中启动一个docker守护进程:

[root@5cae7be526b4 /]# rpm -qa docker-ce
docker-ce-17.09.0.ce-1.el7.centos.x86_64

这是我的守护进程配置

{
"hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:5555"],
"live-restore": true,
"insecure-registries": ["172.17.0.6:9980"]
}

在不更改配置的情况下,docker守护程序可以在容器中启动和重启:

[root@5cae7be526b4 /]# docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 17.09.0-ce
Storage Driver: vfs
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 3.10.0-514.el7.x86_64
Operating System: CentOS Linux 7 (Core) (containerized)
OSType: linux
Architecture: x86_64
CPUs: 16
Total Memory: 31.26GiB
Name: 5cae7be526b4
ID: N3Y4:VTIJ:WCHK:AQL3:MU3F:DNHE:BIXO:7ISI:4D4V:Q4IG:VYIT:FOH3
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

但是更改配置,它失败了:

[root@5cae7be526b4 /]# systemctl restart docker 
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
[root@5cae7be526b4 /]# systemctl status docker -l
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Thu 2017-11-02 05:51:02 UTC; 2s ago
     Docs: https://docs.docker.com
  Process: 260 ExecStart=/usr/bin/dockerd (code=exited, status=1/FAILURE)
 Main PID: 260 (code=exited, status=1/FAILURE)

Nov 02 05:51:02 5cae7be526b4 systemd[1]: Failed to start Docker Application Container Engine.
Nov 02 05:51:02 5cae7be526b4 systemd[1]: Unit docker.service entered failed state.
Nov 02 05:51:02 5cae7be526b4 systemd[1]: docker.service failed.
Nov 02 05:51:02 5cae7be526b4 systemd[1]: docker.service holdoff time over, scheduling restart.
Nov 02 05:51:02 5cae7be526b4 systemd[1]: start request repeated too quickly for docker.service
Nov 02 05:51:02 5cae7be526b4 systemd[1]: Failed to start Docker Application Container Engine.
Nov 02 05:51:02 5cae7be526b4 systemd[1]: Unit docker.service entered failed state.
Nov 02 05:51:02 5cae7be526b4 systemd[1]: docker.service failed.

当然,这个守护进程配置可以在主机上运行。

我已启动容器--privileged-v /sys/fs/cgroup:/sys/fs/cgroup以启用容器中的systemctl

根本原因是"hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:5555"],我不知道如何修复它,但我确实需要设置主机。

我想将此容器设为repo并启动其他容器来执行此docker守护程序中的pull之类的docker操作。

我该如何启用它?

1 个答案:

答案 0 :(得分:0)

我在这里分享我的解决方案,请告诉我错误或有更好的方法。

首先,检查docker版本,只有新的正式版可以在容器中运行。对于centos,它表示docker-ce,请参阅https://docs.docker.com/engine/installation/linux/docker-ce/centos/

其次,检查启动容器时主机端口是否未设置为-p。 docker守护程序可以监听它并使用-p指定会产生冲突。

第三,在容器中启动docker守护进程应该为存储分配一个卷。如果不是,则存储选项只能是vfs