[GH-ISSUE #2396] docker compose setups are potentially loaded with environment from repository root instead of those from their own directory #1102

Closed
opened 2026-03-01 21:48:55 +03:00 by kerem · 3 comments
Owner

Originally created by @simon-20 on GitHub (Jul 12, 2024).
Original GitHub issue: https://github.com/nektos/act/issues/2396

Bug report info

act version:            0.2.64
GOOS:                   linux
GOARCH:                 amd64
NumCPU:                 20
Docker host:            DOCKER_HOST environment variable is not set
Sockets found:
	/var/run/docker.sock
Config files:           
	/home/simon/.config/act/actrc:
		-P ubuntu-latest=catthehacker/ubuntu:act-latest
		-P ubuntu-22.04=catthehacker/ubuntu:act-22.04
		-P ubuntu-20.04=catthehacker/ubuntu:act-20.04
		-P ubuntu-18.04=catthehacker/ubuntu:act-18.04
Build info:
	Go version:            go1.22.4
	Module path:           command-line-arguments
	Main version:          
	Main path:             
	Main checksum:         
	Build settings:
		-buildmode:           exe
		-compiler:            gc
		-ldflags:             -X main.version=0.2.64
		DefaultGODEBUG:       httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
		CGO_ENABLED:          1
		CGO_CFLAGS:           
		CGO_CPPFLAGS:         
		CGO_CXXFLAGS:         
		CGO_LDFLAGS:          
		GOARCH:               amd64
		GOOS:                 linux
		GOAMD64:              v1
Docker Engine:
	Engine version:        27.0.3
	Engine runtime:        runc
	Cgroup version:        2
	Cgroup driver:         systemd
	Storage driver:        overlay2
	Registry URI:          https://index.docker.io/v1/
	OS:                    Ubuntu 22.04.4 LTS
	OS type:               linux
	OS version:            22.04
	OS arch:               x86_64
	OS kernel:             6.5.0-41-generic
	OS CPU:                20
	OS memory:             31757 MB
	Security options:
		name=apparmor
		name=seccomp,profile=builtin
		name=cgroupns

Command used with act

act push

Describe issue

When running a docker compose setup within a Github Actions workflow, act does not load the docker compose with its correct environment file, but loads it with the environment variables loaded from the repository's root directory.

For example, given the following repository structure:

.
├── .github
│   └── workflows
│       └── test.yml
├── .env
└── automated-test-environment
    ├── .env
    └── docker-compose.yml

Where test.yml is:

name: Run Automated Tests
on:
  workflow_dispatch:
  push:
    branches:
      develop

jobs:
  run-tests:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Run docker-compose
      run: cd ./automated-test-environment; docker compose up -d

The docker compose setup is loaded with values from ./.env and not ./automated-test-environment/.env.

This is different to what Github Actions does--Github Actions correctly loads the environment from automated-test-environment/.env.

The contents of ./.env:

DB_NAME=test_db
DB_USER=test_user
DB_PASS=pass
DB_PORT=5276

The contents of ./automated-test-environment/.env:

DB_NAME=test_db
DB_USER=test_user
DB_PASS=pass
DB_PORT=5277

Then, while the docker compose setup is running:

❯ psql -h localhost -U test_user -d test_db -p 5277
psql: error: connection to server at "localhost" (127.0.0.1), port 5277 failed: Connection refused
	Is the server running on that host and accepting TCP/IP connections?

❯ psql -h localhost -U test_user -d test_db -p 5276
Password for user test_user: 

No response

Workflow content

name: Run Automated Tests
on:
  workflow_dispatch:
  push:
    branches:
      develop

jobs:
  run-tests:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Run docker-compose
      run: cd ./automated-test-environment; docker compose up -d

Relevant log output

❯ psql -h localhost -U test_user -d test_db -p 5277
psql: error: connection to server at "localhost" (127.0.0.1), port 5277 failed: Connection refused
	Is the server running on that host and accepting TCP/IP connections?

❯ psql -h localhost -U test_user -d test_db -p 5276
Password for user test_user:

Additional information

May be related to: https://github.com/nektos/act/issues/2151

Originally created by @simon-20 on GitHub (Jul 12, 2024). Original GitHub issue: https://github.com/nektos/act/issues/2396 ### Bug report info ```plain text act version: 0.2.64 GOOS: linux GOARCH: amd64 NumCPU: 20 Docker host: DOCKER_HOST environment variable is not set Sockets found: /var/run/docker.sock Config files: /home/simon/.config/act/actrc: -P ubuntu-latest=catthehacker/ubuntu:act-latest -P ubuntu-22.04=catthehacker/ubuntu:act-22.04 -P ubuntu-20.04=catthehacker/ubuntu:act-20.04 -P ubuntu-18.04=catthehacker/ubuntu:act-18.04 Build info: Go version: go1.22.4 Module path: command-line-arguments Main version: Main path: Main checksum: Build settings: -buildmode: exe -compiler: gc -ldflags: -X main.version=0.2.64 DefaultGODEBUG: httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1 CGO_ENABLED: 1 CGO_CFLAGS: CGO_CPPFLAGS: CGO_CXXFLAGS: CGO_LDFLAGS: GOARCH: amd64 GOOS: linux GOAMD64: v1 Docker Engine: Engine version: 27.0.3 Engine runtime: runc Cgroup version: 2 Cgroup driver: systemd Storage driver: overlay2 Registry URI: https://index.docker.io/v1/ OS: Ubuntu 22.04.4 LTS OS type: linux OS version: 22.04 OS arch: x86_64 OS kernel: 6.5.0-41-generic OS CPU: 20 OS memory: 31757 MB Security options: name=apparmor name=seccomp,profile=builtin name=cgroupns ``` ### Command used with act ```sh act push ``` ### Describe issue When running a docker compose setup within a Github Actions workflow, `act` does not load the docker compose with its correct environment file, but loads it with the environment variables loaded from the repository's root directory. For example, given the following repository structure: ``` . ├── .github │   └── workflows │   └── test.yml ├── .env └── automated-test-environment ├── .env └── docker-compose.yml ``` Where `test.yml` is: ```yaml name: Run Automated Tests on: workflow_dispatch: push: branches: develop jobs: run-tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run docker-compose run: cd ./automated-test-environment; docker compose up -d ``` The `docker compose` setup is loaded with values from `./.env` and not `./automated-test-environment/.env`. This is different to what Github Actions does--Github Actions correctly loads the environment from `automated-test-environment/.env`. The contents of `./.env`: ```env DB_NAME=test_db DB_USER=test_user DB_PASS=pass DB_PORT=5276 ``` The contents of `./automated-test-environment/.env`: ```env DB_NAME=test_db DB_USER=test_user DB_PASS=pass DB_PORT=5277 ``` Then, while the docker compose setup is running: ```bash ❯ psql -h localhost -U test_user -d test_db -p 5277 psql: error: connection to server at "localhost" (127.0.0.1), port 5277 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? ❯ psql -h localhost -U test_user -d test_db -p 5276 Password for user test_user: ``` ### Link to GitHub repository _No response_ ### Workflow content ```yml name: Run Automated Tests on: workflow_dispatch: push: branches: develop jobs: run-tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run docker-compose run: cd ./automated-test-environment; docker compose up -d ``` ### Relevant log output ```sh ❯ psql -h localhost -U test_user -d test_db -p 5277 psql: error: connection to server at "localhost" (127.0.0.1), port 5277 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? ❯ psql -h localhost -U test_user -d test_db -p 5276 Password for user test_user: ``` ### Additional information May be related to: https://github.com/nektos/act/issues/2151
kerem 2026-03-01 21:48:55 +03:00
  • closed this issue
  • added the
    stale
    label
Author
Owner

@ChristopherHX commented on GitHub (Jul 12, 2024):

  1. act loads the .env to your workflow, those are now real env variables that make the second point the truth
  2. docker compose prefers env over the .env file of the subdir

Tell act to not load your .env, by creating .act-env, .actrc with content
--env-file .act-env. After this only env variables of .act-env end up as global workflow variables within act

Tbh, act's defaults can never make everybody happy.

<!-- gh-comment-id:2225377437 --> @ChristopherHX commented on GitHub (Jul 12, 2024): 1. act loads the .env to your workflow, those are now real env variables that make the second point the truth 1. docker compose prefers env over the .env file of the subdir Tell act to not load your .env, by creating `.act-env`, `.actrc` with content `--env-file .act-env`. After this only env variables of `.act-env` end up as global workflow variables within act Tbh, act's defaults can never make everybody happy.
Author
Owner

@simon-20 commented on GitHub (Jul 12, 2024):

Hi,

Thanks for that--it's allowed me to get it working without having to mangle the files in the repo.

Totally understand that the defaults can't keep everyone happy.

I guess the potential issue just is that the values in .env are ordinarily application configuration variables and not workflow configuration variables, and Github Actions does not use the values in .env to setup the environment for the workflow. So when act does this, it departs from Github Actions and may end up producing behaviour that is (i) unexpected, and (ii) different to that which occurs when the workflow is run on Github Actions.

But anyway, it's straightforward enough to work around for most workflows. Thank you very much for your quick response.

<!-- gh-comment-id:2225484203 --> @simon-20 commented on GitHub (Jul 12, 2024): Hi, Thanks for that--it's allowed me to get it working without having to mangle the files in the repo. Totally understand that the defaults can't keep everyone happy. I guess the potential issue just is that the values in `.env` are ordinarily application configuration variables and not workflow configuration variables, and Github Actions does not use the values in `.env` to setup the environment for the workflow. So when `act` does this, it departs from Github Actions and may end up producing behaviour that is (i) unexpected, and (ii) different to that which occurs when the workflow is run on Github Actions. But anyway, it's straightforward enough to work around for most workflows. Thank you very much for your quick response.
Author
Owner

@github-actions[bot] commented on GitHub (Jan 9, 2025):

Issue is stale and will be closed in 14 days unless there is new activity

<!-- gh-comment-id:2578927692 --> @github-actions[bot] commented on GitHub (Jan 9, 2025): Issue is stale and will be closed in 14 days unless there is new activity
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#1102
No description provided.