dockershdocker-entrypointprovectuslabs-kafka-ui

How i can embed my script into the image kafka-ui


I took the Kafka UI image (provectuslabs/kafka-ui:v0.7.1): https://hub.docker.com/layers/provectuslabs/kafka-ui/master/images/sha256-633606ca07677d1c4b9405c5df1b6f0087aa75b36528a17eed142d06f65d0881?context=explore

I want to execute my script before starting Kafka UI, but I get the error script not found.

FROM provectuslabs/kafka-ui:v0.7.1

# Secret for swarm
USER root
COPY script.sh /script.sh
RUN chmod +x /script.sh

EXPOSE 8080

ENTRYPOINT ["/script.sh"]

CMD ["/bin/sh" "-c" "java --add-opens java.rmi/javax.rmi.ssl=ALL-UNNAMED  $JAVA_OPTS -jar kafka-ui-api.jar"]

Error: exec /script.sh: no such file or directory

I was able to do this trick with other images, for example with the image bitnami/kafka. But I can't figure out how to do it with this image provectuslabs/kafka-ui:v0.7.1.

ADDITION: I don't want to store secrets in docker compose files, so I use docker swarm secrets. They are stored in /run/secrets/... The secrets are stored in docker files, so I use the sh script to turn them into environment variables. Code link: https://github.com/swarm-pack/swarm-sync/blob/master/env_secrets_expand.sh

#!/bin/bash

env_secret_expand() {
    var="$1"
    eval val=\$$var
    if secret_name=$(expr match "$val" "DOCKER-SECRET->\([^}]\+\)$"); then
        secret="${ENV_SECRETS_DIR}/${secret_name}"
        env_secret_debug "Secret file for $var: $secret"
        if [ -f "$secret" ]; then
            val=$(cat "${secret}")
            export "$var"="$val"
            env_secret_debug "Expanded variable: $var=$val"
        else
            env_secret_debug "Secret file does not exist! $secret"
        fi
    fi
}

env_secrets_expand() {
    for env_var in $(printenv | cut -f1 -d"=")
    do
        env_secret_expand $env_var
    done
}

env_secrets_expand

In order to be able to execute the bash script, I added the line to the docker file:

RUN apk add --no-cache bash

In the logs I see that the bash script is running, but kafka-ui ignores these variables, instead using the templates that are specified in the docker compose:

  SPRING_SECURITY_USER_NAME: DOCKER-SECRET->kafka_ui_user
  SPRING_SECURITY_USER_PASSWORD: DOCKER-SECRET->kafka_ui_password

Solution

  • If I understand you correctly then you want to run script.sh and then proceed with the normal startup of the base image. Try this:

    FROM provectuslabs/kafka-ui:v0.7.1
    
    USER root
    
    COPY script.sh /script.sh
    
    RUN chmod +x /script.sh
    
    EXPOSE 8080
    
    CMD /script.sh && java --add-opens java.rmi/javax.rmi.ssl=ALL-UNNAMED -jar kafka-ui-api.jar
    

    In the screenshot below you can see the result of a simple script.sh that runs before the main Kafka UI job starts.

    #!/bin/sh
    
    echo "Hello, World!"
    

    enter image description here