DEV Community

André Moriya
André Moriya

Posted on • Updated on

How to use the keycloak latest tag instead of the legancy tag, in your docker-compose.

Hi everyone.

Some time ago, and after a long time, I was trying to use again a new keycloak version.
But I've had some problem to start my container with this compose:

version: '3.8'
volumes:
  postgres_data:
    driver: local
  keycloak_data:
    driver: local
networks:
  local:
    name: localhost
    external: true
services:
  postgres:
    image: 'postgres:latest'
    networks:
      - local
    volumes:
      - 'postgres_data:/var/lib/postgresql/data'
    environment:
      POSTGRES_DB: keycloak
      POSTGRES_USER: keycloak
      POSTGRES_PASSWORD: password
  keycloak:
    image: 'quay.io/keycloak/keycloak:latest'
    networks:
      - local
    environment:
      DB_VENDOR: POSTGRES
      DB_ADDR: postgres
      DB_DATABASE: keycloak
      DB_USER: keycloak
      DB_SCHEMA: public
      DB_PASSWORD: password
      KEYCLOAK_USER: kc_user
      KEYCLOAK_PASSWORD: kc_pass
    ports:
      - '8000:8080'
    depends_on:
      - postgres
  pgadmin4:
    image: 'dpage/pgadmin4:latest'
    environment:
      PGADMIN_DEFAULT_EMAIL: andremoriya@gmail.com
      PGADMIN_DEFAULT_PASSWORD: admin123
    networks:
      - local
    depends_on:
      - postgres
    ports:
      - '6543:80'
Enter fullscreen mode Exit fullscreen mode

I just wanted to see if this compose worked, but when I ran docker-compose, I received the following error.

Attaching to keycloak-latest_keycloak_1
keycloak_1  | Keycloak - Open Source Identity and Access Management
keycloak_1  | 
keycloak_1  | Find more information at: https://www.keycloak.org/docs/latest
keycloak_1  | 
keycloak_1  | Usage:
keycloak_1  | 
keycloak_1  | kc.sh [OPTIONS] [COMMAND]
keycloak_1  | 
keycloak_1  | Use this command-line tool to manage your Keycloak cluster.
keycloak_1  | Make sure the command is available on your "PATH" or prefix it with "./" (e.g.:
keycloak_1  | "./kc.sh") to execute from the current folder.
keycloak_1  | 
keycloak_1  | Options:
keycloak_1  | 
keycloak_1  | -cf, --config-file 
keycloak_1  |                      Set the path to a configuration file. By default, configuration properties are
keycloak_1  |                        read from the "keycloak.conf" file in the "conf" directory.
keycloak_1  | -h, --help           This help message.
keycloak_1  | -v, --verbose        Print out error details when running this command.
keycloak_1  | -V, --version        Show version information
keycloak_1  | 
keycloak_1  | Commands:
keycloak_1  | 
keycloak_1  |   build                   Creates a new and optimized server image.
keycloak_1  |   start                   Start the server.
keycloak_1  |   start-dev               Start the server in development mode.
keycloak_1  |   export                  Export data from realms to a file or directory.
keycloak_1  |   import                  Import data from a directory or a file.
keycloak_1  |   show-config             Print out the current configuration.
keycloak_1  |   tools                   Utilities for use and interaction with the server.
keycloak_1  |     completion            Generate bash/zsh completion script for kc.sh.
keycloak_1  | 
keycloak_1  | Examples:
keycloak_1  | 
keycloak_1  |   Start the server in development mode for local development or testing:
keycloak_1  | 
keycloak_1  |       $ kc.sh start-dev
keycloak_1  | 
Enter fullscreen mode Exit fullscreen mode

Changing

So, in our compose, we must change and add a few simple configurations.

The admin environment variable in Keycloak has been changed from KEYCLOAK_USER and KEYCLOAK_PASSWORD to KEYCLOAK_ADMIN and KEYCLOAK_ADMIN_PASSWORD respectively.
And we must include the 'command: start-dev' in our compose.

After changing, our compose should look like this:

