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 enableddocker build --ssh default ...
works as expected Output ofdocker-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
- 9.12 / debian
- installed using “https://github.com/docker/compose/releases/download/1.25.4/docker-compose-Linux-x86_64”
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 14
- Comments: 23 (3 by maintainers)
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
andexport 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
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:This seems like a big in docker-compose run?
I have the same problem as this ticket mentions. Adding
COMPOSE_DOCKER_CLI_BUILD=1
andDOCKER_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.