cookie
cookie

Reputation: 2728

dockerfile parse error line 63: Unknown flag: link

terminal

COMPOSE_DOCKER_CLI_BUILD=1 COMPOSE_DOCKER_CLI_LINK=1 DOCKER_BUILDKIT=1 docker-compose up --build

Output

Successfully built fe4aa685d34a0cdeb29c4af824f2cfa7c11a6d036ee85ee19bd7615a518d80a9
Building php
[+] Building 0.8s (4/4) FINISHED                                                                                                                                      
 => [internal] load build definition from Dockerfile                                                                                                             0.0s
 => => transferring dockerfile: 38B                                                                                                                              0.0s
 => [internal] load .dockerignore                                                                                                                                0.1s
 => => transferring context: 35B                                                                                                                                 0.0s
 => resolve image config for docker.io/docker/dockerfile:experimental                                                                                            0.4s
 => CACHED docker-image://docker.io/docker/dockerfile:experimental@sha256:600e5c62eedff338b3f7a0850beb7c05866e0ef27b2d2e8c02aa468e78496ff5                       0.0s
failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = failed to create LLB definition: 

dockerfile parse error line 63: Unknown flag: link

Traceback (most recent call last):
  File "/usr/bin/docker-compose", line 11, in <module>
    load_entry_point('docker-compose==1.25.0', 'console_scripts', 'docker-compose')()
  File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 72, in main
    command()

Dockerfile

COPY --link docker/php/conf.d/app.ini $PHP_INI_DIR/conf.d/ # line 63

The docker service/containers are stock, found over at: https://api-platform.com/docs/distribution/

Upvotes: 10

Views: 11143

Answers (5)

Adnen Chouibi
Adnen Chouibi

Reputation: 416

According to the official Doc, you need to enable the BuildKit mode https://hub.docker.com/r/docker/dockerfile .

If you are using Docker v18.09 or later, BuildKit mode can be enabled by setting export DOCKER_BUILDKIT=1 on your terminal. You can also build with docker buildx build to use BuildKit mode.

To use the --link flag set Dockerfile version to at least 1.4.

# syntax=docker/dockerfile:1.4

Upvotes: 14

Hossein
Hossein

Reputation: 4539

You need to add below line to the top of your Dockerfile.

# syntax=docker/dockerfile:1.4

Upvotes: 0

BryceLarkin
BryceLarkin

Reputation: 504

You need to add # syntax=docker/dockerfile:1.4 to the top of your Dockerfile to enable the --link flag.

Source: https://www.docker.com/blog/image-rebase-and-improved-remote-cache-support-in-new-buildkit/

Upvotes: 3

khgasd652k
khgasd652k

Reputation: 301

I have same problem when building image with latest https://github.com/dunglas/symfony-docker template on my GitLab CI Pipeline. The weird thing is, everythings works normally on my local laptop with Ubuntu 22.04 and latest docker engine.

On my GitLab pipeline, turn out the problem is, both api-platform and symfony-docker template use Dockerfile:1.4 which contains --link parameters on COPY command.

There is two (2) ways to solve this:

  1. Remove every --link command from your Dockerfile. It will build the image with usual COPY and your image will worked normally.

  2. If you still want to use the default image with link, you need to add DOCKER_BUILDKIT=1 as environment variable. I use this method and update the docker:dind service to docker:20.10.21-dind and now my pipeline run well.

Upvotes: 11

cookie
cookie

Reputation: 2728

We have more success when removing the --link flags within Dockerfile.

#syntax=docker/dockerfile:experimental
# Adapted from https://github.com/dunglas/symfony-docker

# Prod image
FROM php:8.1-fpm-alpine AS app_php

ENV APP_ENV=prod

WORKDIR /srv/app

# persistent / runtime deps
RUN apk add --no-cache \
        acl \
        fcgi \
        file \
        gettext \
        git \
    ;

RUN set -eux; \
    apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        icu-data-full \
        icu-dev \
        libzip-dev \
        zlib-dev \
    ; \
    \
    docker-php-ext-configure zip; \
    docker-php-ext-install -j$(nproc) \
        intl \
        zip \
    ; \
    pecl install \
        apcu \
    ; \
    pecl clear-cache; \
    docker-php-ext-enable \
        apcu \
        opcache \
    ; \
    \
    runDeps="$( \
        scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
            | tr ',' '\n' \
            | sort -u \
            | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
    )"; \
    apk add --no-cache --virtual .app-phpexts-rundeps $runDeps; \
    \
    apk del .build-deps

###> recipes ###
###> doctrine/doctrine-bundle ###
RUN apk add --virtual .pgsql-deps postgresql-dev; \
    docker-php-ext-install -j$(nproc) pdo_pgsql; \
    apk add --no-cache --virtual .pgsql-rundeps so:libpq.so.5; \
    apk del .pgsql-deps
###< doctrine/doctrine-bundle ###
###< recipes ###

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY docker/php/conf.d/app.ini $PHP_INI_DIR/conf.d/
COPY docker/php/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/

COPY docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
RUN mkdir -p /var/run/php

COPY docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck

HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]

COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV PATH="${PATH}:/root/.composer/vendor/bin"

COPY --from=composer/composer:2-bin /composer /usr/bin/composer

# prevent the reinstallation of vendors at every changes in the source code
COPY composer.* symfony.* ./
RUN set -eux; \
    composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress; \
    composer clear-cache

# copy sources
COPY . .
RUN rm -Rf docker/

RUN set -eux; \
    mkdir -p var/cache var/log; \
    composer dump-autoload --classmap-authoritative --no-dev; \
    composer dump-env prod; \
    composer run-script --no-dev post-install-cmd; \
    chmod +x bin/console; sync

# Dev image
FROM app_php AS app_php_dev

ENV APP_ENV=dev XDEBUG_MODE=off
VOLUME /srv/app/var/

RUN rm $PHP_INI_DIR/conf.d/app.prod.ini; \
    mv "$PHP_INI_DIR/php.ini" "$PHP_INI_DIR/php.ini-production"; \
    mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

COPY docker/php/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/

RUN set -eux; \
    apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \
    pecl install xdebug; \
    docker-php-ext-enable xdebug; \
    apk del .build-deps

RUN rm -f .env.local.php

# Build Caddy with the Mercure and Vulcain modules
FROM caddy:2-builder-alpine AS app_caddy_builder

RUN xcaddy build \
    --with github.com/dunglas/mercure \
    --with github.com/dunglas/mercure/caddy \
    --with github.com/dunglas/vulcain \
    --with github.com/dunglas/vulcain/caddy

# Caddy image
FROM caddy:2-alpine AS app_caddy

WORKDIR /srv/app

COPY --from=app_caddy_builder /usr/bin/caddy /usr/bin/caddy
COPY --from=app_php /srv/app/public public/
COPY docker/caddy/Caddyfile /etc/caddy/Caddyfile

Source files: https://github.com/api-platform/api-platform/generate

The containers now spin up successfully but it's still not fully working, over at the browser:-

enter image description here

CONTAINER ID   IMAGE                        COMMAND                  CREATED         STATUS                            PORTS                                                                                                                           NAMES
d0bd06fe7289   fluffy-octo-broccoli_caddy   "caddy run --config …"   6 seconds ago   Up 4 seconds                      2019/tcp, 0.0.0.0:8123->80/tcp, :::8123->80/tcp, 0.0.0.0:444->443/tcp, 0.0.0.0:444->443/udp, :::444->443/tcp, :::444->443/udp

what's more interesting is the url appears to redirect from http://localhost:8123/api to https://localhost/api

enter image description here

Upvotes: 0

Related Questions