Docker compose issue with pgAdmin - docker

I have the following docker-compose file.
But I am unable to connect to pgAdmin from the browser. I don't understand the issue as if I send data from postman then it gets saved to pgAdmin app which is on my local machine But when I visit localhost://5050/browser/ then that table does not appear in the browser.
version: '1'
services:
postgres:
container_name: postgres_container
image: 'postgres:latest'
environment:
POSTGRES_USER: ${POSTGRES_USERNAME}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DATABASE}
ports:
- 5432:5432
networks:
app_network:
ipv4_address: 172.26.0.11
restart: unless-stopped
healthcheck:
test: ['CMD', 'pg_isready -U postgres']
interval: 5s
timeout: 5s
retries: 5
volumes:
- postgres:/data/postgres
pgadmin:
container_name: pgadmin_container
image: dpage/pgadmin4
depends_on:
- postgres
volumes:
- pgadmin:/var/lib/pgadmin
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-'email'}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-'password'}
PGADMIN_CONFIG_SERVER_MODE: 'False'
ports:
- '${PGADMIN_PORT:-5050}:80'
networks:
- app_network
restart: unless-stopped
networks:
app_network:
external: true
driver: bridge
volumes:
postgres:
pgadmin:
The tables from my pgAdmin app.
The tables from the localhost:5050/browser/ link.
I have correctly set the connection for pgAdmin in browser.

Related

Secrets are not available in Docker container

I create secret "databasePassword" using the below command:
echo 123456 | docker secret create databasePassword -
Below is my yml file to create the MySQL and phpMyAdmin where I'm trying to use this secret in the yml file.
version: '3.1'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: unless-stopped
container_name: db-mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'false'
MYSQL_ROOT_PASSWORD: /run/secrets/databasePassword
ports:
- 3306:3306
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
timeout: 20s
retries: 10
secrets:
- databasePassword
beyond-phpmyadmin:
image: phpmyadmin
restart: unless-stopped
container_name: beyond-phpmyadmin
environment:
PMA_HOST: db-mysql
PMA_PORT: 3306
PMA_ARBITRARY: 1
links:
- db
ports:
- 8081:80
But the databasePassword is not getting set as 123456. It is set as the string "/run/secrets/databasePassword" I tried using docker stack deploy also, but it also didn't work.
I tried setting the secrets at the end of the file like below by some web research, but it also didn't work.
version: '3.1'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: unless-stopped
container_name: db-mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'false'
MYSQL_ROOT_PASSWORD: /run/secrets/databasePassword
ports:
- 3306:3306
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
timeout: 20s
retries: 10
secrets:
- databasePassword
beyond-phpmyadmin:
image: phpmyadmin
restart: unless-stopped
container_name: beyond-phpmyadmin
environment:
PMA_HOST: db-mysql
PMA_PORT: 3306
PMA_ARBITRARY: 1
links:
- db
ports:
- 8081:80
secrets:
databasePassword:
external: true
Docker cannot know that /run/secrets/databasePassword is not a literal value of the MYSQL_ROOT_PASSWORD variable, but a path to a file that you would like to read the secret from. That's not how secrets work. They are simply available in a /run/secrets/<secret-name> file inside the container. To use a secret, your container needs to read it from the file.
Fortunatelly for you, the mysql image knows how to do it. Simply use MYSQL_ROOT_PASSWORD_FILE instead of MYSQL_ROOT_PASSWORD:
services:
db:
image: mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'false'
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/databasePassword
secrets:
- databasePassword
...
secrets:
databasePassword:
external: true
See "Docker Secrets" in the mysql image documentation.

Cant login into pgAdmin 4 with docker

I feel like its highly stupid question, but I just cant log into my pgAdmin.
My compose.yml file is
services:
back:
container_name: blog-django
build: ./blog-master
command: gunicorn blog.wsgi:application --bind 0.0.0.0:8000
expose:
- 8000
links:
- db
volumes:
- blog-django:/usr/src/app/
- blog-static:/usr/src/app/static
- blog-media:/usr/src/app/media
env_file: ./.env
depends_on:
db:
condition: service_healthy
nginx:
container_name: blog-nginx
build: ./nginx/
ports:
- "1337:80"
volumes:
- blog-static:/usr/src/app/static
- blog-media:/usr/src/app/media
links:
- back
depends_on:
- back
db:
container_name: db
image: postgres:14
restart: always
expose:
- "5432"
environment:
POSTGRES_DB: docker
POSTGRES_USER: docker
POSTGRES_PASSWORD: docker
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data/
healthcheck:
test: ["CMD-SHELL", "pg_isready -U docker"]
interval: 5s
timeout: 5s
retries: 5
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin
restart: always
ports:
- "5050:80"
environment:
PGADMIN_DEFAULT_EMAIL: admin#admin.com
PGADMIN_DEFAULT_PASSWORD: root
volumes:
- pgadmin-data:/var/lib/pgadmin
depends_on:
- db
links:
- db
mailhog:
container_name: mailhog
image: mailhog/mailhog
#logging:
# driver: 'none' # disable saving logs
expose:
- 1025
ports:
- 1025:1025 # smtp server
- 8025:8025 # web ui
volumes:
blog-django:
blog-static:
blog-media:
pgdata:
pgadmin-data:
and my .env file is
DEBUG=1
SECRET_KEY='a key'
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=docker
SQL_USER=docker
SQL_PASSWORD=docker
SQL_HOST=db
SQL_PORT=5432
DATABASE=postgres
but with any username/email and password it keeps saying "wrong email/password". although if I login with "admin#admin.com" error is "Incorrect username or password" and with username it says "email/username is not valid"
I tried using admin#mailhog.local email so I can do password recovery, but again, "Incorrect username or password"

