Build args doesn't work
Fazendaaa opened this issue · 6 comments
Expected Behavior
I have a scenario similar to the following:
version: '3'
services:
myservice:
build:
context: .
dockerfile: Dockerfile.alpine
args:
- MY_VAR=$MY_VAR
When I try to run through the recommended docker-compose installation, he can't build because he doesn't find MY_VAR.
Current Behavior
It says he can't find MY_VAR and ends up leaving it with an 'empty' value, I had to install the docker-compose in order to run the project through the build.
Environment
OS: 5.8.16-2-MANJARO
CPU architecture: x86_64
How docker service was installed: through the recommended method
Command used to create docker container (run/create/compose/screenshot)
Behavior presented in both:
docker-compose up --build
docker-compose build
1. Why are you building locally? Just pull the images we we push to docker hub, github or gitlab, or retrieve the binaries from our github releases
2. If you really want to do it, build via docker cli, you don't need compose to build it.
3. Don't use a variable to set your variable in your compose yaml because clearly your original variable isn't set properly? Just set your variable as - MY_VAR=blahblah
Closing as this is not a bug
Looks like I misunderstood. So you're using this container to build a different image and having issues with the var not set?
Your original var $MY_VAR
is set on host, but compose is running inside a container, which is a sandboxed environment. Everything compose needs to use/access, has to be somehow injected into the container. We accomplish that via mapping the folder the compose file is in, and mapping docker.sock. However, we don't inject vars that are set on host, that's why your compose thinks the var is unset.
I don't have a good solution off the top of my head, but will deliberate with other team members and will post back here
How/where are you defining or supplying $MY_VAR
?
$MY_VAR is defined in my
.zshrc
file, @nemchik
Try instead setting COMPOSE_OPTIONS="-e MY_VAR=MY_VAL"
Or create a .env
file and set anything you need there and then set COMPOSE_OPTIONS="--env-file /path/to/.env"
Edit: these are applied here
Line 80 in 68969e4
COMPOSE_OPTIONS
is the right one to use for this purpose.This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.