Making migrations for hasura container and running console - postgresql

I want to make a developer offline space to develop my database with hasura
I know the existence of the container with the tag cli-migrations, but the command:
hasura-cli console
doesn't work for accessing outside of the container.
My configuration for the docker-compose.yml is:
version: '3'
services:
hasura:
environment:
- HASURA_GRAPHQL_DATABASE_URL=postgres://[some pass]:[some user]#db:5432/[some db]
- HASURA_GRAPHQL_ENABLE_CONSOLE=false
image: hasura/graphql-engine:v1.0.0-rc.1.cli-migrations
container_name: hasura
volumes:
- ./hasura-migrations:/hasura-migrations
networks:
- hasura-db
ports:
- "8081:8080"
- "8082:8081"
restart: always
command: hasura-cli console --console-port 8081 --no-browser
db:
environment:
- POSTGRES_USER=[some user]
- POSTGRES_PASSWORD=[some pass]
- POSTGRES_DB=[some db]
image: postgres:11.4-alpine
container_name: db
restart: always
networks:
- hasura-db
networks:
hasura-db:
There is a Pull request in the hasura graphql project for this issue, but is not merged.
I'm looking for a workaround for this pull request now.

I found a workaround for this!
If I install hasura cli in my machine and use
hasura console --console-port 8080 --endpoint http://127.0.0.1:8081
I can connect to the hasura api and run a console locally.
this is my updated docker-compose.yml
version: '3'
services:
hasura:
environment:
- HASURA_GRAPHQL_DATABASE_URL=postgres://[some pass]:[some user]#db:5432/[some db]
- HASURA_GRAPHQL_ENABLE_CONSOLE=false
image: hasura/graphql-engine:v1.0.0-rc.1.cli-migrations
container_name: hasura
volumes:
- ./hasura-migrations:/hasura-migrations
networks:
- hasura-db
ports:
- "8081:8080"
restart: always
db:
environment:
- POSTGRES_USER=[some user]
- POSTGRES_PASSWORD=[some pass]
- POSTGRES_DB=[some db]
image: postgres:11.4-alpine
container_name: db
restart: always
networks:
- hasura-db
networks:
hasura-db:

Related

SonarQube cannot access PostgresDB

I am trying to set up SonarQube self-hosted using docker with docker-compose. To use SonarQube via HTTPS I am using nginx as reverse proxy and the jrcs/letsencrypt-nginx-proxy-companion to handle the SSL-Certificate.
Now I have configured SonarQube using the following docker-compose.yml:
version: '3'
networks:
ext:
int:
volumes:
certs:
vhosts:
html:
postgresql_data:
postgresql:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:
services:
nginxproxy:
image: jwilder/nginx-proxy:alpine
container_name: nginxproxy
hostname: nginxproxy
restart:
unless-stopped
networks:
- ext
volumes:
- certs:/etc/nginx/certs:ro
- vhosts:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./config/my_proxy.conf:/etc/nginx/conf.d/myproxy.conf:ro
ports:
- 80:80
- 443:443
labels:
- com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy
environment:
- SSL_POLICY=Mozilla-Intermediate
nginxproxy_comp:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginxproxy_comp
hostname: nginxproxy_comp
restart:
unless-stopped
depends_on:
- nginxproxy
networks:
- ext
volumes:
- certs:/etc/nginx/certs
- vhosts:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- /var/run/docker.sock:/var/run/docker.sock:ro
sonarqube:
image: sonarqube:community
container_name: sonarqube
hostname: sonarqube
depends_on:
- db
restart:
unless-stopped
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_logs:/opt/sonarqube/logs
- sonarqube_extensions:/opt/sonarqube/extensions
environment:
- SONAR_JDBC_URL=jdbc:postgresql://localhost:5432/sonarqube
- SONAR_JDBC_USER=sonarqube
- SONAR_JDBC_PASSWORD=sonarqube
networks:
- int
ports:
- 9000:9000
db:
image: postgres:12
container_name: db
hostname: db
networks:
- int
ports:
- 5432:5432
environment:
- POSTGRES_USER=sonarqube
- POSTGRES_PASSWORD=sonarqube
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data
restart:
unless-stopped
Now when I try to start docker-compose, SonarQube is giving me the following Error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader#277050dc-org.sonar.db.DefaultDatabase': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Fail to connect to database
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Can anyone please tell me what i did wrong?
What I see here is the incorrect JDBC URL. It must below
SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonarqube
Since you have network between containers DB accessible via db
Also, under SonarQube container add below as well
privileged: true
Check one of my sample project in GitHub
https://github.com/shamith234/sonarqube-9.5-postgres-docker/blob/master/docker-compose.yml

