両方が同じネットワーク上で動作する場合に可能です。だから、最高のは、私まで、この組成とnginx1
コンテナに行くが
docker-compose exec nginx1 bash
を使用して、以下を実行するとdocker-compose
ファイル
version: '3'
services:
nginx1:
image: nginx
ports:
- "8082:80"
nginx2:
image: nginx
ports:
- "8081:80"
networks:
default:
aliases:
- dotcomtest.net
でそれらの両方を置くことであるあなたのよう
[email protected]:/# apt update && apt install -y curl
[email protected]:/# curl http://dotcomtest.net
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
コマンド私のnginx1コンテナがnginx2へのアクセスを見ることができます
あなたはcontaiあなたのホストマシンにあるdotcomtest.netに連絡するのは?どのOSを使用していますか? –
はい(私はそうだと思いますが)、私は2つのコンテナが自分のネットワーク上にあると思っていましたので、2つのコンテナ間の通信のケースだと思いました。 MacOS – Richlewis