I have the following docker compose:
version: '3'
services:
postgres:
container_name: test-psql
image: postgres:10.4-alpine
restart: always
ports:
- 5432:5432
volumes:
- ~/docker_data/postgres:/data/postgres
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
I start everything with docker-compose up and then docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f4cae94afaa6 postgres:10.4-alpine "docker-entrypoint.s…" 48 seconds ago Up 47 seconds 0.0.0.0:5432->5432/tcp test-psql
But when trying to connect to it with psql
psql -h localhost -U test
I get the error
psql: could not connect to server: Connection refused
Is the server running on host “localhost” (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host “localhost” (127.0.0.1) and accepting
TCP/IP connections on port 5432?
What you're trying is correct - I tested it on my end just in case and it's working as intended. I'd suggest checking your firewall configuration.
Related
I’m trying to connect to an ssh server from a docker container lifted by docker-compose.
On my localhost, I have enabled the port to use with "ufw allow 4222", I have placed port 4222 in my docker-compose.yml file.
I have also added the public key of my localhost to the container and to the authorized keys of the server, the problem is that it keeps failing me, someone knows that more I can check or take into account? thank you.
docker-compose.yml
version: '3.9'
services:
hermes:
depends_on:
- mongodb
build:
context: ./hermes-app/
container_name: hermes
tty: true
ports:
- "5000:5000"
- "4222"
environment:
- SLACK_CLIENT_ID=${SLACK_CLIENT_ID}
- SLACK_CLIENT_SECRET=${SLACK_CLIENT_SECRET}
- SLACK_SIGNING_SECRET=${SLACK_SIGNING_SECRET}
- SLACK_VERIFICATION_TOKEN=${SLACK_VERIFICATION_TOKEN}
- SSH_HOST=${SSH_HOST}
- SSH_USER=${SSH_USER}
- SSH_PORT=${SSH_PORT}
networks:
- netrmes
Error:
root#6d55aa960f46:/hermes-app# ssh root#my_server -p 4222
ssh: connect to host my_server port 4222: Connection refused
So you try to ssh from the container to your host system. The container knows nothing about my_server if it is not in netrmes network. You could use host network and then
ssh root#localhost -p 4222
I created a docker file to create a pgAdmin4 container and a postgres container.
version: '3.8'
services:
postgres:
container_name: pg_container
image: postgres
restart: always
environment:
POSTGRES_USER: webquiver
POSTGRES_PASSWORD: webquiver
POSTGRES_DB: quiver_db
ports:
- "5432:5432"
pgadmin:
container_name: pgadmin4_container
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin#admin.com
PGADMIN_DEFAULT_PASSWORD: admin
ports:
- "5050:80"
When running docker compose up I can go to the localhost:5050 to reach pgAdmin4 and login in with my credentials you can see in the code.
But when I use the dropdown menu for servers, it is empty. nothing is created. And I can not create any server there. It does not allow me to. I get the Error:
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
TCP/IP connections on port 5432?
could not connect to server: Address not available
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
please help. THX ^^
greetings
I've reproduced your docker-compose file and everything is fine with it.
I'm guessing there is a misunderstanding how postgres and pgadmin are interacting with each other from scratch.
pgadmin is only the frontend that you can connect to a postgres database, it's not automatically searching for any existing postgres server.
I'm able to add the server inside the pgadmin with this host and port: postgres:5432 As inside the docker will resolve the service name as hostname postgres to the other service pgadmin.
This configuration will be lost, when the composition is restartet, as no volumes to persist the configuration are specified. Therefore, you have to follow steps from Importing-servers and repeat them every time you start the composition.
eg: build you own pgadmin image that specifies the json to import at startup
Use the docker compose build: property to specify a source
Ok after a night of sleep I found the issue. For the server Host I wrote the db name and not the real container name. So pgAdmin could not find the container.
Have a nice day. : )
I'm using docker-compose to run MariaDB and it is working fine. I am fetching jasper server and maria DB docker images and running them. When I telnet the jasper server image, it responds correctly, but when I telnet to MariaDB, it says:
telnet localhost 3306
Trying ::1...
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
What I might be doing wrong?
Here is the output of sudo docker ps -a:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9e759f106006 bitnami/jasperreports:7 "/app-entrypoint.sh …" 21 minutes ago Up 21 minutes 0.0.0.0:9093->8080/tcp, 0.0.0.0:443->8443/tcp ceyedev_jasperreports_1
9242e52f6af8 bitnami/mariadb:10.3 "/opt/bitnami/script…" 21 minutes ago Up 21 minutes 3306/tcp ceyedev_mariadb_1
Here is my docker compose file:
version: '2'
services:
mariadb:
image: 'bitnami/mariadb:10.3'
environment:
- MARIADB_USER=bn_jasperreports
- MARIADB_DATABASE=bitnami_jasperreports
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- 'mariadb_data:/bitnami'
jasperreports:
image: 'bitnami/jasperreports:7'
environment:
- MARIADB_HOST=mariadb
- MARIADB_PORT_NUMBER=3306
- JASPERREPORTS_DATABASE_USER=bn_jasperreports
- JASPERREPORTS_DATABASE_NAME=bitnami_jasperreports
- ALLOW_EMPTY_PASSWORD=yes
ports:
- '9093:8080'
- '443:8443'
volumes:
- 'jasperreports_data:/bitnami'
depends_on:
- mariadb
volumes:
mariadb_data:
driver: local
jasperreports_data:
driver: local
You have to open the ports in your Docker compose file (that thing you posted is called a Docker Compose file, not Dockerfile which is the one containing the commands to build a Docker image).
In the mariadb section make it like this:
services:
mariadb:
image: 'bitnami/mariadb:10.3'
environment:
- MARIADB_USER=bn_jasperreports
- MARIADB_DATABASE=bitnami_jasperreports
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- 'mariadb_data:/bitnami'
ports:
- 3306
This way, the 3306 port of MariaDB will be exposed to your local computer. This means:
that you may access MariaDB through the 3306 port
that ANYONE with direct network access to your computer (i.e. local IP address) will be able to access MariaDB through port 3306.
Bear in mind those two things regarding your system security.
I setup a very basic rails app that connects to a postgres instance and a rails instance. For some reason, when I execute rails db:setup, it won't connect to the database. My setup is below. Don't think it can get much simpler.
Important to note, postgres was up and ready to accept connections.
docker-compose.yml
version: '3.4'
services:
postgres:
image: postgres
environment:
- POSTGRES_PASSWORD=password
volumes:
- ./tmp/postgres/data:/var/lib/postgres/data
redis:
image: redis
ports:
- '6379:6379'
web:
build:
context: .
target: development
command: tail -f /dev/null # I exec'ed in to run command
depends_on:
- postgres
- redis
env_file:
- ./docker-dev.env
ports:
- '3000:3000'
database.yml
development:
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
password: password
host: postgres
The error ouput
D, [2020-04-03T03:20:34.562188 #32] DEBUG -- : using default configuration
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
Couldn't create 'hinge_test_db' database. Please check your configuration.
rails aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
The error is not related to docker but related to postgres, open postgres configuration file pg_hba.conf and set it to allow permissions from localhost and restart the postgres server. Hope it helps 👍
Issue
I cannot connect with MySQL from the host the MariaDB Container is running from. Here are some infos concerning the environment:
docker compose-file
version: '3.1'
services:
db:
image: mariadb
restart: always
environment:
BIND-ADDRESS: 0.0.0.0
MYSQL_ROOT_PASSWORD: example
ports:
- 3306:3006
adminer:
image: adminer
restart: always
ports:
- 8080:8080
Connecting with the container via docker exec -it rancherclientplatform_db_1 /bin/bash and the connecting with mysql -uroot -p unsurprisingly works.
GRANTS
Grants are as follows:
MariaDB [(none)]> SHOW GRANTS;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root#localhost
|
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY PASSWORD '*57237BB49761F29AB9724BA084E811D70C12393D' WITH GRANT OPTION |
| GRANT PROXY ON ''#'%' TO 'root'#'localhost' WITH GRANT OPTION
|
+----------------------------------------------------------------------------------------------------------------------------------------+
On the host
No when I try to connect on the host, neither
mysql -uroot -p nor
mysql -hlocalhost -uroot -p nor
mysql -h127.0.0.1 -uroot -p
work. The first 2 fail with a socket error, -h127.0.0.1 fails with
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"
The port 3306 itself seems to be published to the host properly, as
nmap -p3306 localhost delivers
PORT STATE SERVICE
3306/tcp open mysql
Any ideas on what to do here?
MariaDB default port is 3306.
so :
ports:
- 3306:3006
you probably want to map port using 3306:3306 if you want to access mariadb on localhost using port 3306