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

Environment variables from env_file containing a "#" are truncated in V2 #9327

Closed
ceelian opened this issue Mar 30, 2022 · 5 comments · Fixed by docker/docs#14507
Closed

Comments

@ceelian
Copy link

ceelian commented Mar 30, 2022

Description

Environment variables which contain "#" in the value are truncated starting from the "#" when using the env_file.
For example the line TEST_VAR=abc#def in an env_file will lead to TEST_VAR=abc in the container instead of TEST_VAR=abc#def

Regarding the official docs

Lines beginning with # are treated as comments and are ignored.

only lines beginning with an "#" should be ignored, so the given example should work.

Steps to reproduce the issue:

  1. create a env file with a line TEST_VAR=abc#def
  2. create a docker compose service which uses the env file
  3. connect to a shell inside the container and execute printenv | grep TEST_VAR

Describe the results you received:
TEST_VAR=abc

Describe the results you expected:
TEST_VAR=abc#def

Additional information you deem important (e.g. issue happens only occasionally):
It works on compose 1.29.2 it is not working on 2.3.3

Output of docker compose version:

$ docker compose version  
Docker Compose version v2.3.3

Output of docker info:

docker info           
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.8.1)
  compose: Docker Compose (Docker Inc., v2.3.3)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 46
  Running: 34
  Paused: 0
  Stopped: 12
 Images: 30
 Server Version: 20.10.13
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 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: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc
 runc version: v1.0.3-0-gf46b6ba
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.104-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 5
 Total Memory: 31.31GiB
 Name: docker-desktop
 ID: EPXM:RZ2P:Q5WT:LTKD:H47P:HYP3:Y762:HODR:NHFO:EJJE:DHMF:ZIJV
 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
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false
@ulyssessouza
Copy link
Contributor

Actually what's happening is that it's just interpreting it as an inline comment.
To avoid that you can use double quotes to indicate that the "#" makes part of the value and not an inline comment.
That would be like:

TEST_VAR="abc#def"

@ceelian
Copy link
Author

ceelian commented Apr 1, 2022

@ulyssessouza Agree, but that's not documented. Anyway it is a breaking change from V1 to V2. Do you know if this breaking change is mentioned somewhere?

@ceelian
Copy link
Author

ceelian commented Apr 1, 2022

IMO this is still an open issue because if this is intended behaviour than the documentation is wrong as mentioned/linked in my first post.

Personally I find that the V1 behaviour which is officially documented and only accepts comments if the first character in a line is "#" makes more sense and is less error prone.

@ulyssessouza
Copy link
Contributor

@ceelian I agree. But at the same time I see that as a nice feature. So I'm proposing a change to the documentation to reflect the new behaviour

docker/docs#14507

@ceelian
Copy link
Author

ceelian commented Apr 7, 2022

@ulyssessouza Thank you for the quick PR and merge. Don't get me wrong but could you explain why you think the breaking change is a "nice feature"? I mainly see the disadvantage of a breaking change which will cause more work for the DevOps when they want/need to migrate to V2. But maybe I overlook some demanded advantages of the change.

I am just curious I know you already decided and merged the PR.

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

Successfully merging a pull request may close this issue.

2 participants