Repository: nektos/act (language: go)

Issue:
network-scoped alias is supported only for containers in user defined networks
### Bug report info

```plain text
act version:            0.2.53
GOOS:                   windows
GOARCH:                 amd64
NumCPU:                 8
Docker host:            DOCKER_HOST environment variable is not set
Sockets found:
        \\.\pipe\docker_engine(broken)
Config files:
        C:\Users\maxim\.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.20.10
        Module path:           github.com/nektos/act
        Main version:          (devel)
        Main path:             github.com/nektos/act
        Main checksum:
        Build settings:
                -buildmode:           exe
                -compiler:            gc
                -ldflags:             -s -w -X main.version=0.2.53 -X main.commit=1bb2ee7098f338765ce5169c850d0f19e59d3147 -X main.date=2023-11-01T02:14:01Z -X main.builtBy=goreleaser
                CGO_ENABLED:          0
                GOARCH:               amd64
                GOOS:                 windows
                GOAMD64:              v1
                vcs:                  git
                vcs.revision:         1bb2ee7098f338765ce5169c850d0f19e59d3147
                vcs.time:             2023-11-01T02:13:36Z
                vcs.modified:         false
Docker Engine:
        Engine version:        24.0.6
        Engine runtime:        runc
        Cgroup version:        1
        Cgroup driver:         cgroupfs
        Storage driver:        overlay2
        Registry URI:          https://index.docker.io/v1/
        OS:                    Docker Desktop
        OS type:               linux
        OS version:
        OS arch:               x86_64
        OS kernel:             5.15.90.1-microsoft-standard-WSL2
        OS CPU:                8
        OS memory:             7889 MB
        Security options:
                name=seccomp,profile=unconfined
```


### Command used with act

```sh
act
```


### Describe issue

docker image will not run with error:
Error: failed to start container: Error response from daemon: network-scoped alias is supported only for containers in user defined networks

It works fine when downgrading to 0.2.52
What I found: https://github.com/docker/compose-cli/issues/1619

### Link to GitHub repository

_No response_

### Workflow content

```yml
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
  push:
    branches: [ "master", "build_and_test_on_local_and_github" ]
  pull_request:
    branches: [ "master" ]

permissions:
  contents: read
  issues: read
  checks: write
  pull-requests: write

jobs:
  build-and-test-with-gradle:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Set up JDK 8 and JDK with min version for ANTLR
      uses: actions/setup-java@v3
      with:
        java-version: |
          8
          19
        distribution: 'temurin'
    - name: java 8 compile everything in 'src/test/java' to 'build/test-classfiles'
      run: mkdir -p build/test-classfiles && cd src/test/resources/java && for dir in $(find -mindepth 1 -type d); do  find -name "*.java" | xargs javac -d ../../../../build/test-classfiles/$dir; done && ls ../../../../build/test-classfiles -R
    - name: Change wrapper permissions
      run: chmod +x ./gradlew
    - name: Build with Gradle
      uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
      with:
        arguments: build
    - name: Publish Test Results
      uses: EnricoMi/publish-unit-test-result-action@v2
      if: always()
      with:
        files: |
            build/test-results/test/TEST-*.xml
```


### Relevant log output