....
  keycloak:
    image: 'quay.io/keycloak/keycloak:latest'
    networks:
      - local
    environment:
      // new environment variables
      KC_DB: postgres
      KC_DB_URL: jdbc:postgresql://postgresqldb:5432/keycloak
      KC_DB_USERNAME: user
      KC_DB_PASSWORD: pass
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: admin123
    ports:
      - '8000:8080'
    command: start-dev // Added
    depends_on:
      - postgres
....
Enter fullscreen mode Exit fullscreen mode

After that, we can run again, and the console output should look like this.:

Attaching to keycloak-latest_keycloak_1keycloak_1  | Updating the configuration and installing your custom providers, if any. Please wait.Attaching to keycloak-latest_keycloak_1
keycloak_1  | 2022-08-02 15:02:59,158 INFO  [io.quarkus.deployment.QuarkusAugmentor] (main) Quarkus augmentation completed in 6757ms
keycloak_1  | 2022-08-02 15:03:02,504 INFO  [org.keycloak.quarkus.runtime.hostname.DefaultHostnameProvider] (main) Hostname settings: FrontEnd: , Strict HTTPS: false, Path: , Strict BackChannel: false, Admin: , Port: -1, Proxied: false
keycloak_1  | 2022-08-02 15:03:03,351 WARN  [org.infinispan.PERSISTENCE] (keycloak-cache-init) ISPN000554: jboss-marshalling is deprecated and planned for removal
keycloak_1  | 2022-08-02 15:03:03,469 WARN  [org.infinispan.CONFIG] (keycloak-cache-init) ISPN000569: Unable to persist Infinispan internal caches as no global state enabled
keycloak_1  | 2022-08-02 15:03:03,514 INFO  [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000556: Starting user marshaller 'org.infinispan.jboss.marshalling.core.JBossUserMarshaller'
keycloak_1  | 2022-08-02 15:03:03,752 INFO  [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000128: Infinispan version: Infinispan 'Triskaidekaphobia' 13.0.9.Final
keycloak_1  | 2022-08-02 15:03:04,200 INFO  [org.keycloak.connections.infinispan.DefaultInfinispanConnectionProviderFactory] (main) Node name: node_357415, Site name: null
keycloak_1  | 2022-08-02 15:03:05,672 INFO  [org.keycloak.quarkus.runtime.storage.database.liquibase.QuarkusJpaUpdaterProvider] (main) Initializing database schema. Using changelog META-INF/jpa-changelog-master.xml
keycloak_1  | 2022-08-02 15:03:08,125 INFO  [org.keycloak.services] (main) KC-SERVICES0050: Initializing master realm
keycloak_1  | 2022-08-02 15:03:10,137 INFO  [org.keycloak.services] (main) KC-SERVICES0009: Added user 'admin' to realm 'master'
keycloak_1  | 2022-08-02 15:03:10,279 INFO  [io.quarkus] (main) Keycloak 18.0.2 on JVM (powered by Quarkus 2.7.5.Final) started in 10.932s. Listening on: http://0.0.0.0:8080
keycloak_1  | 2022-08-02 15:03:10,280 INFO  [io.quarkus] (main) Profile dev activated. 
keycloak_1  | 2022-08-02 15:03:10,280 INFO  [io.quarkus] (main) Installed features: [agroal, cdi, hibernate-orm, jdbc-h2, jdbc-mariadb, jdbc-mssql, jdbc-mysql, jdbc-oracle, jdbc-postgresql, keycloak, narayana-jta, reactive-routes, resteasy, resteasy-jackson, smallrye-context-propagation, smallrye-health, smallrye-metrics, vault, vertx]
keycloak_1  | 2022-08-02 15:03:10,287 WARN  [org.keycloak.quarkus.runtime.KeycloakMain] (main) Running the server in development mode. DO NOT use this configuration in production.
Enter fullscreen mode Exit fullscreen mode

And using the web browser, we can see this page:

Image description

Conclusion

That's it.

That's something I've recently discovered.

If you have any suggestions for how I can improve this post, please let me know. Please leave a comment if you have any suggestions or criticism.

See you!

Top comments (2)

Collapse
 
fatehmohamed14 profile image
Fateh Mohamed 🐢

Thanks saved me

Collapse
 
andremoriya profile image
André Moriya

Happy to help you :D