wwww
wwww

Reputation: 822

Changing default port of keycloak in docker

I have logged in to virtual machine in docker but I can't find standalone.sh It isn't in /bin. I don't know also how to write dockerfile which set -Djboss.socket.binding.port-offset=100

Upvotes: 11

Views: 24078

Answers (5)

cnichols
cnichols

Reputation: 1

If the container is already created.

  1. Stop the container
docker stop <container_name>
  1. Commit the container
docker commit keycloak keycloak2
  1. Rerun with new port
docker run -p 28080:28080 -td keycloak2 start-dev --http-port=28080

Upvotes: 0

Coderji
Coderji

Reputation: 7745

Using Keycloak 19+:

keycloak:
    image: quay.io/keycloak/keycloak:19.0.1
    environment:
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
    command: ["start-dev", "--http-port=8888"]

Upvotes: 8

suchita
suchita

Reputation: 56

This worked for me as in to change the default port of keycloak server through docker file. (keycloak runs on localhost:8100)

keycloak:
    build:
      context: ./keycloak
      dockerfile: ./Dockerfile
    environment:
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
      KEYCLOAK_DEFAULT_THEME: custom 
      KEYCLOAK_WELCOME_THEME: keycloak 
      DB_VENDOR: h2
    container_name: keycloak-container
    command: ["-Djboss.http.port=8100"]
    # Uncomment for development purpose
    # volumes:
    #   - ${PWD}/keycloak/theme/custom:/opt/jboss/keycloak/themes/custom
    ports:
      - 8100:8100

Upvotes: 2

Zhang Ran
Zhang Ran

Reputation: 316

Below is a sample docker-compose YAML file which shows you may set the offset in the command. Please kindly change according to your setting.

version: '2.1'
services:
  keycloak:
    image: jboss/keycloak:4.5.0.Final
    container_name: keycloak
    user: change_it
    hostname: change_it
    command: ["-Djboss.socket.binding.port-offset=0"]
    extra_hosts:
            - "change_it"
    environment:
      - KEYCLOAK_USER=change_it
      - KEYCLOAK_PASSWORD=change_it
    ports:
      - 8080:8080
      - 8443:8443

Upvotes: 5

Yuriy P
Yuriy P

Reputation: 1550

You can pass port as -Djboss.http.port parameter, for example:

 docker run --name keycloak -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -p 11111:11111 jboss/keycloak -Djboss.http.port=11111

Upvotes: 14

Related Questions