Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

docker - Two containers with access to same local port

How can I have two or more containers write data out to localhost on the same port? Is the only way to do this run the destation service in a container as well and have the write clients write to the container's IP/service name?

Specifically, I have 3 containers that are writing data out. I want them to write a local database running on localhost:8086.

question from:https://stackoverflow.com/questions/66055857/two-containers-with-access-to-same-local-port

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Do you mean your target database to write with is running on your Host machine? and your clients that would write runs inside the container? If so, you can publish a port from your Host machine to your containers then inside your container, you can access your Host machine's port.

$ docker run --name my-database-client-1 -p 8086:8086 ...

Or, if your database also runs inside the container, it's better to use a network then reference your server-database using its container name i.e. my-database-server:8086.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...