```sh
time="2023-11-01T17:10:12+01:00" level=debug msg="Loading environment from C:\\Git\\compiler\\.env"
time="2023-11-01T17:10:12+01:00" level=debug msg="Loading action inputs from C:\\Git\\compiler\\.input"
time="2023-11-01T17:10:12+01:00" level=debug msg="Loading secrets from C:\\Git\\compiler\\.secrets"
time="2023-11-01T17:10:12+01:00" level=debug msg="Loading vars from C:\\Git\\compiler\\.vars"
time="2023-11-01T17:10:12+01:00" level=debug msg="Conditional GET for notices etag=4516f189-72d2-4e0d-aad8-45e63f4270d6"
time="2023-11-01T17:10:12+01:00" level=debug msg="Evaluated matrix inclusions: map[]"
time="2023-11-01T17:10:12+01:00" level=debug msg="Loading workflows from 'C:\\Git\\compiler\\.github\\workflows'"
time="2023-11-01T17:10:12+01:00" level=debug msg="Loading workflows recursively"
time="2023-11-01T17:10:12+01:00" level=debug msg="Found workflow 'gradle.yml' in 'C:\\Git\\compiler\\.github\\workflows\\gradle.yml'"
time="2023-11-01T17:10:12+01:00" level=debug msg="Reading workflow 'C:\\Git\\compiler\\.github\\workflows\\gradle.yml'"
time="2023-11-01T17:10:12+01:00" level=debug msg="Preparing plan with all jobs"
time="2023-11-01T17:10:12+01:00" level=debug msg="Using default workflow event: push"
time="2023-11-01T17:10:12+01:00" level=debug msg="Planning jobs for event: push"
time="2023-11-01T17:10:12+01:00" level=debug msg="gc: 2023-11-01 17:10:12.1455533 +0100 CET m=+0.039342801" module=artifactcache
time="2023-11-01T17:10:12+01:00" level=debug msg="Plan Stages: [0xc0003a23d8]"
time="2023-11-01T17:10:12+01:00" level=debug msg="Stages Runs: [build-and-test-with-gradle]"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Name: build-and-test-with-gradle"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.RawNeeds: {0 0    <nil> []    0 0}"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.RawRunsOn: {8 0 !!str ubuntu-latest  <nil> []    24 14}"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Env: {0 0    <nil> []    0 0}"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.If: {0 0  success()  <nil> []    0 0}"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Steps: actions/checkout@v3"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Steps: Set up JDK 8 and JDK with min version for ANTLR"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Steps: java 8 compile everything in 'src/test/java' to 'build/test-classfiles'"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Steps: Change wrapper permissions"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Steps: Build with Gradle"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Steps: Publish Test Results"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.TimeoutMinutes: "
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Services: map[]"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Strategy: <nil>"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.RawContainer: {0 0    <nil> []    0 0}"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Defaults.Run.Shell: "
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Defaults.Run.WorkingDirectory: "
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Outputs: map[]"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Uses: "
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.With: map[]"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job.Result: "
time="2023-11-01T17:10:12+01:00" level=debug msg="Empty Strategy, matrixes=[map[]]"
time="2023-11-01T17:10:12+01:00" level=debug msg="Job Matrices: [map[]]"
time="2023-11-01T17:10:12+01:00" level=debug msg="Runner Matrices: map[]"
time="2023-11-01T17:10:12+01:00" level=debug msg="Final matrix after applying user inclusions '[map[]]'"
time="2023-11-01T17:10:12+01:00" level=debug msg="Loading revision from git directory"
time="2023-11-01T17:10:12+01:00" level=debug msg="Found revision: 337362e1af0d251703c97494ffa1b9bd71b17304"
time="2023-11-01T17:10:12+01:00" level=debug msg="HEAD points to '337362e1af0d251703c97494ffa1b9bd71b17304'"
time="2023-11-01T17:10:12+01:00" level=debug msg="using github ref: refs/heads/build_and_test_on_local_and_github"
time="2023-11-01T17:10:12+01:00" level=debug msg="Found revision: 337362e1af0d251703c97494ffa1b9bd71b17304"
time="2023-11-01T17:10:12+01:00" level=debug msg="Detected CPUs: 8"
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] evaluating expression 'success()'
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] expression 'success()' evaluated to 'true'
[Java CI with Gradle/build-and-test-with-gradle] 🚀  Start image=catthehacker/ubuntu:act-latest
time="2023-11-01T17:10:12+01:00" level=info msg="Parallel tasks (0) below minimum, setting to 1"
[Java CI with Gradle/build-and-test-with-gradle]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=true
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG]   🐳  docker pull catthehacker/ubuntu:act-latest
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] pulling image 'docker.io/catthehacker/ubuntu:act-latest' ()
time="2023-11-01T17:10:13+01:00" level=debug msg="Saving notices etag=4516f189-72d2-4e0d-aad8-45e63f4270d6"
time="2023-11-01T17:10:13+01:00" level=debug msg="No new notices"
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] Pulling from catthehacker/ubuntu :: act-latest
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] Digest: sha256:88030ffb426831aab0022f7beda465251e00c45d8746069349101c6902d94e4b ::
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] Status: Image is up to date for catthehacker/ubuntu:act-latest ::
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] Removed container: 652a6845bb0e1398327526fc8eb7ccda2bd3b1b524af2ad3bb3c334489896676
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG]   🐳  docker volume rm act-Java-CI-with-Gradle-build-and-test-with-gradle-ce7c01884ee4591db19584be89f26333ae41ccfff0b5f85430a32846d955a885
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG]   🐳  docker volume rm act-Java-CI-with-Gradle-build-and-test-with-gradle-ce7c01884ee4591db19584be89f26333ae41ccfff0b5f85430a32846d955a885-env
time="2023-11-01T17:10:13+01:00" level=info msg="Parallel tasks (0) below minimum, setting to 1"
[Java CI with Gradle/build-and-test-with-gradle]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] Common container.Config ==> &{Hostname: Domainname: User: AttachStdin:false AttachStdout:false AttachStderr:false ExposedPorts:map[] Tty:true OpenStdin:false StdinOnce:false Env:[RUNNER_TOOL_CACHE=/opt/hostedtoolcache RUNNER_OS=Linux RUNNER_ARCH=X64 RUNNER_TEMP=/tmp LANG=C.UTF-8] Cmd:[] Healthcheck:<nil> ArgsEscaped:false Image:catthehacker/ubuntu:act-latest Volumes:map[] WorkingDir:/mnt/c/Git/compiler Entrypoint:[] NetworkDisabled:false MacAddress: OnBuild:[] Labels:map[] StopSignal: StopTimeout:<nil> Shell:[]}
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] Common container.HostConfig ==> &{Binds:[/var/run/docker.sock:/var/run/docker.sock] ContainerIDFile: LogConfig:{Type: Config:map[]} NetworkMode:host PortBindings:map[] RestartPolicy:{Name: MaximumRetryCount:0} AutoRemove:false VolumeDriver: VolumesFrom:[] ConsoleSize:[0 0] Annotations:map[] CapAdd:[] CapDrop:[] CgroupnsMode: DNS:[] DNSOptions:[] DNSSearch:[] ExtraHosts:[] GroupAdd:[] IpcMode: Cgroup: Links:[] OomScoreAdj:0 PidMode: Privileged:false PublishAllPorts:false ReadonlyRootfs:false SecurityOpt:[] StorageOpt:map[] Tmpfs:map[] UTSMode: UsernsMode: ShmSize:0 Sysctls:map[] Runtime: Isolation: Resources:{CPUShares:0 Memory:0 NanoCPUs:0 CgroupParent: BlkioWeight:0 BlkioWeightDevice:[] BlkioDeviceReadBps:[] BlkioDeviceWriteBps:[] BlkioDeviceReadIOps:[] BlkioDeviceWriteIOps:[] CPUPeriod:0 CPUQuota:0 CPURealtimePeriod:0 CPURealtimeRuntime:0 CpusetCpus: CpusetMems: Devices:[] DeviceCgroupRules:[] DeviceRequests:[] KernelMemory:0 KernelMemoryTCP:0 MemoryReservation:0 MemorySwap:0 MemorySwappiness:<nil> OomKillDisable:<nil> PidsLimit:<nil> Ulimits:[] CPUCount:0 CPUPercent:0 IOMaximumIOps:0 IOMaximumBandwidth:0} Mounts:[{Type:volume Source:act-toolcache Target:/toolcache ReadOnly:false Consistency: BindOptions:<nil> VolumeOptions:<nil> TmpfsOptions:<nil> ClusterOptions:<nil>} {Type:volume Source:act-Java-CI-with-Gradle-build-and-test-with-gradle-ce7c01884ee4591db19584be89f26333ae41ccfff0b5f85430a32846d955a885-env Target:/var/run/act ReadOnly:false Consistency: BindOptions:<nil> VolumeOptions:<nil> TmpfsOptions:<nil> ClusterOptions:<nil>} {Type:volume Source:act-Java-CI-with-Gradle-build-and-test-with-gradle-ce7c01884ee4591db19584be89f26333ae41ccfff0b5f85430a32846d955a885 Target:/mnt/c/Git/compiler ReadOnly:false Consistency: BindOptions:<nil> VolumeOptions:<nil> TmpfsOptions:<nil> ClusterOptions:<nil>}] MaskedPaths:[] ReadonlyPaths:[] Init:<nil>}
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] input.NetworkAliases ==> [build-and-test-with-gradle]
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] Created container name=act-Java-CI-with-Gradle-build-and-test-with-gradle-ce7c01884ee4591db19584be89f26333ae41ccfff0b5f85430a32846d955a885 id=caacdabf5b22e1af77100cd8d2f514c0b1692aabe728d3a008e079916a70e985 from image catthehacker/ubuntu:act-latest (platform: )
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] ENV ==> [RUNNER_TOOL_CACHE=/opt/hostedtoolcache RUNNER_OS=Linux RUNNER_ARCH=X64 RUNNER_TEMP=/tmp LANG=C.UTF-8]
[Java CI with Gradle/build-and-test-with-gradle]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Java CI with Gradle/build-and-test-with-gradle] [DEBUG] Starting container: caacdabf5b22e1af77100cd8d2f514c0b1692aabe728d3a008e079916a70e985
Error: failed to start container: Error response from daemon: network-scoped alias is supported only for containers in user defined networks
```


