链接和主机名称docker组成
我有一个docker-compose文件中定义了两个服务,并且正在寻找一个服务名称映射到一个主机条目,这样我就可以发送数据到一个端点在mongo数据库服务,例如在我的主机上我有
127.0.0.1 dotcomtest.net
如果我有一个称为web
服务和称为echo-chamber
的服务,如何在我的Web容器(或者docker撰写文件)中设置我的hosts文件,以便我可以向该端点发送请求,即http://dotcomtest.net/query_string?
谢谢
当他们都在同一个networking上运行时,这是可能的。 所以最好的是把它们都放在一个docker-compose
文件中
version: '3' services: nginx1: image: nginx ports: - "8082:80" nginx2: image: nginx ports: - "8081:80" networks: default: aliases: - dotcomtest.net
当我把这个组成,并使用nginx1
容器
docker-compose exec nginx1 bash
并执行下面的命令
root@cabf18b17f34:/# apt update && apt install -y curl root@cabf18b17f34:/# 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