Build args not passing from docker-compoes.yml to Dockerfile

Viewed 59

My docker-compose.yml:

version: "3.8"

services:
  web:
    build:
      context: .
      args:
        file_url: 'some-url'

My Dockerfile:

FROM ruby:2.7.4-bullseye

ARG file_url

RUN curl $file_url -L -o "file"

When I run:

docker-compose up --build

I expect Docker'd build and start my containers. But instead, I got:

Step 4/12 : RUN curl $file_url -L -o "file"
 ---> Running in 59696c6274c7
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information

So obviously the build args are not passing to Dockerfile. I've read a lot of similar threads on Stackoverflow but couldn't figure out what went wrong.

One more thing. I can actually build the containers with docker-compose build web just fine. It's just when I run docker-compose up --build or docker-compose up the error occurred.

1 Answers

The variable is not passed correctly in your dockerfile. see this for variable calls inside dockerfile: https://docs.docker.com/engine/reference/builder/

Ideally it's contained inside ${variable_name} . this line RUN curl $file_url -L -o "file needs rectification.

In your Dockerfile change $file_url to ${file_url}

Related