Password auth failed for user "postgres"

I am trying to run my postgres server and nestjs project with docker script and it does fire up the server and database. While firing up it does run migrations too but when I open pgAdmin I see no database there and if i try to create new server i get fatal pasword incorrect error. Also my server crashes too with error saying Password authentication failed for user "postgres". It was running fine yesterday but today its not running at all. I tried pruning everything and made fresh build and then compose up but nothing. Here is docker script
version: "3.5"
services:
dev-api:
container_name: xxxxxxxx-api
build:
context: .
dockerfile: Dockerfile
depends_on:
- dev-db
environment:
DATABASE_URL: postgresql://postgres:postgres#dev-db:5432/xxxxxxx_api
APP_ENV: development
PORT: 3030
WAIT_HOSTS: dev-db:5432
ports:
- "3030:3030"
- "9229:9229"
volumes:
- .:/usr/api/
dev-db:
container_name: xxxxxxxx-postgres
image: postgres:13.5-alpine
restart: always
ports:
- "5432:5432"
volumes:
- ./pg-data:/var/lib/postgresql/data
- ./src/db/docker/init.sql:/docker-entrypoint-initdb.d/dbinit.sql
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=xxxxxxx_api
expose:
- "5432"
pgadmin:
container_name: xxxxxxx-pgadmin
image: dpage/pgadmin4:6.2
ports:
- 8080:80
volumes:
- pgadmin-data:/var/lib/pgadmin
environment:
- PGADMIN_DEFAULT_EMAIL=user#postgres.com
- PGADMIN_DEFAULT_PASSWORD=postgres
- PGADMIN_LISTEN_PORT=80
depends_on:
- dev-db
volumes:
pgadmin-data:

Can't connect containers mariadb and phpmyadmin

I get the error "mysqli::real_connect(): (HY000/2002): No such file or directory" when trying to login to phpmyadmin. I verified I can connect to the DB container from the localhost using mysql -h 127.0.0.1 -P 3306 -u root -p. Below is my docker-compose file:
version: "3.7"
########################### SECRETS
secrets:
mysql_root_password:
file: $DOCKERDIR/secrets/mysql_root_password
########################### SERVICES
services:
# Portainer - WebUI for Containers
portainer:
container_name: portainer
image: portainer/portainer-ce:latest
restart: unless-stopped
command: -H unix:///var/run/docker.sock
security_opt:
- no-new-privileges:true
ports:
- "$PORTAINER_PORT:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- $DOCKERDIR/portainer/data:/data
environment:
- TZ=$TZ
# MariaDB - MySQL Database
db:
container_name: db
image: linuxserver/mariadb:latest
restart: always
security_opt:
- no-new-privileges:true
ports:
- "$MARIADB_PORT:3306"
volumes:
- $DOCKERDIR/mariadb/data:/config
environment:
- PUID=$PUID
- PGID=$PGID
- TZ=$TZ
- FILE__MYSQL_ROOT_PASSWORD=/run/secrets/mysql_root_password
secrets:
- mysql_root_password
# phpMyAdmin - Database management
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
container_name: phpmyadmin
restart: unless-stopped
depends_on:
- db
security_opt:
- no-new-privileges:true
ports:
- "$PHPMYADMIN_PORT:80"
volumes:
- $DOCKERDIR/phpmyadmin:/etc/phpmyadmin
environment:
- PMA_HOST=db
#- PMA_ARBITRARY=1
- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password
secrets:
- mysql_root_password
# Dozzle - Real-time Docker Log Viewer
dozzle:
image: amir20/dozzle:latest
container_name: dozzle
restart: unless-stopped
security_opt:
- no-new-privileges:true
ports:
- "$DOZZLE_PORT:8080"
environment:
DOZZLE_LEVEL: info
DOZZLE_TAILSIZE: 300
DOZZLE_FILTER: "status=running"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
For the life of me, I can't figure out what I am doing wrong to log into Phpmyadmin. Can someone explain my mistake or mistakes and point me in the right direction? Thanks
I figured the issue out, first was I had the network set on the pphpmyadmin section, and not db, once I added the network statement to db section, I was able to connect.

PostgreSQL + metabase connection refused

I am trying to configure postgres to run with springboot and metabase. Each service is running separately alone but when I try to put the 3 together in a docker-compose file, I am getting the following error :
Caused by: org.postgresql.util.PSQLException: Connection to 0.0.0.0:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
metabase-container | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:303)
However, I have mapped the port 5432 of db to the port 5432 of the metabase container.
And yet, It doesn't seem to work. Any help on this issue? (please find my docker-compose file below)
version: '2'
services:
spring:
image: 'realtime:latest'
container_name: spring
depends_on:
- db
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/compose-postgres
- SPRING_DATASOURCE_USERNAME=compose-postgres
- SPRING_DATASOURCE_PASSWORD=same
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
volumes:
- /home/vagrant/valorisation-2.0:/app
command: ["java", "-jar", "rtv-1.jar"]
mem_limit: 10g
mem_reservation: 10g
ports:
- "8079:8080"
db:
image: 'postgres:13.1-alpine'
container_name: db
environment:
- POSTGRES_USER=compose-postgres
- POSTGRES_PASSWORD=********
- METABASE_PASSWORD=same
ports:
- "8078:5432"
- "54320:5432"
metabase:
container_name: metabase-container
restart: "always"
image: metabase/metabase
ports:
- "3000:3000"
- "5432:5432"
environment:
- MB_DB_TYPE=postgres
- MB_DB_DBNAME=db
- MB_DB_PORT=5432
- MB_DB_USER=compose-postgres
- MB_DB_PASS=same
- MB_DB_HOST=0.0.0.0
- MB_ENCRYPTION_SECRET_KEY=********
Try changing MB_DB_HOST in the metabase environmental variables from 0.0.0.0 to db.
The subtilty I hadn't understood is that all the services are in the same network. Hence, deleting port forwarding (which exposes the services to outside components but is irrelevant for communication within the container) between the services and changing the Metabase configuration file does the job. Here is the modified docker-compose.yml file :
version: '2'
services:
spring:
image: 'realtime:latest'
container_name: spring
depends_on:
- db
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/compose-postgres
- SPRING_DATASOURCE_USERNAME=********
- SPRING_DATASOURCE_PASSWORD=**********
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
volumes:
- /home/vagrant/valorisation-2.0:/app
command: ["java", "-jar", "rtv-1.jar"]
mem_limit: 10g
mem_reservation: 10g
ports:
- "8079:8080"
db:
image: 'postgres:13.1-alpine'
container_name: db
environment:
- POSTGRES_USER=compose-postgres
- POSTGRES_PASSWORD=compose-postgres
- METABASE_PASSWORD=compose-postgres
ports:
- "8078:5432"
metabase:
container_name: metabase-container
depends_on:
- db
restart: "always"
image: metabase/metabase
ports:
- "3000:3000"
environment:
- MB_DB_TYPE=postgres
- MB_DB_DBNAME=********
- MB_DB_PORT=5432
- MB_DB_USER=************
- MB_DB_PASS=compose-postgres
- MB_DB_HOST=db
- MB_ENCRYPTION_SECRET_KEY=***********

Intergrate elasticsearch with multiple mongodb in docker-compose

I have a implemented a microservice architecture with several servers and databases. I have installed elasticsearch with docker and when I do docker-compose up, everything seems to run fine.
However I would like to integrate the elasticsearch with the several databases (2 mongodb in this sample below) in the system. How do I synch the two mongodb in two different containers with elasticsearch so that I can search them?
client:
container_name: client
stdin_open: true
build:
context: ./client
dockerfile: Dockerfile
restart: always
volumes:
- './client:/app'
ports:
- '1000:3000'
environment:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING=true
weatherdb:
container_name: weather-db
image: mongo
restart: always
ports:
- '2002:27017'
volumes:
- ./weather_service/weather_db:/data/db
networks:
- backend
weather-service:
container_name: weather-service
build: ./weather_service
restart: always
ports:
- "1002:3000"
depends_on:
- weatherdb
links:
- elasticsearch
networks:
- backend
newsdb:
container_name: news-db
image: mongo
restart: always
ports:
- '2003:27017'
volumes:
- ./news_service/news_db:/data/db
networks:
- backend
news-service:
container_name: news-service
build: ./news_service
restart: always
ports:
- "1003:3000"
depends_on:
- newsdb
links:
- elasticsearch
networks:
- backend
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.0
container_name: elasticsearch
restart: always
ports:
- 9200:9200
- 9300:9300
environment:
ES_JAVA_OPTS: '-Xms512m -Xmx512m'
network.bind_host: 0.0.0.0
network.host: 0.0.0.0
discovery.type: single-node
volumes:
- ./elasticsearch/esdata:/usr/share/elasticsearch/data
networks:
- backend
Its very simple to just add a elasticsearch docker section in any docker-compose file and start it, all these are independent docker containers and as long as their exposed port on host is not interfering each other and you have the correct configuration in place it should work.
Please refer elasticsearch multi-docker installation using docker file for more info.
NOTE: You have not mentioned what exact issue you are facing, you have mentioned everything ie all docker containers are running file, so please explain in detail what exactly you are trying to solve