Dockerfile ARG Empty Value Error when Installing Dependencies

I’m facing an issue while trying to build a Docker image with a Dockerfile, and I’m getting an error that looks like this:

ERROR [2/8] RUN pip install 'numpy=='

The problem seems to be related to the use of an ARG, which appears to be empty. Here’s the relevant part of my Dockerfile:

# Use the official Python image as the base image
FROM python:3.8

# Define an ARG for the dependency version
ARG NUMPY_VERSION= 1.15.2

# Attempt to install numpy with the ARG
RUN pip install "numpy==${NUMPY_VERSION}"

I want to be able to specify the NUMPY_VERSION at build time, but it appears to be empty, causing this error. How can I correctly pass the NUMPY_VERSION as an argument when building the Docker image and make sure it’s not empty during the build process?

I google it for you using the search terms “docker build args”, first result is: https://docs.docker.com/build/guide/build-args/

I have read over the site before however I still couldn’t figure the solution for it.

The documentation that @meyay linked very clearly shows how to pass a build argument in the “Change runtime versions” section. Are you sure you read the page above and not something else?

I have, the problem is it is within quotations and for some reason it appears as empty when I run it and Docker recognizes it like this: RUN pip install 'numpy=='. I have not found an example in the doc where it shows how I can handle this scenario I guess.

I give you another chance since it is so obvious. Please, go to the end of the section I mentioned in my previous post. Of course it is not using the same variable but it is an example.

Hello @egeselcuk. I had a similar problem recently. While I was able to use the value of an ARG in the FROM declaration, other ARG variables were empty when I was trying to use them for RUN pip install. It turns out ARG are not visible below FROM so you could try something like:

ARG NUMPY_VERSION= 1.15.2
FROM python:3.8
ARG NUMPY_VERSION
RUN pip install “numpy==${NUMPY_VERSION}”

You can find more details here Dockerfile reference | Docker Docs . I hope this helps!

You are absolutely right, however the topic was not about that. I understand why you got confused, since the original question was changed one day after @meyay and I answered. The version number in the ARG instruction was added later and it was empty in the original question. So the goal was to set it from command line.

A build argument defined before the FROM instruction is not visible by default after that, because it is not part of the “stage”. An ARG before the FROM instruction is for setting something in the FROM instructions which you could not do with an ARG which is defined after it. It can also be used like a global variable, but as you discovered, you need to specifically state that you want that by defining the ARG again without overriding the value.

1 Like