I am trying to link my containerized VueJS frontend with my containerized Spring Boot API backend, with great difficulty.
Whenever I try to make an HTTP request to my API using the container name, I get the following.
OPTIONS http://api:4505/user/sign-in net::ERR_NAME_NOT_RESOLVED
Here is my docker-compose file:
version: "3"
services:
mongodb:
image: mongo
container_name: mongo
ports:
- "27017:27017"
api:
image: registry.gitlab.com/darragh.oflah/api:latest
container_name: api
ports:
- "4505:4505"
links:
- mongodb
web:
image: registry.gitlab.com/darragh.oflah/web:latest
container_name: web
ports:
- "80:8080"
links:
- api
Here what I get when I run sudo docker network inspect tmp_default
So it would seem that the network is set up correctly
[
{
"Name": "tmp_default",
"Id": "75ab7c89cb5a80aa7eddd7c5a3f7f4aafb911cfe96a923ad3db2219552366fd7",
"Created": "2020-02-04T16:55:49.131485109Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"6ae3db08be2ed22245a173a677ae1b0f28eca878aa84e43744a320589cbda5af": {
"Name": "mongo",
"EndpointID": "b399bb72f28b6d47a93927712a665dcc725d27a6ba2ee432e715db00c9cbc835",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
},
"fa7e4066e436181ce2991e048790f8de518af31fb97cf9351316ff8f41824449": {
"Name": "api",
"EndpointID": "bf8d071683bfa4ecbd215f3dd534d0e278702ed4377552ef242e5c65b01c3fa1",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
},
"fb544ef5389afd74d53f45d6de968008632b65340f161527a9c7aa4214aa7674": {
"Name": "web",
"EndpointID": "2dc3e8a452c241916a2e9f7e25b33ee7997fe2d25ec3543e5d34e888e50d905c",
"MacAddress": "02:42:ac:12:00:04",
"IPv4Address": "172.18.0.4/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "default",
"com.docker.compose.project": "tmp",
"com.docker.compose.version": "1.21.2"
}
}
]
In the net work tab, the request is saying failed, which would indicate to me that the request is failing to leave the container at all.
Your compose file creates a docker network. You're running "web" in a container on that network. All containers in the docker network can access other containers via the hostname. However, the browser is running on your host machine. Your host machine is not in the docker network. Therefore your browser won't be able to access the api container via the hostname. If you type http://api:4505/user/sign-in into the browser url bar, it's doing the same thing, and you'll also get an error.
Related
I alway lookup the services each other by docker name in my system, things like : "curl http://contianer_name". Initially, All things is fine and It has worked for several months, But it is broken yesterday, Nginx could not bypass the url like http://contianer_name, And I could not curl successfully for the http://container_name in my host machine. What it is happen? :(,,,
docker network ls:
NETWORK ID NAME DRIVER SCOPE
ecbfafa9fccf bridge bridge local
b1aac67cfbfa myapp-api_default bridge local
5195101110d3 host host local
d90ca5db218d none null local
docker network inspect
[
{
"Name": "myapp-api_default",
"Id": "b1aac67cfbfa2923d5ae88a26e8729159f34e1ae083944e385a23047a7fc7237",
"Created": "2022-09-28T18:21:57.202490009+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.22.0.0/16",
"Gateway": "172.22.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"850c8c091467b7c92aedff5631869ab2f5603ae48ee4a1efb7f18f2f890154ff": {
"Name": "app-boot-system-sample",
"EndpointID": "1497a7ac8726646f24bf82400d69c56bbcacb689d4423ab54db15af586373179",
"MacAddress": "02:42:ac:16:00:05",
"IPv4Address": "172.22.0.5/16",
"IPv6Address": ""
},
"c819074103a5b108d21b836afd1c156036e13f523b44eb5002e13edf48d9f825": {
"Name": "sample-tenant-pc",
"EndpointID": "d4ef531762a117132cbd40dee729cdf2458061e2444d35fc7968411676329e7b",
"MacAddress": "02:42:ac:16:00:04",
"IPv4Address": "172.22.0.4/16",
"IPv6Address": ""
},
"d04e0c550c95da196844c160ca9b9f80f99e3536f92da55d6e9f18533a381802": {
"Name": "sample-event-pc",
"EndpointID": "71bb31e965df8f47cfcc32685594803496bf77ad396854b5dc57851467f99996",
"MacAddress": "02:42:ac:16:00:07",
"IPv4Address": "172.22.0.7/16",
"IPv6Address": ""
},
"ee6589ced2f5080b9f3641104262f430da8f37e1278f094f78a45e2414a607f4": {
"Name": "app-boot-redis-sample",
"EndpointID": "be41952c5709d7a843b9b2ce3276bd7ac8e951ab653ba478d3a8f7cf7fe9599a",
"MacAddress": "02:42:ac:16:00:03",
"IPv4Address": "172.22.0.3/16",
"IPv6Address": ""
},
"fd9196fc0fee67de364d6be37581e4fd9827b2983a332995269af78817828bbd": {
"Name": "sample-org-pc",
"EndpointID": "a0fd805ee5705533f58b7f0e3f1cbdb0a20abc1a01057bd23a2a5161d0c5181c",
"MacAddress": "02:42:ac:16:00:02",
"IPv4Address": "172.22.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "myapp-api_default",
"com.docker.compose.project": "myapp-api",
"com.docker.compose.version": "1.26.2"
}
}
]
Docker compose defined as below in the project sample-tenant-pc:
version: '2.4'
services:
sample-tenant-pc:
build:
context: .
restart: always
container_name: sample-tenant-pc
image: sample-tenant-pc
ports:
- 9001:80
networks:
- myapp-api_default
networks:
myapp-api_default:
external: false
name: myapp-api_default
I have 2 containers that need to talk to each other. the first container simulates sendmail daemon to mock out sending email. The second is localstack mocking out sending an email alert due do a cloud watch alarm. Apparently I am the only person in the whole world having this problem. The localstack people are at a complete loss on why I cannot have their pro-examples talk to SMTP4DEV.
OS = latest Mac OS Monterey 12.6
container 1 (smtp4dev to simulate sending email):
docker run --rm -it -p 3000:80 -p 2525:25 rnwood/smtp4dev
I have a python program that creates a mail message and when it sends. a mail message shows up in the smtp4dev container.
container 2:
export SMTP_HOST=host.docker.internal:2525
DEBUG=1 DNS_ADDRESS=127.0.0.1 LOCALSTACK_API_KEY=####### SMTP_HOST=host.docker.internal:2525 localstack start
when I run the code at https://github.com/localstack/localstack-pro-samples/tree/master/cloudwatch-metrics-aws. The log in the container is showing the it is trying to send a message to the SMTP4DEV container but fails.
both containers are in the bridge network. I would think that being in the same network they should be able to talk to each other
docker network inspect bridge
[
{
"Name": "bridge",
"Id": "150e446de01292139f0ff57b46cfbc1ab5b091ab589911cb88f3ee3abda983be",
"Created": "2022-10-11T18:37:05.724386042Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"5be878e9738953a0e7047da51bc855c80c939d6c21bc5fbbedf61d4e2ddfb6e2": {
"Name": "localstack_main",
"EndpointID": "455353f471e1c9f80fcba66216c5c5face8a07bab9b6b66f9da39fecc221d5b4",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": ""
},
"f16d5edf8b42286ac3484e307761c0bd63a49532f5f019321587c8a9588eb942": {
"Name": "goofy_haibt",
"EndpointID": "8ee0ab91dc3a3c308063b0da8e806c4b0a26a8297e6cc4549ba6dfd12d51a1fa",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
I have a workaround. the option LAMBDA_DOCKER_NETWORK can be used to set the network from localstack.
DEBUG=1 DNS_ADDRESS=127.0.0.1 LOCALSTACK_API_KEY=dddddd SMTP_HOST=host.docker.internal:2525 LAMBDA_DOCKER_NETWORK=host localstack start
the real solution would be to use the "DOCKER_FLAGS" environment variable will the value of "--add-host=host.docker.internal:host-gateway". I am have asked LocalStack how I should tell use the host.docker.internal?
I have 2 docker containers running on my windows 10 machine. I have been able to interact with them by binding container ports to host ports, but now I want to dockerize another application that I have been using to interact with these containers. Up until now I have been configuring the urls using localhost, but after moving the third application to a container that will no longer be an option, so I did some research and decided to use the default bridge network. I checked that all 3 containers were in the network:
[
{
"Name": "bridge",
"Id": "c570148be95b87b5bc768de573e85c25fa4584df2c5df5c63b2d317decabe651",
"Created": "2021-03-22T07:49:32.2206325Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"38beb0863d86dab0f014ef9f1ad85f02efa7fb96520455df6f6ea6b5519f60cc": {
"Name": "my_redis",
"EndpointID": "58a6cfab6f233ac39c9b043c660124fd9cb98970f99f154ad8b3774a3356e71b",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": ""
},
"70fe60faa0dc3b853edcf2005e16d6219015eafa1c65d48aebd57256ff329f2b": {
"Name": "rabbitmq",
"EndpointID": "ed4ac901659785eebfd58de4056efd51addd19eda8c184a38632f1486c178e53",
"MacAddress": "02:42:ac:11:00:04",
"IPv4Address": "172.17.0.4/16",
"IPv6Address": ""
},
"b34359519bbf0253af3eba8e800a1bcabeb3cfe6e5cc5007679c6f632f1d4820": {
"Name": "app",
"EndpointID": "3363141459cc7eebeca1651b047ed3af81c4af37c3706dfa74e5eadb6f95f302",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
From what I can see, icc is enabled and all 3 containers are on the network. I used the IPv4Address in the configuration in app: STA_REDIS_HOST = 172.17.0.3 (with and without the /16 at the end, because I'm not sure what it means), and it seems as if the ip is being resolved to something else, because I get the following error:
Error 111 connecting to 127.0.0.1:6379. Connection refused.
I don't know where 127.0.0.1 but it looks like the private ip of the host machine.
Where am I going wrong here?
I didn't get how you are trying to connecting one container to other...
docker_bridge_network demonstrates pinging one container to others by using bridge network
My docker container is not reachable on all host network interfaces.
My host server has 2 network interfaces (and ip adresses). When running my docker container without a specific defined docker network, it works and the container is reachable on both ip adresses.
But when I'm running with a self defined docker network and add it to the docker-compose file only 1 ip is working. The other timesout. Why does this happen?
Docker-compose file
version: '3.7
services:
servicename-1:
#network_mode: "host"
image: nginxdemos/hello
init: true
ports:
- 8081:80
volumes:
omitted
environment:
ommitted
networks:
- a-netwerk-1
networks:
a-netwerk-1:
external:
name: a-network-1
docker inspect network:
[
{
"Name": "a-network-1",
"Id": "df4ab5e3285c75b71f8f88f66c4c5d85ad8f2f9b17e66f960b11778007810b96",
"Created": "2020-01-30T10:55:14.853289976+01:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.29.0.0/16",
"Gateway": "172.29.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"2f2d5b2e22b3066085246ea53d1ca2c9f963b5e9138ae7202d8382be98428476": {
"Name": "test_testservicename_1",
"EndpointID": "c750b0d9d6ae82fec109da15d385b936f79f09bf814dd3b8d03642a2f03d46e2",
"MacAddress": "02:42:ac:1d:00:02",
"IPv4Address": "172.29.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
I've two docker containers apiserver and loginserver. Both of them are provide REST API and are built using spring boot. I've created a bridge network called my-network and both the containers are attached to the same bridge.
I pinged loginserver from apiserver via interactive shell and it is accessible. I make REST request from the host machine so I know the socket exposed. But, when I make the same REST request from apiserver to loginserver, I am getting error:
: HttpQueryService::uri=http://172.28.0.7:8090/users/login
2018-06-19 19:08:24.196 ERROR 7 --- [nio-9000-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
org.apache.http.conn.HttpHostConnectException: Connect to 172.28.0.7:8090 [/172.28.0.7] failed: Connection refused (Connection refused)
Here are the details from my-network:
docker network inspect my-network
[
{
"Name": "my-network",
"Id": "ef610688b58b6757cba57caf6261f7a1eaeb083798098214c4848cbb152cae26",
"Created": "2018-04-21T00:19:46.918124848Z",
"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": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"71863d2f61789d4350fcabb1330b757500d5734a85c68b60eb1ac8f6f1e8344e": {
"Name": "mymongo",
"EndpointID": "717c8dbdc8993a70f9d3e97e549cb9784020b8e68e7a557c30b0818b4c9acb90",
"MacAddress": "02:42:ac:1c:00:02",
"IPv4Address": "172.28.0.2/16",
"IPv6Address": ""
},
"936447ce8325f3a7273a7fb462d75e55841a9ff37ccf27647831b3db1b8a1371": {
"Name": "mypg",
"EndpointID": "6a1a1b2f7852b89a9d2cb9b9abecdabd134849cd789c31613c7ddb91a4bc43d1",
"MacAddress": "02:42:ac:1c:00:06",
"IPv4Address": "172.28.0.6/16",
"IPv6Address": ""
},
"ad03348dffaef3edd916d349c88e8adf6cf7d88dbc40f82dc2384dee826cfa83": {
"Name": "myloginserver",
"EndpointID": "fe22c2b5f57b7fe4776087972ffa5f7f089ca6a59fde2fa677848b3f238ea026",
"MacAddress": "02:42:ac:1c:00:07",
"IPv4Address": "172.28.0.7/16",
"IPv6Address": ""
},
"c69bfbf9ccdc9e29e87d2847b5c2a51e9c232fb8d06635bcef0cdd1f7c66e051": {
"Name": "apiserver",
"EndpointID": "46e94a52d34670eb00448b1d39a0cc365b882ece790c9d868dcee04ad141d1ca",
"MacAddress": "02:42:ac:1c:00:0b",
"IPv4Address": "172.28.0.11/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
Is port 8090 exposed by your loginserver image? For checking type in command
docker images
and then find the ImageID of your loginserver image. Then enter command
docker inspect image {Login server image id}
In the output check ExposedPorts if 8090 is exposed or not
Late to the party but I just fixed this on my system by setting the address to get the REST request from as the public IP address:
eg: http://217.114.203.196/myrequest