moby / buildkit

concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
https://github.com/moby/moby/issues/34227
Apache License 2.0
8.21k stars 1.16k forks source link

The heredoc syntax is not being recognized. #4967

Closed fantab01 closed 5 months ago

fantab01 commented 5 months ago

This issue is driving me crazy. I am working on wsl2 on windows and my docker version is: Docker version 26.1.3, build b72abbb and I've tried the following:

# syntax=docker/dockerfile:1
FROM ubuntu:22.04
RUN <<EOF
apt-get update
EOF
# syntax=docker/dockerfile:1.3-labs
......
docker build -t test:v1 .
docker buildx build -t test:v1 .
DOCKER_BUILDKIT=1 docker build -t test:v1 .

None of these work at all. they all result in the same error: "unknown instruction"

fantab01@DESKTOP-34H8QC1:~/src/habo/test$ docker buildx build -t test:v1 .
[+] Building 15.9s (4/4) FINISHED                                                              docker:default
 => [internal] load build definition from dockerfile                                                     0.0s
 => => transferring dockerfile: 116B                                                                     0.0s
 => resolve image config for docker-image://docker.io/docker/dockerfile:1                               15.7s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed0  0.0s
 => [internal] load .dockerignore                                                                        0.0s
 => => transferring context: 2B                                                                          0.0s
dockerfile:4
--------------------
   2 |     FROM ubuntu:22.04
   3 |     RUN <<EOF
   4 | >>> apt-get update
   5 |     EOF
--------------------
ERROR: failed to solve: dockerfile parse error on line 4: unknown instruction: apt-get

I really can't find where the problem is. Please help me.

tonistiigi commented 5 months ago

Maybe it is related to https://github.com/moby/buildkit/issues/4282 somehow

The Dockerfile you pasted here seems to work fine

» docker buildx build . 
[+] Building 14.1s (9/9) FINISHED                                                                                docker:default
 => [internal] load build definition from Dockerfile                                                                        0.1s
 => => transferring dockerfile: 113B                                                                                        0.0s
 => resolve image config for docker.io/docker/dockerfile:1                                                                  0.0s
 => CACHED docker-image://docker.io/docker/dockerfile:1                                                                     0.0s
 => [internal] load metadata for docker.io/library/ubuntu:22.04                                                             1.6s
 => [auth] library/ubuntu:pull token for registry-1.docker.io                                                               0.0s
 => [internal] load .dockerignore                                                                                           0.1s
 => => transferring context: 2B                                                                                             0.0s
 => [1/2] FROM docker.io/library/ubuntu:22.04@sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2       2.0s
 => => resolve docker.io/library/ubuntu:22.04@sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2       0.0s
 => => sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2 1.13kB / 1.13kB                              0.0s
 => => sha256:462e829de9164b6c066246cddc265a936071744f689f0ea73daa92b4f9feb47e 424B / 424B                                  0.0s
 => => sha256:7423357ed609f13ba90313f43454dc3026afb26476e14cb8b1dbb3eadb8a192c 2.31kB / 2.31kB                              0.0s
 => => sha256:d5a2ad729c09fbfdb259ae764f92188efc67a615ffde9bb34a46298d1edf3cd6 27.36MB / 27.36MB                            1.0s
 => => extracting sha256:d5a2ad729c09fbfdb259ae764f92188efc67a615ffde9bb34a46298d1edf3cd6                                   0.9s
 => [2/2] RUN <<EOF (apt-get update)                                                                                       10.0s
 => exporting to image                                                                                                      0.1s
 => => exporting layers                                                                                                     0.1s
 => => writing image sha256:9d9be5c6d3b7a899d43228f370fd6cb4723253f4d603df2e5c2e8debf94230cc                                0.0s
fantab01 commented 5 months ago

Maybe it is related to #4282 somehow

The Dockerfile you pasted here seems to work fine

» docker buildx build . 
[+] Building 14.1s (9/9) FINISHED                                                                                docker:default
 => [internal] load build definition from Dockerfile                                                                        0.1s
 => => transferring dockerfile: 113B                                                                                        0.0s
 => resolve image config for docker.io/docker/dockerfile:1                                                                  0.0s
 => CACHED docker-image://docker.io/docker/dockerfile:1                                                                     0.0s
 => [internal] load metadata for docker.io/library/ubuntu:22.04                                                             1.6s
 => [auth] library/ubuntu:pull token for registry-1.docker.io                                                               0.0s
 => [internal] load .dockerignore                                                                                           0.1s
 => => transferring context: 2B                                                                                             0.0s
 => [1/2] FROM docker.io/library/ubuntu:22.04@sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2       2.0s
 => => resolve docker.io/library/ubuntu:22.04@sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2       0.0s
 => => sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2 1.13kB / 1.13kB                              0.0s
 => => sha256:462e829de9164b6c066246cddc265a936071744f689f0ea73daa92b4f9feb47e 424B / 424B                                  0.0s
 => => sha256:7423357ed609f13ba90313f43454dc3026afb26476e14cb8b1dbb3eadb8a192c 2.31kB / 2.31kB                              0.0s
 => => sha256:d5a2ad729c09fbfdb259ae764f92188efc67a615ffde9bb34a46298d1edf3cd6 27.36MB / 27.36MB                            1.0s
 => => extracting sha256:d5a2ad729c09fbfdb259ae764f92188efc67a615ffde9bb34a46298d1edf3cd6                                   0.9s
 => [2/2] RUN <<EOF (apt-get update)                                                                                       10.0s
 => exporting to image                                                                                                      0.1s
 => => exporting layers                                                                                                     0.1s
 => => writing image sha256:9d9be5c6d3b7a899d43228f370fd6cb4723253f4d603df2e5c2e8debf94230cc                                0.0s

