cli icon indicating copy to clipboard operation
cli copied to clipboard

`--env-file` doesn't support inline comments

Open LeviPesin opened this issue 3 years ago • 8 comments

Description

Currently docker run --env-file someenvfile.env sometag doesn't remove inline comments -- so if something like SOMEVAR=somevalue # comment is written, SOMEVAR is set to somevalue # comment instead of somevalue. Similar issue for Docker Compose was fixed about 1.5 years ago.

Reproduce

  1. echo 'SOMEVAR=somevalue # comment' > test.env
  2. docker run --env-file test.env bash bash -c 'echo $''SOMEVAR'

Expected behavior

somevalue is expected but somevalue # comment is actual.

docker version

Client: Docker Engine - Community
 Cloud integration: v1.0.35
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:52:17 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Desktop
 Engine:
  Version:          24.0.2-38-g8e70a1b23e
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       8e70a1b23e965d86ec8c2feb77605196ae124630
  Built:            Fri Jun  2 15:58:50 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client: Docker Engine - Community
 Version:    24.0.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.19.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-compose
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.20
    Path:     /usr/local/lib/docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.6
    Path:     /usr/local/lib/docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-sbom
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-scan
  scout: Command line tool for Docker Scout (Docker Inc.)
    Version:  0.16.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-scout

Server:
 Containers: 17
  Running: 6
  Paused: 0
  Stopped: 11
 Images: 40
 Server Version: 24.0.2-38-g8e70a1b23e
 Storage Driver: stargz
  driver-type: io.containerd.snapshotter.v1
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3dce8eb055cbb6872793272b4f20ed16117344f8
 runc version: v1.1.7-0-g860f061
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 5.15.90.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.235GiB
 Name: docker-desktop
 ID: 4359e80c-f658-4395-9bc1-c38e42346fb7
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support

Additional Info

No response

LeviPesin avatar Jul 06 '23 13:07 LeviPesin

This is by design (but can be confusing, because compose also implemented an --env-file option, which is not the equivalent.

The compose --env-file option specifies the path of the .env file in compose, which is a compose feature (and also allows, e.t.c export FOO=bar.

The --env-file on docker run is strictly a list of key=value pairs, and only allows line comments, not inline comments; https://github.com/docker/cli/blob/dc2eb3bf7c835ff820e0a38de123a846b9e887e9/docs/reference/commandline/run.md#-set-environment-variables--e---env---env-file

Changing that would be a breaking change, so not likely something we could do

thaJeztah avatar Jul 06 '23 13:07 thaJeztah

You can also load the environment variables from a file. This file should use the syntax =value (which sets the variable to the given value) or  (which takes the value from the local environment), and # for comments.

It isn't really clear from this that line comments are supported but not inline... So maybe the documentation can be updated?

LeviPesin avatar Jul 06 '23 15:07 LeviPesin

Can i work on This? @thaJeztah

michaelnadar avatar Jul 26 '23 10:07 michaelnadar

Is this issue still open or was it fixed in #4464 ?

mounilKshah avatar Oct 29 '23 07:10 mounilKshah

open bro

michaelnadar avatar Oct 29 '23 08:10 michaelnadar

I would like to work on it @thaJeztah

desmond3th avatar Nov 06 '23 09:11 desmond3th

Yes, looks like https://github.com/docker/cli/pull/4464 was closed before it was reviewed/merged.

We should probably use similar wording as we do for describing how comments are handled in the Dockerfile syntax; https://docs.docker.com/engine/reference/builder/

Screenshot 2023-11-06 at 11 31 02

/cc @dvdksn

thaJeztah avatar Nov 06 '23 10:11 thaJeztah

@desmond3th feel free to open a PR!

dvdksn avatar Nov 06 '23 12:11 dvdksn