I have a Mongo database running through Docker but I am unable to connect to it using Intellij.
(I am getting a timeout).
Can you help me? 😃
Error: "java.net.ConnectException: Connection refused: no further information"
Thx 😉
My docker-compose.yml:
version: '3.1'
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: PanDiMooN
MONGO_INITDB_ROOT_PASSWORD: PanDiMooN
MONGO_INITDB_DATABASE: The_Milky_Way
I tried to restart the container, change ports but I am still getting the timeout.
IntelliJ is trying to connect to localhost on port 27017. localhost is how your computer refers to itself in networks. The problem is that your computer isn't listening for requests on this port, a Docker container on your computer is.
To bind requests to port 27017 with your Docker container, you can add a ports section to the compose file:
version: '3.1'
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: PanDiMooN
MONGO_INITDB_ROOT_PASSWORD: PanDiMooN
MONGO_INITDB_DATABASE: The_Milky_Way
ports:
- "27017:27017"
Related
I'm trying to connect to a mongodb container inside docker but I'm getting this error:
getaddrinfo ENOTFOUND mongo.ks.local
The database works just fine when I access it from docker but I'm not able to access it from MongoDBCompass
This is my docker-compose.yml file:
version: '3.8'
services:
mongo:
image: mongo
container_name: mongo.ks.local
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: <username>
MONGO_INITDB_ROOT_PASSWORD: <password>
ports:
- 27017:27017
volumes:
- ks_mongodb:/data/db
I'm quite new to docker and will appreciate any help I can get
You need the ip address of the container:
try:
docker inspect <CONTAINER NAME>
And search for the ip address. Then use the ip address to connect to mongodb
I have tried connecting to the container using mongo compass. It failed but when I removed the line of mounting the volume and tried again it connects to the database.
Then tried to mount the volume like below it worked. I have changed the username and password and specified the INITDB env variable.
version: "3.8"
services:
mongo:
image: mongo:latest
container_name: mongo.ks.local
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: 1234
MONGO_INITDB_DATABASE: admin
ports:
- 27017:27017
volumes:
- /data/db
My Postgres DB is running in a Docker container. When container is started, it says it's ready to listen on 5432.
My application container is set to depend on it.
container_name: my_postgres_db
image: library/postgres:latest
network_mode: bridge
expose:
- 5432
ports:
- 5432:5432
environment:
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=admin
- POSTGRES_DB=localdb
restart: always
The config for app:
container_name: my_test_app
depends_on:
- db
build:
context: ./
dockerfile: Dockerfile
image: my_test_app
ports:
- 8080:8080
Based on solutions to the similar questions, I changed the localhost in the DB URL to:
spring.datasource.url=jdbc:postgresql://db:5432/localdb
It causes another error = "Unknown host exception". Even if I manage to build app this way, it still doesn't work. Logs say,
Connection to localhost:5432 refused
What else am I missing?
Why is it still listening to localhost:5432 when I obviously changed it to db:5432 and gradlew clean/build it?
just change the network_mode in postgres and app to host
network_mode: host
note that this will ignore the expose option and will use the host network an containers network
I have the following docker compose file that I use to spin up a mongo docker container which works as intended.
However, I cannot seem to connect to the container from compass on my local machine.
I executed docker inspect on my mongo container and got its IP and tried to connect using compass, but it didn't work - connection timed out.
Is it the IP of my docker network or the IP of the mongo container I need?
docker compose file:
version: "3"
services:
pokerStats:
image: pokerStats
container_name: pokerStats
ports:
- 8080:8080
depends_on:
- db
db:
image: mongo
container_name: mongo
volumes:
- ./database:/data
ports:
- "27017:27017"
I was able to get this working using the top answer on this question.
I had to change my docker-compose file to expose port 27018 on my local:
db:
image: mongo
container_name: mongo
volumes:
- ./database:/data
ports:
- "27018:27017"
And my connection details on Compass to be:
You are mapping port 27017 from your host machine to port 27017 on the container. So the following connection string should work mongodb://localhost:27017
I have a mongodb running as a docker container which created by docker-compose.
Here is my docker-compose.yml:
verion:'3.7'
services:
mongo_env:
image: mongo:4.2.1-bionic
ports:
- "27017:27017"
volumes:
- $PWD/DBVOL/mongo/data:/data/db:rw
environment:
MONGO_INITDB_ROOT_USERNAME: <rootuser>
MONGO_INITDB_ROOT_PASSWORD: <mypassword>
MONGO_INITDB_DATABASE: <mydatabase>
I want to connect mongodb from outside using Robo 3T,But It always tell me that 'Failed to load database'.Here is my Robo 3T config:
Please Help me It's emergency!
Are your sure it started successfull? Your Docker Compose has a typo in "version:3.7".
correct version:
version: '3.7'
services:
mongo_env:
image: mongo:4.2.1-bionic
ports:
- "27017:27017"
volumes:
- $PWD/DBVOL/mongo/data:/data/db:rw
environment:
MONGO_INITDB_ROOT_USERNAME: <rootuser>
MONGO_INITDB_ROOT_PASSWORD: <mypassword>
MONGO_INITDB_DATABASE: <mydatabase>
Please check after starting if the container is running with
docker ps
I'm trying to configure my docker to pgadmin4 in my nest js project, to do the backend, but when i try connect, show this message "Unable to connect to server:
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting"
I already tried configure the docker-compose.yml with pgadmin configurations, network configurations and
my docker-compose.yml
version: '3'
services:
db:
image: postgres
environment:
POSTGRES_PASSWORD: "12345678"
ports:
- "5432:5432"
volumes:
- ./data/pgadmin/
networks:
- pg-network
pgadmin:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: "monnerat#monnerat.com.br"
PGADMIN_DEFAULT_PASSWORD: "abc"
ports:
- "5050:80"
depends_on:
- db
networks:
- pg-network
networks:
pg-network:
driver: bridge
My actual result is connection refused is server running on host "localhost (127.0.0.1) and accepting"
but i expect he open the pgadmin to create the database
Your docker-compose.yml is good. Please see the attached host name should be 'db'