2

I am trying to use docker-compose ARGs in multi-stage build context. My dockerfile looks like this:

ARG PHP_VERSION

FROM php:${PHP_VERSION}

ARG COMPOSER_VERSION

COPY --from=composer:${COMPOSER_VERSION} /usr/bin/composer /usr/bin/composer

The PHP_VERSION argument is working just fine. However, the COMPOSER_VERSION in the fourth line results in the following error:

ERROR: Service 'app' failed to build: invalid from flag value composer:${COMPOSER_VERSION}: invalid reference format.

Any help would be greatly appreciated.

1 Answer 1

4

Variable expansion is not supported in COPY --from. See this issue for more details. You can modify your Dockerfile to implement this by defining a stage that you late copy from:

ARG PHP_VERSION
ARG COMPOSER_VERSION

FROM composer:${COMPOSER_VERSION} as composer
FROM php:${PHP_VERSION}

COPY --from=composer /usr/bin/composer /usr/bin/composer
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.