0

I have Java-Spring-Maven project, which builds a docker image. I define "DATABASE_USER" variable.

My docker-compose.yml:

. . . 

my-service:
    build: my-service/
      context: .
      args:
        - DATABASE_USER=${DBUSR}
    container_name: my-service
    command: java -jar -Xms256M -Xmx1g
      -Dfile.encoding=UTF-8

 . . . . . . 
 
    environment:
      - DATABASE_USER=${DBUSR}

 . . . . . . 

In my dockerfile a have commands:

ARG DATABASE_USER

RUN ....

I want to pass the DATABASE_USER variable from docker-compose.yml to the RUN command in dockerfile.

The problem is that my variable DATABASE_USER is empty. I tried ENV DATABASE_USER, ARG DATABASE_USER=$DATABASE_USER and many other combinations. What is wrong? What is my mistake?

Thank you!

I tried ENV DATABASE_USER, ARG DATABASE_USER=$DATABASE_USER and many other combinations.

  • Does this answer your question? [How to pass arguments to a Dockerfile?](https://stackoverflow.com/questions/34254200/how-to-pass-arguments-to-a-dockerfile) – AymDev Nov 29 '22 at 15:16
  • This one will also help you: [How to define build-args in docker-compose?](https://stackoverflow.com/questions/50734271/how-to-define-build-args-in-docker-compose) – AymDev Nov 29 '22 at 15:17

0 Answers0