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.
Related
I have the a docker-compose configuration for Keycloak and Postgres that works fine.
Now, I have exported the config in real-export.json in order to restart Keycloak with these configuration. Unfortunately, the Keycloak container does not work as expected.
Original docker-compose:
version: '3.1'
services:
postgres:
image: postgres
volumes:
- ~/docker/volumes/keycloak-db:/var/lib/postgresql/data
environment:
POSTGRES_DB: keycloak
POSTGRES_USER: keycloak
POSTGRES_PASSWORD: ${KEYCLOAK_DB_PASS}
keycloak:
image: mihaibob/keycloak:14.0.0
environment:
DB_VENDOR: POSTGRES
DB_ADDR: postgres
DB_DATABASE: keycloak
DB_USER: keycloak
DB_SCHEMA: public
DB_PASSWORD: ${KEYCLOAK_DB_PASS}
KEYCLOAK_USER: admin
KEYCLOAK_PASSWORD: ${KEYCLOAK_PASS}
# Uncomment the line below if you want to specify JDBC parameters. The parameter below is just an example, and it shouldn't be used in production without knowledge. It is highly recommended that you read the PostgreSQL JDBC driver documentation in order to use it.
#JDBC_PARAMS: "ssl=true"
ports:
- 8080:8080
depends_on:
- postgres
New docker-compose to import config:
version: '3.1'
services:
postgres:
image: postgres
container_name: postgres
environment:
POSTGRES_DB: keycloak
POSTGRES_USER: keycloak
POSTGRES_PASSWORD: ${KEYCLOAK_DB_PASS}
keycloak:
image: mihaibob/keycloak:14.0.0
volumes:
- ./realm-export.json:/tmp/realm-export.json
environment:
DB_VENDOR: POSTGRES
DB_ADDR: postgres
DB_DATABASE: keycloak
DB_USER: keycloak
DB_SCHEMA: public
DB_PASSWORD: ${KEYCLOAK_DB_PASS}
KEYCLOAK_USER: admin
KEYCLOAK_PASSWORD: ${KEYCLOAK_PASS}
KEYCLOAK_MIGRATION_ACTION: IMPORT
KEYCLOAK_IMPORT: /tmp/realm-export.json
# Uncomment the line below if you want to specify JDBC parameters. The parameter below is just an example, and it shouldn't be used in production without knowledge. It is highly recommended that you read the PostgreSQL JDBC driver documentation in order to use it.
#JDBC_PARAMS: "ssl=true"
ports:
- 9080:8080
depends_on:
- postgres
The Keycloak container terminates with the following logs:
OpenJDK Server VM warning: No monotonic clock was available - timed services may be adversely affected if the time-of-day clock changes
Added 'admin' to '/opt/jboss/keycloak/standalone/configuration/keycloak-add-user.json', restart server to load user
-b 0.0.0.0
=========================================================================
Using PostgreSQL database
=========================================================================
Grateful for every idea.
Try using absolute path for the volume mounting
I would suggest a better keycloak image vendor. I ended up, after using for sometime JBoss's one, by going with the quay version
here: https://www.keycloak.org/server/containers
It is straightforward to mount your volume that contains the json file of your realm and update the CMD with --import-realm option.
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
I'm using docker-compose and I'm trying to run an express app and postgres db in docker containers.
My problem is that it only starts postgres image, but express app is not running.
What am I doing wrong?
I've published it on my github: https://github.com/ayakymyshyn/docker-playground
looking at your docker-compose file and Dockerfile, i assume that your intention is that the web service in the compose will actually run the image produced by the Dockerfile.
if that is the case, you need to modify the compose file and tell it to build an image based on the Dockerfile.
it should look something like
version: "3.7"
services:
web:
image: node
build: . # <--- this is the missing line
depends_on:
- db
ports:
- '3001:3001'
db:
image: postgres
environment:
POSTGRES_PASSWORD: 123123123
POSTGRES_USER: yakym
POSTGRES_DB: jwt
volumes:
- ./pgdata:/var/lib/postgresql/data
ports:
- '5433:5433'
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 am having one web application which is running with couchdb database.
This coudb container has multiple databases from which web application need only one database.
I am using docker compose to run it but web application didn't recognize database inside couchdb container
by docker-compose.yml file as below
version: "2"
services:
db:
image: mysite/couch:latest
ports:
- "15984:5984"
environment:
DB_USER: admin
DB_PASSWORD: password
DB_NAME: db_new
webapp:
image: mysite/webapp:latest
ports:
- "3050:3000"
links:
- db
- db:db_new
If I run docker manually as mentioned below it works fine
docker run --rm -e DB_URL=http://localip:15984/db_new -p 0.0.0.0:3050:3000
Any Ideas what I am missing in docker-compose file?
After spending lots of time on docker-compose I got the solution as below
version: "2"
services:
db:
image: mysite/couch:latest
ports:
- "15984:5984"
webapp:
image: mysite/webapp:latest
ports:
- "3050:3000"
links:
- db
environment:
DB_URL: http://admin:password#db:5984/db_new