This is my docker-compose.yml
services:
db:
container_name: postgres
image: postgres:latest
restart: always
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: test_db
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin#test.com
PGADMIN_DEFAULT_PASSWORD: admin123
ports:
- 8002:80
Pg-admin is running in port 8002
To connect pgsql with pgadmin I have used below credential to add new server in pgadmin, I am getting below error,
How do I will map this connection ?
In docker panel it's showing postgres is running
My operating system : Mac m1.
When you using more than one container and there are related, localhost not works.
Instead of localhost set the ip of the host in which your postgress is running.
Read these topics to understand ip vs localhost in docker
https://stackoverflow.com/a/52213178/3957754
https://stackoverflow.com/a/63207679/3957754
Related
I have a very simple docker-compose.yml:
version: '3.1'
services:
db:
image: postgres
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: my_password
POSTGRES_DB: demo
And start it with: docker-compose up -d
It starts well:
Creating network "bootcamp_default" with the default driver
Creating bootcamp_db_1 ... done
Name: bootcamp_db_1
Command: docker-entrypoint.sh postgres
State: up
Ports: 0.0.0.0:5432->5432/tcp,:::5432->5432/tcp
When I go into the container I see that demo db exists, but when I try to connect to it any utils say that demo db is not existed.
How can I connect to it?
Solved the problem by moving the project to Ubuntu system. It was caused by OS settings.
I have a docker-compose file that looks like this
version: "3"
services:
db:
image: postgres
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_USER: michael
POSTGRES_PASSWORD: pass123
admin:
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4#pgadmin.org}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
PGADMIN_CONFIG_SERVER_MODE: 'False'
ports:
- "5050:5050"
I run docker-compose up -d and I can see my apps running from Docker Desktop. I cannot however connect to my pgadmin instance at port 5050 using localhost. Any ideas?
Docker container of pgAdmin by default runs on port 80 as per the documentation here https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html
You are exposing port 5050 through the mapping. Either add a environment variable PGADMIN_LISTEN_PORT to the docker_compose to make pgAdmin run on port 5050
OR
change port mapping to 5050:80 for the pgAdmin service
Check the docker inspect or docker ps results to ensure that you have your port exposed correctly
Try to connect to it using the public IP
I'm new to docker and postgres. It should be mentioned that my problem only occurs with docker-compose.Here's my .yml file:
version: '3.5'
services:
postgres:
container_name: postgres_container
image: postgres
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- "5432:5432"
networks:
- postgres
restart: unless-stopped
pgadmin:
container_name: pgadmin_container
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4#pgadmin.org}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
volumes:
- pgadmin:/root/.pgadmin
ports:
- "${PGADMIN_PORT:-5050}:80"
networks:
- postgres
restart: unless-stopped
networks:
postgres:
driver: bridge
volumes:
postgres:
pgadmin:**
When I run docker-compose run postgres bash and then run psql -U postgres i get the following error
psql: error: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Can someone help?
With docker-compose run postgres bash you are replacing the entry-point script of the image with bash. So the DB is not running. Try
$ docker-compose up --detach postgres
$ docker-compose exec postgres bash
instead.
You can use: psql -U postgres -h postgres
specifying the host with the network you've created.
I setup my docker mysql and phpadmin via
version: '3.2'
services:
mysqllocal:
image: mysql:8.0
container_name: container_mysqllocal
restart: always
ports:
- '6603:3306'
environment:
MYSQL_ROOT_PASSWORD: pass1234
MYSQL_ROOT_HOST: '%'
phpmyadmin:
depends_on:
- mysqllocal
image: phpmyadmin/phpmyadmin
container_name: container_phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: mysqllocal
UPLOAD_LIMIT: 3000000000
docker inspect container_mysqllocal and got '172.30.0.2'. However when I tried to connect mysql via SequelPro. It gives Connection Failed error. How do I connect mysql to my SequelPro / mysql workbench app, is there any configuration I've missed?
Below is the screenshot of my SequelPro connection:
have you tried to access mysql from your local machine with the port defined, in your config is 6603
Docker-toolbox on windows. How to connect to the database from a program like WorkBench?
version: "3.1"
services:
mysql:
image: mysql:5.7
command: --innodb_use_native_aio=0
restart: always
volumes:
- //c/Users/radik/projects/laravel/storage/docker/mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: 123456
ports:
- 33061:3306
I'm trying to connect to the database from HeidiSql
host:192.168.99.100
name: root
port: 33061
result:
Cannot connect to MySQL server
you have 33333:3306 in your config so you should connect to port 33333 not 33061 right?
If docker runs on your local machine, you can just use localhost (127.0.0.1) as host.