Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Makefile not passing env variables to docker compose command

I am trying to build a docker container using a makefile:

up_build_dev:
    @echo "Stopping docker images (if running...)"
     docker-compose down
    @echo "Building (when required) and starting docker images..."
     DB_USER=backend DB_PASSWORD=password DB_ROOT_USER=root DB_ROOT_PASSWORD=password DB_NAME=my_db DB_PORT=3306 DB_HOST=mysql LISTEN_PORT=80 HOST_PORT=8080 ENV=dev docker-compose up --build -d
    @echo "Docker images built and started!"

The environment variables are not passed, however, when I run this compose command in my terminal without make it works just fine.

I tried using export and env keywords but it didn’t work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

PS this is a test db and a dev container so I don’t care if I expose any passwords.

>Solution :

Have you tried export with a semicolon after the last var is set?

In your example, add ‘export’ before ‘DB_USER=backend’ and add a semicolon after ‘ENV=dev’ as I’ve shown below.

I may be mistaken but this should do the trick.

up_build_dev:
@echo "Stopping docker images (if running...)"
 docker-compose down
@echo "Building (when required) and starting docker images..."
 export DB_USER=backend DB_PASSWORD=password DB_ROOT_USER=root DB_ROOT_PASSWORD=password DB_NAME=my_db DB_PORT=3306 DB_HOST=mysql LISTEN_PORT=80 HOST_PORT=8080 ENV=dev; docker-compose up --build -d
@echo "Docker images built and started!"

*edited to change quote to code block.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading