I have a docker-compose file which is globally like this.
version '2'
services:
app:
image: myimage
ports:
- "80:80"
networks:
mynet:
ipv4_adress: 192.168.22.22
db:
image: postgres:9.5
ports:
- "6432:5432"
networks:
mynet:
ipv4_adress: 192.168.22.23
...
networks:
mynet:
driver: bridge
ipam:
driver: default
config:
- subnet: 192.168.22.0/24
I want to put my postgresql and application in subnetworks to avoid the ports to be exposed outside my computer/server.
From within the app container, I can't connect to 192.168.22.23, I installed net-tools to use ifconfig/netstat, and it doesn't seem the containers are able to communicate.
I assume I have this problem because I'm using subnetworks with static ipv4 adresses.
I can access both static IPs from the host (connect to postgres and access the application)
Do you have any piece of advice, the goal is to access the ports of another container to communicate with him, without removing the use of static ips (on app at least). Here, to connect to postgresql from the app container.
mynetin networks sectionnetworks:manual configuration. If you don’t setports:then the containers still won’t be reachable from off-host. Use the service block names likedbas host names to communicated between containers. Never think about the container-internal IP addresses.proxy_passrule from host if I don't use static ips to identify my containers ?ports:. On many platforms (including Docker for Mac and anything that uses Docker Toolbox) you cannot use the container-internal IP address at all. You can specifyports: [‘127.0.0.1:8080:8080’]to make something reachable from processes on the host, but not off-host.