docker / buildx

Docker CLI plugin for extended build capabilities with BuildKit
Apache License 2.0
3.33k stars 448 forks source link

Syntax error - can't find = in "-m)". Must be of the form: name=value while setting ENV variable #2553

Closed jabir366 closed 1 week ago

jabir366 commented 1 week ago

Contributing guidelines

I've found a bug and checked that ...

Description

When ENV variable is set as output of a command having spaces in it , the docker does not parse them properly and giving a syntax error

in the Dockerfile the following line

ENV ARCH=$(uname -m) 

Expected behaviour

No error is expected, the variable $ARCH should have the system architecture

Actual behaviour

Docker is showing error

Syntax error - can't find = in "-m)". Must be of the form: name=value

Buildx version

buildah 1.33.8

Docker info

rootless: false
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: false
  serviceIsRemote: false
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.2.3-1.module+el8.10.0+21962+8143777b.x86_64
    version: |-
      slirp4netns version 1.2.3
      commit: c22fde291bb35b354e6ca44d13be181c76a0a432
      libslirp: 4.4.0
      SLIRP_CONFIG_VERSION_MAX: 3
      libseccomp: 2.5.2
  swapFree: 17174347776
  swapTotal: 17175670784
  uptime: 846h 33m 38.00s (Approximately 35.25 days)
  variant: ""
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  - ipvlan
  volume:
  - local
registries:
  search:
  - registry.access.redhat.com
  - registry.redhat.io
  - docker.io
store:
  configFile: /etc/containers/storage.conf
  containerStore:
    number: 7
    paused: 0
    running: 0
    stopped: 7
  graphDriverName: overlay
  graphOptions:
    overlay.mountopt: nodev,metacopy=on
  graphRoot: /var/lib/containers/storage
  graphRootAllocated: 250059685888
  graphRootUsed: 96487174144
  graphStatus:
    Backing Filesystem: xfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Supports shifting: "false"
    Supports volatile: "true"
    Using metacopy: "true"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 491
  runRoot: /run/containers/storage
  transientStore: false
  volumePath: /var/lib/containers/storage/volumes
version:
  APIVersion: 4.9.4-rhel
  Built: 1718020574
  BuiltTime: Mon Jun 10 04:56:14 2024
  GitCommit: ""
  GoVersion: go1.21.7 (Red Hat 1.21.7-2.module+el8.10.0+21638+b01be198)
  Os: linux
  OsArch: linux/amd64
  Version: 4.9.4-rhel

Builders list

docker buildx ls
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Error: unrecognized command `podman buildx ls`
Try 'podman buildx --help' for more information

Configuration

FROM alpine

# Set ARCH environment variable based on uname -m output
ENV ARCH=$(uname -m)

# Use ARCH variable in subsequent commands
RUN echo "Architecture is $ARCH"
$ docker buildx build .

Build logs

Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Error: parsing main Dockerfile: /root/jab/sample/Dockerfile: Syntax error - can't find = in "-m)". Must be of the form: name=value

Additional info

I have tried to change the line from ENV ARCH=$(uname -m) to ENV ARCH=$(arch) . this is passing because it has only one argument inside the $()

jabir366 commented 1 week ago

I also tried using ENV ARCH $(uname -m) It works, but as per the documentation , it says that this option is kept just for backward compatibility and will be removed in future

jabir366 commented 1 week ago

I understand that this won't work as each command in Dockerfile is executed in a separate container