Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Docker heredoc with Google Cloud

It's been a while since Docker introduced the ability to use heredoc in the RUN command, and I use it quite often.

However, when I tried to use it with Cloud Run, it seems that this feature is not supported, or do I need to do something to enable it?

Example:

FROM ubuntu:jammy

RUN <<EOF
apt-get update
apt-get upgrade -y
apt-get install -y build-essential cmake git python3 python3-pip wget zip
pip install conan
conan profile detect
EOF

I get the error:

Error response from daemon: dockerfile parse error line 13: unknown instruction: APT-GET

like image 553
Rodrigo Avatar asked Sep 12 '25 04:09

Rodrigo


2 Answers

I managed to build an image using heredocs with Google Cloud Builds and it runs properly on Google Cloud Run.

  1. In the Dockerfile I added:
#syntax=docker/dockerfile:1.4

heredocs were introduced in this version: https://docs.docker.com/build/dockerfile/release-notes/#140

  1. In my cloudbuild.yaml I used the command docker buildx build ... to use docker toolkit.
steps:
  - id: "Build Docker Image: -> "
    name: "gcr.io/cloud-builders/docker"
    args: ["buildx", "build",  "-t", "${_TAG}", "."]
# ...
like image 108
jrobichaud Avatar answered Sep 15 '25 17:09

jrobichaud


I tried it on my machine, but I have also faced the same error as yours when deployed to cloud run.. To answer your specific question

However, when I tried to use it with Cloud Run, it seems that this feature is not supported, or do I need to do something to enable it?

From my above repro I believe that heredoc is still not supported by cloud run. And I don't think there is something else to be enabled to get it to work. As a work around you may try below script as suggested here

RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y ...

Although work around is there you can still consider raising a feature request in GCP public issue tracker with your use case scenario.

like image 38
Roopa M Avatar answered Sep 15 '25 16:09

Roopa M