Have docker tomcat application on first docker container. And can't connect to mongo in another container. Pls Help!
Tomcat application dataSource:
spring:
data:
mongodb:
host: mongo1
port: 27017
database: open-data
Docker-compose file:
version: '3.3'
services:
mongo:
image: mongo
container_name: mongo1
environment:
MONGO_INITDB_DATABASE: open-data
ports:
- 27017:27017
In docker documentation I can't see that container_name
is used to define host name of service in the docker-compose network.
You must use mongo
instead of mongo1
as it's the name of your service.
spring:
data:
mongodb:
host: mongo
port: 27017
database: open-data
All you need about networking is here :
https://docs.docker.com/compose/networking/
version: '3.3'
services:
mongo: # <= this is used to define host name
If you did provide your entire docker compose file, you must add tomcat container definition in the same docker-compose with mongo for them to be in the same network.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.