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.
PS this is a test db and a dev container so I don't care if I expose any passwords.
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.