I've been trying to fix this for two days now. I've followed a tutorial to setup postgres with pgadmin using docker. Since I need postgis I modified the tutorial to get the following docker-compose.yml file:
version: '3'
services:
fullstack-postgres: # https://hub.docker.com/r/kartoza/postgis/
image: kartoza/postgis:12.0
container_name: full_db_postgres
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASS=${DB_PASSWORD}
- POSTGRES_DBNAME=${DB_NAME}
ports:
- '5432:5432'
volumes:
- ./postgres_data/:/var/lib/postgresql
networks:
- fullstack
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin_container
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
depends_on:
- fullstack-postgres
ports:
- "5050:80"
networks:
- fullstack
restart: unless-stopped
# Networks to be created to facilitate communication between containers
networks:
fullstack:
driver: bridge
After running docker-compose up I can access pgadmin on localhost:5050. I'm able to connect with my postgres instance. In order to connect I do object>create>server. In the connection tab I then give the postgres docker container id to connect:
I now can create a table e.g.:
CREATE TABLE mytable(
loc_id serial PRIMARY KEY,
text VARCHAR (50) UNIQUE NOT NULL,
loc POINT NOT NULL,
time TIMESTAMP
);
Which is working. I can insert data into my table and query it without problem. The issues are in pgadmin:
I cannot see my table(s) in the UI browser on the left
The explain tab is not showing anything
It feels pgadmin4 didn't get configured properly. Any idea on how to solve that?
Related
I'm trying create a new database called "slack-ruby-bot-server-events_sample_development" from my docker-compose.yml, but when I enter into the container for check the databases, sadly does not exist.
Here my docker-compose.yml
version: '3.9'
services:
hermes:
depends_on:
- mongodb
build:
context: ./hermes-app/
container_name: hermes
tty: true
ports:
- "5000:5000"
networks:
- netrmes
mongodb:
image: 'bitnami/mongodb:5.0.8'
container_name: mongodb
restart: on-failure
environment:
- MONGO_INITDB_DATABASE=${MONGODB_DATABASE}
- MONGO_INITDB_ROOT_USERNAME=${MONGODB_ROOT_USER}
- MONGO_INITDB_ROOT_PASSWORD=${MONGODB_ROOT_PASSWORD}
ports:
- "27017:27017"
volumes:
- 'mongodb_data:/bitnami/mongodb'
networks:
- netrmes
networks:
netrmes:
driver: bridge
volumes:
mongodb_data:
driver: local
The root_user and root_password is created successfully, but when i run the command "mongosh" into the container, the database in use is "test".
Anyone knows the way to set up that?, thanks in advance.
I think this variable "MONGO_INITDB_DATABASE" is just used to defined the default DB that the
JS scripts in /docker-entrypoint-initdb.d/*.js default to if you
insert some data or init something (indexes, create timeseries
collections, …). It’s like the default use myDB that you can use.
If you don’t create anything in that DB (I don’t see any script in
here) then nothing happens and the DB isn’t created. MongoDB will
create it if you actually store something in there. Else there is no
reason to create an empty vessel.
Post: https://www.mongodb.com/community/forums/t/is-database-not-initialized-when-spinning-up-a-mongodb-docker-container/148786
I have used docker-compose.yaml. I have configured in docker-compose.yml bellow like:
Step 1: In docker-compose.yaml I user bellow code
services:
postgres:
image: postgres
container_name: postgres
hostname: postgres
volumes:
- db-data:/var/lib/postgresql/data
restart: always
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: accountdb
account-opening:
image: ehaque95/pocv1-account-opening:0.0.1-SNAPSHOT
mem_limit: 700m
ports:
- "8081:8081"
networks:
- account-network
depends_on:
- postgres
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/accountdb
volumes:
db-data:
Step 2 :
I have configure applicaiton.yml in spring boot bellow like:
spring:
datasource:
url: jdbc:postgresql://postgres:5432/accountdb
username: postgres
password: postgres
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
database: postgresql
hibernate:
ddl-auto: update
properties:
dialect: org.hibernate.dialect.PostgreSQLDialect
Note : postgresql server IP change frequently. When i run docker inpspect ,it shows some "IPAddress": "172.19.0.2" or sometimes "IPAddress": "172.19.0.3".It shows when I run docker-compose up again.
It shows connection error.what is the wrong of my code connect to postgresql. Please help me
For two containers to communicate with each other, they must be on the same Docker network. By default, Compose creates a network named default and attaches containers to it; if you specify other networks: for a container, then they are not attached to the default network.
In your docker-compose.yml, the account-opening container has a networks: block, but postgres doesn't:
version: '3.8'
services:
postgres:
...
# no networks:, so implicitly
# networks: [default]
account-opening:
...
networks: [account-network] # and not default
# The postgres container is on the default network
# This container is on account-network
# And so this host name doesn't resolve
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/accountdb
There's nothing wrong with using the default network. For most typical applications you can delete all of the networks: blocks in the entire file. Then the default network will get created with default settings, and all of the containers will attach to that network, and be able to address each other by their Compose service name.
try
url: jdbc:postgresql://localhost:5432/accountopendb
if you are running both the spring app and the postgresql container in the same machine in your datasource config.
I know this question is already asked and also answer given. But it is not working for me. I follow the same. My postgres container is running fine. I checked inside the container that /docker-entrypoint-initdb.d/init.sql exist.I used the following docker-compose.yml.
version: "3"
services:
postgres:
image: postgres:latest
network_mode: bridge
container_name: postgres
expose:
- 5432
ports:
- 5432:5432
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
- POSTGRES_PASSWORD=admin
- POSTGRES_USER=postgres
- POSTGRES_DB=dev
restart: unless-stopped
# APP
profile_editor2:
build:
context: .
dockerfile: ./Dockerfile
network_mode: bridge
container_name: profile_editor2
volumes:
- ./image:/app/image
expose:
- 8080
ports:
- 8080:8080
restart: unless-stopped
depends_on:
- postgres
links:
- postgres
volumes:
postgres-data:
init.sql:-
create table sometable(id int);
No table created. I can see only the database is created. How do I create a table and also if possible insert some data into the table?
You can write your queries inside init.sql, in this squence:-
DROP DATABASE IF EXISTS test_db;
CREATE DATABASE test_db;
\c test_db;
CREATE TABLE Role(
RoleID SERIAL PRIMARY KEY,
RoleName varchar(50),
);
insert into Role(RoleName)
values ('Admin'),('User');
I know this question is already asked and also answer given. But it is not working for me. I follow the same. My postgres container is running fine. I checked inside the container that /docker-entrypoint-initdb.d/init.sql exist.I used the following docker-compose.yml.
version: "3"
services:
postgres:
image: postgres:latest
network_mode: bridge
container_name: postgres
expose:
- 5432
ports:
- 5432:5432
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
- POSTGRES_PASSWORD=admin
- POSTGRES_USER=postgres
- POSTGRES_DB=dev
restart: unless-stopped
# APP
profile_editor2:
build:
context: .
dockerfile: ./Dockerfile
network_mode: bridge
container_name: profile_editor2
volumes:
- ./image:/app/image
expose:
- 8080
ports:
- 8080:8080
restart: unless-stopped
depends_on:
- postgres
links:
- postgres
volumes:
postgres-data:
init.sql:-
create table sometable(id int);
No table created. I can see only the database is created. How do I create a table and also if possible insert some data into the table?
You can write your queries inside init.sql, in this squence:-
DROP DATABASE IF EXISTS test_db;
CREATE DATABASE test_db;
\c test_db;
CREATE TABLE Role(
RoleID SERIAL PRIMARY KEY,
RoleName varchar(50),
);
insert into Role(RoleName)
values ('Admin'),('User');
I have a spring boot app that is correctly configured to work on localhost's Postgres. I have schema.sql and data.sql in the Spring boot resource directory. When I start up it creates the table and inserts data. But now I wish to make docker container for my app and Postgres database. I have the following docker-compose.yml. The building and start of the container are fine. But it doesn't create any table and of course, no data inserted. So how do I create table and insert data by docker-compose?
version: "3"
services:
postgres:
image: postgres:latest
network_mode: bridge
container_name: postgres
expose:
- 5432
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=dev
- POSTGRES_USER=masi
- POSTGRES_DB=testdb
restart: unless-stopped
# APP
profile_editor:
build:
context: .
dockerfile: ./Dockerfile
network_mode: bridge
container_name: profile_editor
volumes:
- ./image:/app/image
expose:
- 8080
ports:
- 8080:8080
restart: unless-stopped
depends_on:
- postgres
links:
- postgres