Docker host remote access to another Docker host

Source: Internet
Author: User
Tags socket port number

This machine installs a Docker, the remote host installs a Docker, this article mainly explains how to use the local Docker client to access the remote host's Docker daemon

By default, the Docker daemon generates a socket (/var/run/docker.sock) file for local process communication without listening to any ports, so you can only use the Docker client locally or use the Docker API to do so.
If you want to operate a Docker host on another host, you need to have the Docker daemon listen to a port for remote communication.

Modify the Docker service startup configuration file, add an unused port number, and restart the Docker daemon.

# Vim/etc/default/docker
docker_opts= "-H 0.0.0.0:5555"
# service Docker restart

If you do not have this file, you should consider modifying the/etc/sysconfig/docker file.

Now that the Docker daemon is listening on port 5555, the Docker process can be accessed through that port on another host.

Example Description:

We can access another Docker-mounted machine from one of the Docker-mounted machines. In general, we use the Docker client of the current machine to access the server side of the current machine. The following shows how to access other Docker server ports.

First set of ip:192.168.12.3

Second set of ip:192.168.12.4

Demo with a second server with Docker installed. To differentiate, set the label differently.

To modify the daemon (Server) default startup configuration:

The default is:-H fd://, can be modified to:-H tcp://0.0.0.0:2375-h unix:///var/run/docker.sock-h fd://--label name=server_1

Multiple connection modes can be set.

TCP is a remote connection, UNIX is a local socket link, FD does not know.

The first Docker service to access the second machine:

Connect to server via http:

Curl Http://192.168.12.4:2375/info

Accesses the info interface of the server 192.168.12.4:2375 and returns information about the server.

Accessing the server through a Docker client:

Docker-h tcp://192.168.12.4:2375 Info

If it is the first machine to access the first machine Docker server, then use 127.0.0.1:2375.

As with the server side, the client also supports three kinds of connection methods, by default,-H Unix:///var/run/docker.sock:

-H Unix:///path/to/sock

Tcp://host:port

Fd://socketfd

The Docker client uses Docker info to access the local server by default. You can modify the environment variable Docker_host to change the default connection. command line input directly:

Export docker_host= "tcp://127.0.0.1:2375"

The 127.0.0.1:237 can be replaced with the actual server address.

If you want to restore the local connection, leave the docker_host empty:

export docker_host= "" 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.