### Additional information

_No response_


Discussion / hints:
I've run into this problem as well.

- Act Version: 0.2.53
- OS: Windows 11 Pro

Workflow file: [.github/workflows/code-style-dev.yml](https://github.com/TheDragonCode/codestyler/blob/3.x/.github/workflows/code-style-dev.yml)

```bash
act -W '.github/workflows/code-style-dev.yml'
```

Output:

```
[Code Style Development/style_dev] 🚀  Start image=catthehacker/ubuntu:act-latest
time="2023-11-02T12:56:55+03:00" level=info msg="Parallel tasks (0) below minimum, setting to 1"
[Code Style Development/style_dev]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=true
[Code Style Development/style_dev] using DockerAuthConfig authentication for docker pull
time="2023-11-02T12:56:57+03:00" level=info msg="Parallel tasks (0) below minimum, setting to 1"
[Code Style Development/style_dev]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Code Style Development/style_dev]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
Error: failed to start container: Error response from daemon: network-scoped alias is supported only for containers in user defined networks
```
This problem occurs in v0.2.53, but it no longer occurs after downgrading to v0.2.51.
I can confirm this bug, I'm working on a fix...
go\pkg\mod\github.com\docker\docker@v24.0.7+incompatible\api\types\container\hostconfig_unix.go
```
// IsUserDefined indicates user-created network
func (n NetworkMode) IsUserDefined() bool {
	return !n.IsDefault() && !n.IsBridge() && !n.IsHost() && !n.IsNone() && !n.IsContainer()
}
```

go\pkg\mod\github.com\docker\docker@v24.0.7+incompatible\api\types\container\hostconfig_windows.go
```
// IsUserDefined indicates user-created network
func (n NetworkMode) IsUserDefined() bool {
	return !n.IsDefault() && !n.IsNone() && !n.IsBridge() && !n.IsContainer()
}
```

Why did docker this?

Seems like I have to replace the convenience function with it's unix definition
We've also run into this problem. Fixed temporary by downgrading act to v0.2.51.
I'm experiencing the same issue. I can provide any information if you need
The patch is finished from my side, but I'm not in the position to be allowed to merge. 

> I can provide any information if you need

I would only need 2 reviewer from maintainers (while I'm one of them, my PR's need a total amount of 3 maintainers, if you would open a PR with the same change I could approve it so only one maintainer review is missing), but that's a bottle neg. _(One reason why my commit rate for this repository is declining and I'm less motivated to review other PR's)_

Please comment and test my linked PR https://github.com/nektos/act/pull/2075, this could increase the chance another maintainer have a look at the change.
If you use gh, in the meantime:

```sh
gh extension install https://github.com/nektos/gh-act --pin v0.2.51
```
I faced this problem today after the upgrade. Downgraded to 0.2.51 and it worked :)
Due to the mass of PR's merged today, I prefer to do manual regression testing before creating a hotfix release.

