compose: Dockerfile parsing error when using mount flag

Description of the issue

Parsing the Dockerfile fails for the build command with “ERROR: Dockerfile parse error line …: Unknown flag: mount”, when using e.g. “RUN --mount=type=ssh” in the Dockerfile.

Context information (for bug reports)

  • DOCKER_BUILDKIT is enabled
  • docker build --ssh default ... works as expected Output of docker-compose version
docker-compose version 1.25.4, build 8d51620a
docker-py version: 4.1.0
CPython version: 3.7.5
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

Output of docker version

Client: Docker Engine - Community
 Version:           19.03.6
 API version:       1.40
 Go version:        go1.12.16
 Git commit:        369ce74a3c
 Built:             Thu Feb 13 01:27:59 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.6
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.16
  Git commit:       369ce74a3c
  Built:            Thu Feb 13 01:26:33 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.12
  GitCommit:        35bd7a5f69c13e1563af8a93431411cd9ecf5021
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Output of docker-compose config (Make sure to add the relevant -f and other flags)

services:
  service:
    build:
      context: /tmp
      dockerfile: d
    environment:
      DOCKER_BUILDKIT: '1'
    image: debian
version: '3.7'

Steps to reproduce the issue

cat <<EOF >Makefile
docker-build:
        DOCKER_BUILDKIT=1 docker -l debug build --no-cache --ssh default -t foo .
compose-build:
        DOCKER_BUILDKIT=1 docker-compose build --build-arg "'--ssh'=default"
EOF

Observed result

Build fails with “ERROR: Dockerfile parse error line …: Unknown flag: mount”

Expected result

Build should also work with docker-compose as it those with docker.

Stacktrace / full error message

DOCKER_BUILDKIT=1 docker-compose build --build-arg "'--ssh'=default"
Building service
ERROR: Dockerfile parse error line ...: Unknown flag: mount

Additional information

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 14
  • Comments: 23 (3 by maintainers)

Most upvoted comments

If you still have not solve this problem. Please remember to add # syntax=docker/dockerfile:experimental To the very beginning of your Dockerfile. I struggled for almost 2 hours before realizing this was my problem.

Yes, export COMPOSE_DOCKER_CLI_BUILD=1 and export DOCKER_BUILDKIT=1 resolve it.

Perhaps you forgot to set COMPOSE_DOCKER_CLI_BUILD=1?

Not to speak for OP, but I know for me the issue isn’t manual building. I have a build script that builds my images no sweat. The problem is delegating the build responsibility to docker-compose for the many host of reasons you’d want to do that in normal circumstances. Docker-compose can trigger builds, but in the circumstance of using the --ssh flag it cannot. That’s the crux of the friction as I see it.

You can alternatively try building with buildx , see here for more info. As it says : Buildx builds using the BuildKit engine and does not require DOCKER_BUILDKIT=1 environment variable to start the builds.

You can run below command to create buildx instance and give it a try if it works. See here for more information docker buildx create --use --name buildkit && docker buildx inspect

This seems like a big in docker-compose run?

Sounds like, due to the build being implicit in that case, the COMPOSE_DOCKER_CLI_BUILD=1 env-var is not taken into account yes.

@sj26 could you open a separate ticket for that? This thread has collected various comments that (at a glance) don’t look related to that case, so having a separate ticket to track that specific case would be better 👍

Yes, docker-compose build ... works fine:

$ COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build app     
WARNING: Native build is an experimental feature and could change at any time
Building app
[+] Building 3.9s (8/13)                                                                                                                                       
 => [internal] load .dockerignore                                                                                                                         0.0s
 => => transferring context: 2B                                                                                                                           0.0s
 => [internal] load build definition from Dockerfile                                                                                                      0.0s
 => => transferring dockerfile: 2.06kB                                                                                                                    0.0s
 => resolve image config for docker.io/docker/dockerfile:experimental                                                                                     2.5s
 => CACHED docker-image://docker.io/docker/dockerfile:experimental@sha256:de85b2f3a3e8a2f7fe48e8e84a65f6fdd5cd5183afa6412fff9caa6871649c44                0.0s
 => [internal] load metadata for docker.io/library/ruby:2.6.5                                                                                             0.0s
 => https://www.postgresql.org/media/keys/ACCC4CF8.asc                                                                                                    1.2s
 => [base 1/5] FROM docker.io/library/ruby:2.6.5                                                                                                          0.0s
 => https://deb.nodesource.com/gpgkey/nodesource.gpg.key                                                                                                  0.0s
 => https://dl.yarnpkg.com/debian/pubkey.gpg                                                                                                              0.1s

This seems like a big in docker-compose run?

I have the same problem as this ticket mentions. Adding COMPOSE_DOCKER_CLI_BUILD=1 and DOCKER_BUILDKIT=1 do indeed invoke the newer build engine, but do not resolve this issue for me.

I have the addition problem / question of how to express this build argument properly within the docker-compose.yml file? My compose file handles more than one image, and I don’t need the --ssh=default for all of them.