Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Docker remote connection settings

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to achieve Docker remote connection settings", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to achieve Docker remote connection settings" this article.

When Docker remote connection is enabled, it will bring convenience in development and learning. However, do not use this method in the external network environment to avoid security problems. The following is an official warning:

Environmental information

This actual combat is first set on Docker on CentOS, and then on Ubuntu. First, the CentOS environment information of actual combat is as follows:

Operating system: CentOS Linux release 7.6.1810

Docker:1.13.1, build b2f74b2/1.13.1

Set up

1. Edit this file: / lib/systemd/system/docker.service

Original settings:

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\-init-path=/usr/libexec/docker/docker-init-current\-seccomp- Profile=/etc/docker/seccomp.json\ $OPTIONS\ $DOCKER_STORAGE_OPTIONS\ $DOCKER_NETWORK_OPTIONS\ $ADD_REGISTRY\ $BLOCK_REGISTRY\ $INSECURE_REGISTRY\ $REGISTRIES

Change ExecStart=/usr/bin/dockerd-current\ to ExecStart=/usr/bin/dockerd-current-H tcp://0.0.0.0:2375-H unix://var/run/docker.sock\, as follows:

ExecStart=/usr/bin/dockerd-current-H tcp://0.0.0.0:2375-H unix://var/run/docker.sock\-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\ -- init-path=/usr/libexec/docker/docker-init-current\-- seccomp-profile=/etc/docker/seccomp.json\ $OPTIONS\ $DOCKER_STORAGE_OPTIONS\ $DOCKER_NETWORK_OPTIONS\ $ADD_REGISTRY\ $BLOCK_REGISTRY\ $INSECURE_REGISTRY\ $REGISTRIES

Save and exit after modification

two。 Reload and restart docker:

Systemctl daemon-reload & & systemctl restart docker

Now that the settings are complete, verify that the settings are in effect.

3. First, try whether the docke service is normal on this machine. As follows, everything is normal for local access:

[root@maven ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEbolingcavalry/nacosconfigdemo 1.0-SNAPSHOT ed524b78f80b 5 days ago 125 MBbolingcavalry/nacosserver 0.0.1 9ab34ff860d8 3 weeks ago 156 MBdocker.io / openjdk 8u212-jdk-stretch 03b20c1fa768 6 weeks ago 488 MBdocker.io/openjdk 8u201-jdk-alpine3.9 3675b9f543c5 4 months ago 105 MBdocker.io/fabric8/java-jboss-openjdk8-jdk 1.3 c9d7e2e7b917 20 months ago 436 MB

4. The native IP address is 192.168.121.131, now try to test remote access to the native machine from another machine with docker installed, the command is docker-H tcp://192.168.121.131:2375 images, as shown below, everything is fine:

[root@centos7] # docker-H tcp://192.168.121.131:2375 imagesREPOSITORY TAG IMAGE ID CREATED SIZEbolingcavalry/nacosconfigdemo 1.0-SNAPSHOT ed524b78f80b 5 days ago 125 MBbolingcavalry/nacosserver 0.0.1 9ab34ff860d8 3 weeks ago 156 MBdocker.io/openjdk 8u212-jdk-stretch 03b20c1fa768 6 weeks ago 488 MBdocker.io/openjdk 8u201-jdk-alpine3.9 3675b9f543c5 4 months ago 105 MBdocker.io/fabric8/java-jboss-openjdk8-jdk 1.3 c9d7e2e7b917 20 months ago 436 MB

5. If you find it troublesome to enter-H tcp://192.168.121.131:2375 every time you use a remote command, you can also store the IP information of the remote docker into the environment variable DOCKER_HOST= "tcp://192.168.121.131:2375". In this way, executing the docker command will connect remotely without the IP address parameter:

[root@centos7 ~] # export DOCKER_HOST= "tcp://192.168.121.131:2375" [root@centos7 ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEbolingcavalry/nacosconfigdemo 1.0-SNAPSHOT ed524b78f80b 5 days ago 125 MBbolingcavalry/nacosserver 0. 0.1 9ab34ff860d8 3 weeks ago 156 MBdocker.io/openjdk 8u212-jdk-stretch 03b20c1fa768 6 weeks ago 488 MBdocker.io/openjdk 8u201-jdk-alpine3.9 3675b9f543c5 4 months ago 105 MBdocker.io/fabric8/java-jboss-openjdk8-jdk 1.3 Settings on c9d7e2e7b917 20 months ago 436 MBUbuntu

The settings on Ubuntu are slightly different from those of CentOS, which are also explained here:

Environment:

Operating system: Ubuntu 18.04.2 LTS

Docker:19.03.1 (Community)

Steps:

Check if the folder / etc/systemd/system/docker.service.d/ exists, and if not, create it

Create a new file override.conf under the folder / etc/systemd/system/docker.service.d/, as follows:

[Service] ExecStart=ExecStart=/usr/bin/dockerd-H tcp://0.0.0.0:2375-H unix://var/run/docker.sockExecReload=/bin/kill-s HUP $MAINPIDTimeoutSec=0RestartSec=2Restart=alway

Reload the configuration and restart the docker service:

Systemctl daemon-reload & & systemctl restart docker.service

Now that the Docker on Ubuntu has successfully started the remote service, it can be verified as in the previous step.

At this point, the setup and verification of the Docker remote connection is complete. Emphasize again: this setting method is only for development and learning. Do not set it like this on the public network, lest this Docker is remotely connected by other unknown clients, causing security problems.

The above is all the contents of the article "how to implement Docker remote connection Settings". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report