Dockerfile Args is not working

I’m having two problems using Dockerfile args. First problem is ARGs in Dockerfile are not getting overridden. Second problem is the service instance fails to start.

My Docker file has:

ARG FOO=banana
RUN echo $FOO > ./foo.txt

In the Build and deployment settings, I override Args and set with:

["FOO=apple"]

In the build logs, FOO is not overridden:

#13 [7/8] RUN echo banana > ./foo.txt
#13 DONE 0.1s

Additionally, the service will fail to start. The Runtime logs don’t say what is failing; it just fails.

If I remove the FOO override, then service instance will build and start just fine.

Hi @Scott_Feldman

Can you describe how are you trying to set the FOO value from your service configuration?

The way to go is to define an environment variable to override the ARG variable value.
Adding the environment variable FOO with the value APPLE should work with the example you provided.

Hi @edouard,

I’m setting FOO here:

Alright, thanks! This field is used to provide the arguments to pass to the Docker command.

To override the FOO ARG, setting up an environment variable with FOO as the name and APPLE as the value should work.

I’m not trying to pass FOO as a runtime env var.

I want to pass args to the Docker command, as if I typed:

docker build --build-arg FOO=apple -t my_image .

And in the Dockerfile:

ARG FOO=banana
RUN echo $FOO > ./foo.txt

I just tried again putting [“FOO=apple”] in the ARgs override, and runtime fails:

The env var will be provided at build time also.

We lack documentation on that but have an initiative to better cover this topic.

You can check out the following post, there is an example showcasing how to override ARGs: Dockerfile Deployment on High-Performance MicroVMs is GA - Koyeb.

Regarding your current configuration:

  1. remove the args override
  2. add an env var FOO=apple

And everything should work as expected.

Ok, putting FOO in env var works!

So what is this Args field for?

Screenshot 2023-10-10 2.02.50 PM

And why does my service fail to start when I put something in there?

Hey!

I’m sorry you had to struggle with this, we need to make the widget more obvious.

As @edouard explained, the environment variables are set both as runtime environment variables (docker run -e ...) and as build arguments (docker build --build-arg ...).

Regarding the other settings:

  • Command is a string, which corresponds to the first entry of a Dockerfile’s CMD
  • Args is an array of strings containing the following entries of CMD.

So, for a Dockerfile with CMD ["nginx", "-g", "daemon off;"], you would need to set Command to nginx, and Args to ["-g", "daemon off;"].

Ok, thanks for the explanations.

Minimally, you should probably change “Args” to “Command Args”, so people don’t think it’s a substitute for --build-arg.

Also, failing the build when Args is non-empty, without any notification is kind of rough. Need better diagnostics when Command/Args are malformed.

Thanks guys.

1 Like