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

Inline comments in .env #9025

Closed
zhao-li opened this issue Dec 11, 2021 · 11 comments
Closed

Inline comments in .env #9025

zhao-li opened this issue Dec 11, 2021 · 11 comments
Assignees

Comments

@zhao-li
Copy link

zhao-li commented Dec 11, 2021

Description
Inline comments in my .env file used to be ignored properly, but now they are getting sucked into docker-compose.yml configurations and is causing errors.

Is this a new feature or the expected behavior going forward? I couldn't find anything new in the documentation.

Thank you for any help or guidance 🙏

Steps to reproduce the issue:

  1. run docker-compose build

Describe the results you received:
Docker Compose errors out with:

1 error(s) decoding:

* error decoding 'Ports': Invalid containerPort: 8080 # inline comment no longer working

Describe the results you expected:
The container should get built/pulled properly.

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker compose version:

Docker Compose version v2.2.1

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.7.1)
  compose: Docker Compose (Docker Inc., v2.2.1)
  scan: Docker Scan (Docker Inc., 0.9.0)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 25
 Server Version: 20.10.11
 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: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.76-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 31.36GiB
 Name: docker-desktop
 ID: WX5R:W64V:3QST:M5F3:3U54:K63Y:PGYJ:QPAM:2HSF:JS34:HVYI:RWEJ
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details:
docker-compose.yml:

services:
  app:
    image: nginx
    ports:
      - ${APP_PORT}

.env:

APP_PORT=8080 # inline comment no longer working
@adrienc-dev
Copy link

adrienc-dev commented Dec 12, 2021

I am experiencing the same issue, with Docker compose v2.2.1 in Docker Desktop 4.3.0 on Windows.
Comment following an env. variable declaration are no longer ignored when building the container (file is utf8 encoded).

However I admit that the documentation describes comment as "Lines beginning with #". It was convenient though 😕

@ulyssessouza
Copy link
Collaborator

This should be resolved with compose-spec/godotenv#14

@zhao-li
Copy link
Author

zhao-li commented Jan 12, 2022

Thanks @ulyssessouza for the info and making the pull request. Sorry, I'm not familiar with how the project is organized. I was not able to find which version might be including the pull request. Would you happen to know what docker compose version will be including this pull request? Thanks again 🙏

@ulyssessouza
Copy link
Collaborator

@zhao-li in the next one. Can be a v2.2.4 or a v2.3.0 but most probably the first.

@zhao-li
Copy link
Author

zhao-li commented Jan 13, 2022

Thanks @ulyssessouza for the versions. I can't wait to test it out 🦦

@ndeloof ndeloof closed this as completed Jan 14, 2022
olivierdalang added a commit to yverdon/geocity that referenced this issue Sep 7, 2022
olivierdalang added a commit to yverdon/geocity that referenced this issue Sep 7, 2022
@LeviPesin
Copy link

Seems like this issue happens again in Docker Compose 2.19.0.

I have this docker-compose.yml file:

services:
  proxy:
    image: $TEST_IMAGE
    ports:
      - "80:80"
      - "443:443"
    env_file: ../test.env
    volumes:
      - ./ssl:/ssl:ro
      - ./static:/static:ro
    tmpfs: /dumps

  backend:
    image: node
    user: node
    working_dir: /home/node/app
    environment:
      - BACKEND_PORT=8191
      - WEBSOCKET_PORT=8192
    volumes:
      - ../:/home/node/app:ro
    expose:
      - 8191
      - 8192
    command: npm run start-backend

And here are some lines of ../test.env:


NGINX_MULTI_ACCEPT=off # on or off

NGINX_POSTPONE_OUTPUT=1448 # ideally should be Maximum Segment Size

They are transformed into environment variables with values off # on or off and 1448 # ideally should be Maximum Segment Size, while should be just off and 1448.

@LeviPesin
Copy link

Hm... I get this error only on GitHub Actions. I don't get it when testing locally.

@LeviPesin
Copy link

Seems like I've got a bit confused with my tests -- the problem is not in env_file in Docker Compose, it rather seems to be in --env-file in Docker CLI.

@ndeloof
Copy link
Contributor

ndeloof commented Jul 6, 2023

@LeviPesin docker CLI does not rely on compose's dotenv file parser, but read .env file as a raw KEY=VALUE file without support for comments nor quoted content

@LeviPesin
Copy link

Thanks! I will file an issue on the Docker CLI's repo then.

@ndeloof
Copy link
Contributor

ndeloof commented Jul 6, 2023

@LeviPesin you can, but don't expect this to change as this would break backward compatibility. dot env is a de facto, informal file format with no established definition, so no surprise "features" used in this format are not homogeneous between ecosystems

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

No branches or pull requests

5 participants