fantab01@DESKTOP-34H8QC1:~/src/habo/test$ cat Dockerfile| base64 IyBzeW50YXg9ZG9ja2VyL2RvY2tlcmZpbGU6MQpGUk9NIHVidW50dToyMi4wNApSVU4gPDxFT0YK YXB0LWdldCB1cGRhdGUKRU9GCg==

Hi, I tried checking the base64 output and didn't find any line breaks. Is there any way to help me locate the issue? I'm a beginner.

tonistiigi commented 5 months ago
» echo IyBzeW50YXg9ZG9ja2VyL2RvY2tlcmZpbGU6MQpGUk9NIHVidW50dToyMi4wNApSVU4gPDxFT0YKYXB0LWdldCB1cGRhdGUKRU9GCg== | base64 -d | docker buildx build -
[+] Building 12.9s (9/9) FINISHED                                                                                  remote:...
 => [internal] load build definition from Dockerfile                                                                        0.1s
 => => transferring dockerfile: 113B                                                                                        0.0s
 => resolve image config for docker-image://docker.io/docker/dockerfile:1                                                   1.0s
 => [auth] docker/dockerfile:pull token for registry-1.docker.io                                                            0.0s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:a57df69d0ea827fb7266491f2813635de6f17269be881f696fbfdf2d83d  0.0s
 => => resolve docker.io/docker/dockerfile:1@sha256:a57df69d0ea827fb7266491f2813635de6f17269be881f696fbfdf2d83dda33e        0.0s
 => [internal] load metadata for docker.io/library/ubuntu:22.04                                                             1.2s
 => [auth] library/ubuntu:pull token for registry-1.docker.io                                                               0.0s
 => [internal] load .dockerignore                                                                                           0.1s
 => => transferring context: 2B                                                                                             0.0s
 => [1/2] FROM docker.io/library/ubuntu:22.04@sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2       2.7s
 => => resolve docker.io/library/ubuntu:22.04@sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2       0.0s
 => => sha256:d5a2ad729c09fbfdb259ae764f92188efc67a615ffde9bb34a46298d1edf3cd6 27.36MB / 27.36MB                            2.0s
 => => extracting sha256:d5a2ad729c09fbfdb259ae764f92188efc67a615ffde9bb34a46298d1edf3cd6                                   0.7s
 => [2/2] RUN <<EOF (apt-get update)
fantab01 commented 5 months ago
> echo IyBzeW50YXg9ZG9ja2VyL2RvY2tlcmZpbGU6MQpGUk9NIHVidW50dToyMi4wNApSVU4gPDxFT0YKYXB0LWdldCB1cGRhdGUKRU9GCg== | base64 -d | docker buildx build -

fantab01@DESKTOP-34H8QC1:~/src/habo/test$ echo IyBzeW50YXg9ZG9ja2VyL2RvY2tlcmZpbGU6MQpGUk9NIHVidW50dToyMi4wNApSVU4gPDxFT0YKYXB0LWdldCB1cGRhdGUKRU9GCg== | base64 -d | docker buildx build -
[+] Building 15.8s (4/4) FINISHED                                                              docker:default
 => [internal] load build definition from Dockerfile                                                     0.0s
 => => transferring dockerfile: 113B                                                                     0.0s
 => resolve image config for docker-image://docker.io/docker/dockerfile:1                               15.5s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed0  0.0s
 => [internal] load .dockerignore                                                                        0.0s
 => => transferring context: 2B                                                                          0.0s
Dockerfile:4
--------------------
   2 |     FROM ubuntu:22.04
   3 |     RUN <<EOF
   4 | >>> apt-get update
   5 |     EOF
   6 |
--------------------
ERROR: failed to solve: dockerfile parse error on line 4: unknown instruction: apt-get

Sigh, the problem still persists 😭 Here is some additional info. and btw, If I remove the heredoc syntax from the Dockerfile, the build process works without any issues.