How do I give a container a static ip, or how do I link two Docker containers?

I have a container with RabbitMQ, it has to connect to the external IP of the application container, the problem is that this external IP is dynamic and changes every time. Accordingly, I have to manually change the configuration of my RabbitMQ every time. Maybe you can somehow set a static ip for the "App" container so that it does not change or somehow connect these two containers?
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- postgres
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./docker/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- postgres
#Redis
redis:
image: 'redis:alpine'
ports:
- "6379:6379"
#PostgreSQL
postgres:
container_name: postgres_container
image: postgres
hostname: postgres
environment:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: secret
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
depends_on:
- postgres
#RabbitMQ
rabbit:
image: "rabbitmq:3-management"
hostname: "rabbit"
environment:
RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
RABBITMQ_DEFAULT_USER: "rabbitmq"
RABBITMQ_DEFAULT_PASS: "rabbitmq"
RABBITMQ_DEFAULT_VHOST: "/"
ports:
- "15672:15672"
- "5672:5672"
labels:
NAME: "rabbitmq"
networks:
- postgres
#ElasticSearch
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3
ports:
- "9200:9200"
- "9300:9300"
networks:
- postgres
#Docker Networks
networks:
postgres:
driver: bridge
volumes:
postgres:
pgadmin:
If they are in the same networks You can simply use the service name instead of the IP, just use the app, You can ping the app service name inside the rabbitMQ container and it works.
as you are using docker-compose all your containers are already on the same network. You can access a container from another container using the name you have specified:
i.e for rabbitmq it is rabbit
for redis it will be redis

How to link PostgreSQL container and PgAdmin in Docker?

I have a docker-compose file with postgres and pgadmin services in my Laravel project. The problem is that when I do the database migration, it succeeds, but when I go to pgadmin, I do not see the tables I created there. I guess I, as always, made a mistake while writing docker-compose and I just can't find what I was missing.
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- postgres
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./docker/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- postgres
#Redis
redis:
image: 'redis:alpine'
ports:
- "6379:6379"
#PostgreSQL
postgres:
container_name: postgres_container
image: postgres
environment:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: secret
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
#RabbitMQ
rabbit:
image: "rabbitmq:3-management"
hostname: "rabbit"
environment:
RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
RABBITMQ_DEFAULT_USER: "rabbitmq"
RABBITMQ_DEFAULT_PASS: "rabbitmq"
RABBITMQ_DEFAULT_VHOST: "/"
ports:
- "15672:15672"
- "5672:5672"
labels:
NAME: "rabbitmq"
#ElasticSearch
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3
ports:
- "9200:9200"
- "9300:9300"
networks:
- postgres
#Docker Networks
networks:
postgres:
driver: bridge
volumes:
postgres:
pgadmin:
In pgAdmin, when you add a new server, you need to define "host.docker.internal" (when on Windows) as Host (How to add a new server).

Docker-compose containers refuse connection

I',m trying to create e simple python-flask api connected to a postgress database,
So added to my docker-compose.yaml my api, db and pgadmin but when I try to start my docker-composer container it doens't
Here is my docker-compose.yaml
version: '3.7'
services:
api:
build: ./Backend/src
depends_on:
- db
environment:
STAGE: test
SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://test:test#db/test
networks:
- default
ports:
- 5000:5000
volumes:
- ./app:/usr/src/app/app
restart: always
db:
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
image: postgres:latest
networks:
- local
ports:
- 5432:5432
restart: always
volumes:
- ./postgres-data:/var/lib/postgresql
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: admim
PGADMIN_DEFAULT_PASSWORD: admin
ports:
- 5050:80
networks:
- local
restart: always
networks:
local:
driver: bridge
Running the docker from pycharm I get this error:
Deploying 'Compose: docker-compose-dev.yaml'...
Failed to deploy 'Compose: docker-compose-dev.yaml': Sorry but parent: com.intellij.execution.impl.ConsoleViewImpl[,0,0,1008x155,invalid,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=] has already been disposed (see the cause for stacktrace) so the child: com.intellij.util.Alarm#56e3f4b will never be disposed

Resources