Softwareโฑ๏ธ 2 min read๐Ÿ“… 2026-05-31

How to Fix: ARG substitution in RUN command not working for Dockerfile

ARG substitution not working for Dockerfile, Docker build arguement, Docker run command

Quick Answer: The issue is caused by the order of arguments in the RUN command. Try rearranging them to use the substituted value first.

The issue you're facing is due to the fact that Docker doesn't support ARG substitution in RUN commands. This is because the RUN command executes immediately when building the image, and the ARG values are not available until the build process is complete.

๐Ÿš€ How to Resolve This Issue

Method 1: Use a separate RUN command for ARG substitution

  1. Step 1: Create a separate RUN command that uses the ARG value.

Example:

ARG a-version RUN wget -q -O /tmp/alle.tar.gz http://someserver/server/$a-version/a-server-$a-version.tar.gz && \ mkdir /opt/apps/$a-version

๐Ÿ’ก Conclusion

By using a separate RUN command, you can ensure that the ARG values are substituted correctly. This is the recommended approach when working with ARG substitution in Dockerfiles.

Did this fix your problem?

If not, try searching for specific error codes.

๐Ÿ” Search Error Database

โ“ Frequently Asked Questions