I am trying to get angular and nginx containers in docker-compose to speak to each other on a google-compute vm instance (Debian OS), without success. Here is my docker-compose.yml:
version: '3'
services:
angular:
container_name: angular
hostname: angular
build: project-frontend
ports:
- "80:80"
#network_mode: host
nodejs:
container_name: nodejs
hostname: nodejs
build: project-backend
ports:
- "8080:8080"
# network_mode: host
I have read the docs and numerous SO posts such as this, and understand that angular should be trying to find node at http://nodejs:8080/, but I'm getting:
POST http://nodejs:8080/login/ net::ERR_NAME_NOT_RESOLVED
When I do docker networkk inspect
I see this
[
{
"Name": "project_default",
"Id": "2d1665ce09f712457e706b83f4ae1139a846f9ce26163e07ee7e5357d4b28cd3",
"Created": "2020-05-22T11:25:22.441164515Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.28.0.0/16",
"Gateway": "172.28.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"b0fceb913ef14b0b867ae01ce4852ad4a0827c06194102082c0d4b18d7b80464": {
"Name": "angular",
"EndpointID": "83fba04c3cf6f7af743cae87116730805d030040f286706029da1c7a687b199c",
"MacAddress": "02:42:ac:1c:00:03",
"IPv4Address": "172.28.0.3/16",
"IPv6Address": ""
},
"c181cd4b0e9ccdd793c4e1fc49067ef4880cda91228a10b900899470cdd1a138": {
"Name": "nodejs",
"EndpointID": "6da8ad2a83e2809f68c310d8f34e3feb2f4c19b40f701b3b00b8fb9e6f231906",
"MacAddress": "02:42:ac:1c:00:02",
"IPv4Address": "172.28.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
I'm not sure what other steps can help me to debug this. Thanks.
EDIT: Thanks to this post I tried to ping nodejs container through the angular container successfully:
$ sudo docker exec -it angular ping nodejs
PING nodejs (172.28.0.2): 56 data bytes
64 bytes from 172.28.0.2: seq=0 ttl=64 time=0.079 ms
64 bytes from 172.28.0.2: seq=1 ttl=64 time=0.105 ms
I also tried tested the port on the nodejs constainer and it seems to be there:
$ sudo docker port nodejs
8080/tcp -> 0.0.0.0:8080
EDIT: I'm starting to think this is a google compute VM question as I have it running on my local linux box without any problem...have updated the title accordingly