Hi There,
I’m using Keycloak for the first time and I’m facing some problems using it in a docker-compose environment.
I create the following docker-compose file
version: '3.4'
services:
postgresql:
container_name: postgresql
image: bitnami/postgresql:12.11.0
volumes:
- C:\Docker_files\postgresql:/bitnami/postgresql
ports:
- "5432:5432"
environment:
- POSTGRESQL_USERNAME=admin
- POSTGRESQL_PASSWORD=admin
- POSTGRESQL_DATABASE=keycloak
networks:
- onestore_network
keycloak:
container_name: KeyCloak
image: bitnami/keycloak:18.0.0
ports:
- "8080:8080"
environment:
- KEYCLOAK_DATABASE_HOST=postgresql
- KEYCLOAK_DATABASE_PORT=5432
- KEYCLOAK_DATABASE_NAME=keycloak
- KEYCLOAK_DATABASE_USER=admin
- KEYCLOAK_DATABASE_PASSWORD=admin
- KEYCLOAK_CREATE_ADMIN_USER=true
- KEYCLOAK_ADMIN_USER=admin
- KEYCLOAK_ADMIN_PASSWORD=admin
depends_on:
- postgresql
hostname: keycloak
networks:
- onestore_network
MyWebApp:
container_name: MyWebApp
environment:
- TZ=Europe/Rome
- ASPNETCORE_ENVIRONMENT=dev
- ASPNETCORE_URLS=https://+:3002;http://+:3001
image: ${DOCKER_REGISTRY-}mywebapp
build:
context: .
dockerfile: MyWebApp/Dockerfile
ports:
- "3001:3001"
- "3002:3002"
volumes:
- C:\Docker_files\logs\MyWebApp:/data/logs
depends_on:
- keycloak
hostname: mywebapp
networks:
- onestore_network
networks:
onestore_network:
driver: bridge
name: onestore_network
and I am not able to authenticate using keycloak.
I think the problem is in the auth-server-url, which is set to localhost:8080, as you can see below
{
"realm": "docker_one_store",
"auth-server-url": "http://localhost:8080/",
"ssl-required": "external",
"resource": "mywebapp",
"credentials": {
"secret": "V8IXKkwofEFZzaebNLabZjYnWn5QSMQe"
},
"confidential-port": 0
}
but from inside che container I need to use the contaner name (keycloak) instead of localhost.
If i connect to Keycloak from an app outside the container it works fine, so the realm configuration seems ok.
Can you help me solving this problem?
Thanks a lot