0

I am running into an issue and wondering if anyone has experienced it before or has a solution for it. Maybe you can help me out

I am running docker with docker-compose and I am using two env_file(s) to send parameters to my containers

My intention is to separate environment variables in different files so that I reuse the value for different purposes. Let's say my MySQL user is the same as the client I want to connect against it but the environment variable in both services are named differently.

I don't want to use the same env_file in both containers as I would end up with unnecessary environment variables in both of them.

Expected result: I expect my container to receive both environment variables, the second one with the same value as the first one.

Result: Te value of "SAME_USERNAME" env var is empty and shown as "" in "docker-compose config"

My lab has:

PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

Docker Compose version v2.16.0 Python 3.10.6

ii  docker-buildx-plugin                  0.10.2-1~ubuntu.22.04~jammy             amd64        Docker Buildx cli plugin.
ii  docker-ce                             5:23.0.1-1~ubuntu.22.04~jammy           amd64        Docker: the open-source application container engine
ii  docker-ce-cli                         5:23.0.1-1~ubuntu.22.04~jammy           amd64        Docker CLI: the open-source application container engine
ii  docker-ce-rootless-extras             5:23.0.1-1~ubuntu.22.04~jammy           amd64        Rootless support for Docker.
ii  docker-compose-plugin                 2.16.0-1~ubuntu.22.04~jammy             amd64        Docker Compose (V2) plugin for the Docker CLI.
ii  docker-scan-plugin                    0.23.0~ubuntu-jammy                     amd64        Docker scan cli plugin.
rc  docker.io                             20.10.12-0ubuntu4                       amd64        Linux container runtime



Client: Docker Engine - Community
Version:           23.0.1
API version:       1.42
Go version:        go1.19.5
Git commit:        a5ee5b1
Built:             Thu Feb  9 19:47:01 2023
OS/Arch:           linux/amd64
Context:           default

Server: Docker Engine - Community
Engine:
Version:          23.0.1
API version:      1.42 (minimum version 1.12)
Go version:       go1.19.5
Git commit:       bc3805a
Built:            Thu Feb  9 19:47:01 2023
OS/Arch:          linux/amd64
Experimental:     false
containerd:
Version:          1.6.18
GitCommit:        2456e983eb9e37e47538f59ea18f2043c9a73640
  runc:
 Version:          1.1.4
 GitCommit:        v1.1.4-0-g5fd4c4d
  docker-init:
 Version:          0.19.0
 GitCommit:        de40ad0

I have this docker-compose file (Example):

service_1:
  image: service_1_image
  container_name: service_1
  env_file: 
    - file1

service-2:
  image: service_2_image
  container_name: service_2
  env_file: 
    - file1
    - file2

The content of the env_file(s) is:

file1:
MY_USERNAME="my_user"
 
file2:
SAME_USERNAME="${MY_USERNAME:-}"

According to the theory it will use "my_user" in the first var and the value of "MY_USERNAME" in the second one as it has no default value

Any idea if this is meant to work? I could not find anyone using it this way and asking for help

Tried with several version of Docker and docker-compose but no luck

I guess my next option would be to add a request in the docker-compose bug site

Any help is appreciated,Thanks

Alf
  • 31
  • 4
  • I will fix the formatting tomorrow, the code validator complains and complains. – Alf Mar 17 '23 at 05:45
  • @sangam-belose, Thanks a lot! You ara amazing man, thanks for the help. Just had a two 80 hour work weeks and had no energy to go through the formatting fix. Thanks – Alf Mar 18 '23 at 17:16

0 Answers0