# syntax=docker/dockerfile:1
FROM ubuntu:22.04
RUN apt-get update
fantab01@DESKTOP-34H8QC1:~/src/habo/test$ docker info
Client: Docker Engine - Community
 Version:    26.1.3
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 5
 Server Version: 26.1.3
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e377cd56a71523140ca6ae87e30244719194a521
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.146.1-microsoft-standard-WSL2
 Operating System: Ubuntu 22.04.4 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.704GiB
 Name: DESKTOP-34H8QC1
 ID: fe611766-ca4f-43a8-95d4-9c4c65788321
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://rzqsts79.mirror.aliyuncs.com/
  https://docker.nju.edu.cn/
 Live Restore Enabled: false
tonistiigi commented 5 months ago

What is this sha256:42399d4635eddd7a9b8a... image of docker/dockerfile:1 ? The output is clipped so I can't see full digest, but it doesn't match any architecture of the current docker/dockerfile:1 in Docker Hub.

fantab01 commented 5 months ago

What is this sha256:42399d4635eddd7a9b8a... image of docker/dockerfile:1 ? The output is clipped so I can't see full digest, but it doesn't match any architecture of the current docker/dockerfile:1 in Docker Hub.

Thank you so much, you really have a keen eye. As is well known, China has some unique network characteristics, and indeed the problem was with the network: I was using the Docker Hub mirror site, but I didn't expect that even the big company's mirror site wasn't fully updated. I manually pulled dockerfile:1 just now and found out it was actually an image from two years ago. I switched to another reverse proxy mirror site, pulled dockerfile:1 again, and rebuilt it, and everything went smoothly. Thanks again 🙏🙏

thaJeztah commented 5 months ago

I had another report recently that also failed on heredoc, and that was also using that mirror; https://github.com/moby/moby/issues/47688#issuecomment-2042227870

docker/dockerfile:1 is synonym for 1.x so should always give the latest version of the dockerfile syntax (currently 1.7.0) 🤔

I do see you have a mirror configured for docker hub; https://5p2mkxep.mirror.aliyuncs.com/ wondering if that mirror is out of date 🤔

Looking at the version that's pulled in your case, that looks to be v1.3.1;

docker run --rm docker/dockerfile@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2 --version
Unable to find image 'docker/dockerfile@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2' locally
docker.io/docker/dockerfile@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2: Pulling from docker/dockerfile
bcf72e19a205: Download complete
Digest: sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2
Status: Downloaded newer image for docker/dockerfile@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2
/bin/dockerfile-frontend github.com/moby/buildkit/frontend/dockerfile/cmd/dockerfile-frontend dockerfile/1.3.1 966bcf4aa3ef397a9d6025fade18f2d59a5bf29d

Pulling the latest docker/dockerfile:1 from docker hub;

docker run --rm docker/dockerfile:1 --version
Unable to find image 'docker/dockerfile:1' locally
1: Pulling from docker/dockerfile
Digest: sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021
Status: Downloaded newer image for docker/dockerfile:1
/bin/dockerfile-frontend github.com/moby/buildkit/frontend/dockerfile/cmd/dockerfile-frontend dockerfile/1.6.0 18fc875d9bfd6e065cd8211abc639434ba65aa56
fantab01 commented 5 months ago

我最近收到另一份报告,报告也因 heredoc 而失败,并且也使用了该镜像;moby/moby#47688(评论)

docker/dockerfile:1是同义词,1.x因此应始终提供最新版本的 dockerfile 语法(当前1.7.0)🤔 我确实看到你为 docker hub 配置了一个镜像;https://5p2mkxep.mirror.aliyuncs.com/想知道该镜像是否过时了🤔 查看您案例中所用的版本,它似乎是 v1.3.1;

docker run --rm docker/dockerfile@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2 --version
Unable to find image 'docker/dockerfile@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2' locally
docker.io/docker/dockerfile@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2: Pulling from docker/dockerfile
bcf72e19a205: Download complete
Digest: sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2
Status: Downloaded newer image for docker/dockerfile@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2
/bin/dockerfile-frontend github.com/moby/buildkit/frontend/dockerfile/cmd/dockerfile-frontend dockerfile/1.3.1 966bcf4aa3ef397a9d6025fade18f2d59a5bf29d

docker/dockerfile:1从 docker hub提取最新版本;

docker run --rm docker/dockerfile:1 --version
Unable to find image 'docker/dockerfile:1' locally
1: Pulling from docker/dockerfile
Digest: sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021
Status: Downloaded newer image for docker/dockerfile:1
/bin/dockerfile-frontend github.com/moby/buildkit/frontend/dockerfile/cmd/dockerfile-frontend dockerfile/1.6.0 18fc875d9bfd6e065cd8211abc639434ba65aa56

Another unlucky wretch🤦‍♂️