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
.
DOCKER_BUILDKIT
is enableddocker build --ssh default ...
works as expecteddocker-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'
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
Build fails with "ERROR: Dockerfile parse error line ...: Unknown flag: mount"
Build should also work with docker-compose
as it those with docker
.
DOCKER_BUILDKIT=1 docker-compose build --build-arg "'--ssh'=default"
Building service
ERROR: Dockerfile parse error line ...: Unknown flag: mount
Perhaps you forgot to set COMPOSE_DOCKER_CLI_BUILD=1
?
Yes, export COMPOSE_DOCKER_CLI_BUILD=1
and export DOCKER_BUILDKIT=1
resolve it.
@grafoo
Did the above fix work? If not, r u still getting the same error?
Also this is not necessarily a bug?
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.
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
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.
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.
I have a Dockerfile which works great with DOCKER_BUILDKIT=1 docker build -t app .
, and am using docker-compose 1.26.2, yet COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose run app
fails with a ERROR: Dockerfile parse error line ...: Unknown flag: mount
when using a cache mount.
$ docker version
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.40
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:41:33 2020
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.12
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:49:27 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
$ docker-compose version
docker-compose version 1.26.2, build eefe0d31
docker-py version: 4.2.2
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.1g 21 Apr 2020
@sj26 What does your Dockerfile look like?
Here's a reproducing case:
https://gist.github.com/sj26/5c403481267a455dede515906ca0462c
$ COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose run app true
Building app
ERROR: Dockerfile parse error line 9: Unknown flag: mount
Works fine here.
@sj26 does it work if you manually run docker-compose build
? Wondering if the env-vars are somehow ignored in the docker-compose run
case
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?
Yeah, sorry, it does give me an error when doing docker-compose run
directly.
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 馃憤
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1
It works for me :)
Seems to work as expected with current docker-compose 1.27.4 (both docker-compose run
and docker-compose build
).
Pro-tip: never, never forget to put in your Dockerfile the header
# syntax = docker/dockerfile:experimental
or you will loose some hours of your life like I just did
I'm able to run the build with the environment variables set, but I cannot seem to map --build-arg "'--ssh'='name=/path/to/key'" successfully. The equivalent
docker buildcommand I'm trying to match is
docker build --ssh name=/path/to/key .. Is the above syntax incorrect? How do you pass the
--sshvalue to the
docker-compose build` command?
Most helpful comment
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.