Skip to content
New issue

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

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

Already on GitHub? # to your account

[BUG] Inside .env file, a variable with literal value containing $ gets duplicated #12315

Open
jvitor83 opened this issue Nov 22, 2024 · 4 comments

Comments

@jvitor83
Copy link

Description

If you have a .env file with some variable containing $ in his value, the result duplicate the $ character.

As we define as literal, we expect it to be as-is.

Steps To Reproduce

# .env
SOME_VAR='MY OWN 1$'
# compose.yml
name: dollar-duplication
services:
  scratch:
    image: scratch
    environment:
      CONTAINER_ENV_VAR: "USE ${SOME_VAR}"

Execute:
docker compose config

Output:

name: dollar-duplication
services:
  scratch:
    environment:
      CONTAINER_ENV_VAR: USE MY OWN 1$$
    image: scratch
    networks:
      default: null
networks:
  default:
    name: dollar-duplication_default

Compose Version

Docker Compose version v2.30.3

Docker Environment

Client:
 Version:    26.1.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.0-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.0-desktop.2
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.29
    Path:     C:\Program Files\Docker\cli-plugins\docker-debug.exe
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     C:\Program Files\Docker\cli-plugins\docker-dev.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.23
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     C:\Program Files\Docker\cli-plugins\docker-feedback.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.1.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.8.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 20
  Running: 19
  Paused: 0
  Stopped: 1
 Images: 70
 Server Version: 26.1.1
 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: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e377cd56a71523140ca6ae87e30244719194a521
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 5.15.146.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 8.732GiB
 Name: docker-desktop
 ID: 5150d74e-c0c0-446b-9828-3301461cb963
 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
 Labels:
  com.docker.desktop.address=npipe://\\.\pipe\docker_cli
 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
WARNING: daemon is not using the default seccomp profile

Anything else?

No response

@jvitor83 jvitor83 changed the title [BUG] Inside .env file, a variable with literal value containing $ it's getting duplicated [BUG] Inside .env file, a variable with literal value containing $ gets duplicated Nov 22, 2024
@PRITHIVEE
Copy link

PRITHIVEE commented Nov 24, 2024

Hi @jvitor83
The "$" after 1 is an escaping character for the "$" character present in you env
Without that the output's compose file will try to resolved a $ variable leading to unexpected behaviour

@jvitor83
Copy link
Author

@PRITHIVEE i got that, but the single quote is supposed to treat the content as fully literal.

At least is what is in: https://docs.docker.com/compose/how-tos/environment-variables/variable-interpolation/#env-file-syntax

Single-quoted (') values are used literally.

  • VAR='$OTHER' -> $OTHER
  • VAR='${OTHER}' -> ${OTHER}

Anyway, I coudn't find a way to have only a single $ in the value!

@ndeloof
Copy link
Contributor

ndeloof commented Nov 25, 2024

The content is treated as fully literal, but then as you run docker compose config the resulting compose model is dumped, and $ is escaped to preserve this character from later interpolation by another compose command. This is the desired behavior

Please explain your use case, so I better understand why this is an issue for you and how you rely on config command.

@PRITHIVEE
Copy link

@jvitor83 access the env within the container, you wont be seeing the extra "$" when you access the env

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

No branches or pull requests

3 participants