If there is no release till wednesday, please ping me.
Please update to v0.2.54
- GitHub Release is available https://github.com/nektos/act/releases/tag/v0.2.54
- winget users need to wait for https://github.com/microsoft/winget-pkgs/pull/126522
- all other manually updated packages from package managers can take a while
@ChristopherHX, thank you!

Chocolatey has [not found](https://community.chocolatey.org/packages/act-cli) an update yet. I'll check back later.
I've updated to 0.2.54 and am still experiencing the problem.
Whops
```
// IsHost indicates whether container uses the host network stack.
// returns false as this is not supported by windows
func (n NetworkMode) IsHost() bool {
	return false
}
```


Fix patch:
diff --git a/pkg/container/docker_run.go b/pkg/container/docker_run.go
index 5a8afa222a6..18328845515 100644
--- a/pkg/container/docker_run.go
+++ b/pkg/container/docker_run.go
@@ -448,8 +448,8 @@ func (cr *containerReference) create(capAdd []string, capDrop []string) common.E
 		var networkingConfig *network.NetworkingConfig
 		logger.Debugf("input.NetworkAliases ==> %v", input.NetworkAliases)
 		n := hostConfig.NetworkMode
-		// TODO: use IsUserDefined() once it's windows implementation matches the unix one
-		if !n.IsDefault() && !n.IsBridge() && !n.IsHost() && !n.IsNone() && !n.IsContainer() && len(input.NetworkAliases) > 0 {
+		// IsUserDefined and IsHost are broken on windows
+		if n.IsUserDefined() && n != "host" && len(input.NetworkAliases) > 0 {
 			endpointConfig := &network.EndpointSettings{
 				Aliases: input.NetworkAliases,
 			}
@@ -458,8 +458,6 @@ func (cr *containerReference) create(capAdd []string, capDrop []string) common.E
 					input.NetworkMode: endpointConfig,
 				},
 			}
-		} else {
-			logger.Debugf("not a use defined config??")
 		}
 
 		resp, err := cr.cli.ContainerCreate(ctx, config, hostConfig, networkingConfig, platSpecs, input.Name)


Test patch: