Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker build is not recognising the -e flag for the echo command #4954

Open
kalpaitch opened this issue Mar 20, 2024 · 2 comments
Open

Docker build is not recognising the -e flag for the echo command #4954

kalpaitch opened this issue Mar 20, 2024 · 2 comments

Comments

@kalpaitch
Copy link

kalpaitch commented Mar 20, 2024

Description

I'm not sure how to categorise this but it seems like unexpected behaviour. I'm running a simple command such as echo -e "BEGINNING OF FILE\n\n" > .tmpfile

When I run this from the docker image it outputs as expected. When I run this within a 'RUN' command in the Dockerfile it outputs the '-e' flag as part of the output e.g. "-e BEGINNING OF FILE".

I have no idea why it's outputting the -e flag directly.

Reproduce

Add this step to the Docker file:

RUN echo -e "BEGINNING OF FILE\n\n" > .tmpfile

Expected behavior

The output should be:

BEGINNING OF FILE

But is actually:

-e BEGINNING OF FILE

docker version

Client: Docker Engine - Community
 Version:           25.0.3
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        4debf41
 Built:             Tue Feb  6 21:13:09 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          25.0.3
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       f417435
  Built:            Tue Feb  6 21:13:09 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client: Docker Engine - Community
 Version:    25.0.3
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.6
    Path:     /usr/libexec/docker/cli-plugins/docker-compose
  scout: Docker Scout (Docker Inc.)
    Version:  v1.0.8
    Path:     /home/andrew/.docker/cli-plugins/docker-scout

Server:
 Containers: 4
  Running: 4
  Paused: 0
  Stopped: 0
 Images: 11
 Server Version: 25.0.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: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.2.0-39-generic
 Operating System: Ubuntu 23.04
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 62.52GiB
 Name: kalpaitch-spinach
 ID: a160b708-c811-46e9-9c47-389514f4b548
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional Info

No response

@athulnair02
Copy link

Hi, I would like to work on this, is there a good place to start?

@thaJeztah
Copy link
Member

I'm not able to reproduce this issue using alpine as base-image;

docker build -t foo -<<'EOF'
FROM alpine
RUN echo -e "BEGINNING OF FILE\n\n" > .tmpfile
EOF

Build runs successfully;

[+] Building 1.5s (7/7) FINISHED                                                                                                                                                                           docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                                                       0.0s
 => => transferring dockerfile: 96B                                                                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                                                                                                           0.0s
 => [internal] load .dockerignore                                                                                                                                                                                          0.0s
 => => transferring context: 2B                                                                                                                                                                                            0.0s
 => [1/2] FROM docker.io/library/alpine:latest@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b                                                                                                     1.2s
 => => resolve docker.io/library/alpine:latest@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b                                                                                                     1.2s
 => [auth] library/alpine:pull token for registry-1.docker.io                                                                                                                                                              0.0s
 => [2/2] RUN echo -e "BEGINNING OF FILE\n\n" > .tmpfile                                                                                                                                                                   0.1s
 => exporting to image                                                                                                                                                                                                     0.1s
 => => exporting layers                                                                                                                                                                                                    0.0s
 => => exporting manifest sha256:07e9b08ca1e01a821c0779ed887a2ad47622da64c8bd558c757ada84bfdb97ab                                                                                                                          0.0s
 => => exporting config sha256:e8769b3ba4c8f5e05d3c2b38644985cc74fb123b221a79fd99635b7663815811                                                                                                                            0.0s
 => => exporting attestation manifest sha256:c93bcc769d1be9eca9549c10fe9828a49f922e8abc2c7423cbf6a5ff719b8c99                                                                                                              0.0s
 => => exporting manifest list sha256:97cab80709c4b973b084d9066f472d9dd242a395646bc6f9dfcfc0099b4f0fd3                                                                                                                     0.0s
 => => naming to docker.io/library/foo:latest                                                                                                                                                                              0.0s
 => => unpacking to docker.io/library/foo:latest                                                                                                                                                                           0.0s

And checking the file shows the expected content;

docker run --rm foo cat /.tmpfile
BEGINNING OF FILE

However, the RUN command itself is executed in a container, so it depends on what base-image you're using; my example used alpine, but perhaps it doesn't work with other images; what image are you using as base-image?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants