Docker Community Forums

Share and learn in the Docker community.

How to resolve error calling index: index of untyped nil?

I’m getting an error when trying to parse an expression of a keycloak test that I’ve found on github.
The exception occurs when executing this method:

 function inspectDockerPortMapping() {
local PORT="$1"
local CONTAINER="$2"
local INSPECT_COMMAND="docker inspect --format='{{(index (index .NetworkSettings.Ports \"$PORT\") 0).HostPort}}' $CONTAINER"
MAPPED_PORT="$( eval "$INSPECT_COMMAND" )"
if [ -z "$MAPPED_PORT" ]; then 
    echo "Error finding mapped port for $CONTAINER."
    exit 1
fi

}

And here is my docker-compose.yml file:

version: "2.2"
networks:
      keycloak:
          ipam:
              config:
              - subnet: 10.0.1.0/24

services:

mariadb:
    build: 
        context: db/mariadb
        args:
            MAX_CONNECTIONS: ${DB_MAX_CONNECTIONS:-100}
    image: keycloak_test_mariadb:${KEYCLOAK_VERSION:-latest}
    cpuset: ${DB_CPUSET:-1}
    mem_limit: ${DB_MEMLIMIT:-2g}
    networks:
        - keycloak
    environment:
        MYSQL_ROOT_PASSWORD: root
        MYSQL_DATABASE: keycloak
        MYSQL_USER: keycloak
        MYSQL_PASSWORD: keycloak
        MYSQL_INITDB_SKIP_TZINFO: 1
    ports:
        - "3306:3306"

keycloak:
    build: keycloak
    image: keycloak_test_keycloak:${KEYCLOAK_VERSION:-latest}
    depends_on:
        mariadb:
            condition: service_healthy
    cpuset: ${KEYCLOAK_CPUSET:-2-3}
    mem_limit: ${KEYCLOAK_MEMLIMIT:-2500m}
    networks:
        - keycloak
    environment:
        MARIADB_HOSTS: mariadb:3306
        MARIADB_DATABASE: keycloak
        MARIADB_USER: keycloak
        MARIADB_PASSWORD: keycloak
        KEYCLOAK_ADMIN_USER: ${KEYCLOAK_ADMIN_USER:-admin}
        KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD:-admin}
        # docker-compose syntax note: ${ENV_VAR:-<DEFAULT_VALUE>}
        JAVA_OPTS: ${KEYCLOAK_JVM_MEMORY:--Xms64m -Xmx2g -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m} -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true
        HTTP_MAX_CONNECTIONS: ${KEYCLOAK_HTTP_MAX_CONNECTIONS:-50000}
        WORKER_IO_THREADS: ${KEYCLOAK_WORKER_IO_THREADS:-2}
        WORKER_TASK_MAX_THREADS: ${KEYCLOAK_WORKER_TASK_MAX_THREADS:-16}
        DS_MIN_POOL_SIZE: ${KEYCLOAK_DS_MIN_POOL_SIZE:-10}
        DS_MAX_POOL_SIZE: ${KEYCLOAK_DS_MAX_POOL_SIZE:-100}
        DS_POOL_PREFILL: "${KEYCLOAK_DS_POOL_PREFILL:-true}"
        DS_PS_CACHE_SIZE: ${KEYCLOAK_DS_PS_CACHE_SIZE:-100}
        JSTAT: "${KEYCLOAK_JSTAT:-false}"
    ports:
        - "8080:8080"
        - "9990:990"

The problem is that mariadb container starts correctly but the keycloak container does not.
Any suggestions?