在Dockerfile的同一RUN命令中同时使用挂载和heredocs是可能的吗?

huangapple go评论94阅读模式
英文:

Is it possible to use mounts and heredocs in the same RUN command in a dockerfile

问题

I'm using docker 24.0.1 on an Ubuntu 22.04 install

给定以下Dockerfile:


FROM ubuntu:22.04

RUN --mount=type=cache,target=/var/apt/cache << EOT
  apt-get update -qq
  apt-get install -y apt-utils
EOT

当我运行此文件的构建时,我得到:

dockerfile:6
--------------------
   4 |     
   5 |     RUN --mount=type=cache,target=/var/apt/cache << EOT
   6 | >>>   apt-get update -qq
   7 |       apt-get install -y apt-utils
   8 |     EOT
--------------------
ERROR: failed to solve: dockerfile parse error on line 6: unknown instruction: apt-get

我不确定为什么这两个特性会与彼此不兼容,但考虑到它们是较新的特性,也许它们是不兼容的。有人成功地同时使用它们吗?我是否漏掉了一些东西?

英文:

I'm using docker 24.0.1 on an Ubuntu 22.04 install

Given the following dockerfile:


FROM ubuntu:22.04

RUN --mount=type=cache,target=/var/apt/cache << EOT
  apt-get update -qq
  apt-get install -y apt-utils
EOT

When I run the build for this file, I get:

dockerfile:6
--------------------
   4 |     
   5 |     RUN --mount=type=cache,target=/var/apt/cache << EOT
   6 | >>>   apt-get update -qq
   7 |       apt-get install -y apt-utils
   8 |     EOT
--------------------
ERROR: failed to solve: dockerfile parse error on line 6: unknown instruction: apt-get

I'm not sure why the two features would be incompatible with one another, but given they're newer features, maybe they are. Has anyone had success using both together? Is there something I'm missing to do so?

答案1

得分: 1

David发现了我的错误 - 那个多余的空格是我犯的错。去掉那个空格就修复了构建。

英文:

David caught my error - the typo of the extra space was what caught me off. removing that space fixed the build.

huangapple
  • 本文由 发表于 2023年5月25日 00:29:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76325665.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定