天天看点

docker开启远程端口的坑首先指明要修改的点

为了开启docker远程端口真是难受

google了无数条,全差不多,因为有几种修改方式,所以都尝试过

这里修改点,哪里修改点,搞得回不去了

首先指明要修改的点

  1. 云服务器要开放docker的端口 可自定义端口
  2. /usr/lib/systemd/system/docker.service 文件 修改 ExecStart 处
  3. 读取 systemctl daemon-reload 重启 systemctl restart docker

查看docker状态

sudo systemctl status docker.service
           
sudo systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2020-06-23 18:50:58 CST; 38s ago
     Docs: http://docs.docker.com
  Process: 16400 ExecStart=/usr/bin/docker-current daemon --tls=false -H unix:///var/run/docker.sock -H tcp://0.0.0.0:9876 --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 $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY (code=exited, status=1/FAILURE)
 Main PID: 16400 (code=exited, status=1/FAILURE)

Jun 23 18:50:58 VM_0_11_centos systemd[1]: Starting Docker Application Container Engine...
Jun 23 18:50:58 VM_0_11_centos docker-current[16400]: Command "daemon" is deprecated, and will be removed in Docker 1.16. Please run `dockerd` directly.
Jun 23 18:50:58 VM_0_11_centos docker-current[16400]: unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the c...docker.sock])
Jun 23 18:50:58 VM_0_11_centos systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Jun 23 18:50:58 VM_0_11_centos systemd[1]: Failed to start Docker Application Container Engine.
Jun 23 18:50:58 VM_0_11_centos systemd[1]: Unit docker.service entered failed state.
Jun 23 18:50:58 VM_0_11_centos systemd[1]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
           

英语水平太差不过看到了

unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the c...docker.sock])
           

然后我就 vim /etc/docker/daemon.json 查看发现有之前的配置没有删除

删除之后就好了

/usr/lib/systemd/system/docker.service 的修改处

ExecStart=/usr/bin/docker-current daemon --tls=false -H unix:///var/run/docker.sock  -H tcp://192.168.18.183:2375  \
          --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 \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY
           

tcp 处 自行修改