From f684988ae27b26fd26f9ac90daa86425900ab5a6 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 9 May 2023 16:41:31 +0800 Subject: [PATCH] Do not set the default network to `host` (#55) In [nektos/act/pull/1739](https://github.com/nektos/act/pull/1739), the container network mode defaults to `host` if the network option isn't specified in `options`. When calling `ConnectToNetwork`, the `host` network mode may cause the error: `Error response from daemon: container sharing network namespace with another container or host cannot be connected to any other network` see the code: https://gitea.com/gitea/act/src/commit/d2df2b0eebe1b517b786d0ef468b30e43041b05f/pkg/container/docker_run.go#L51-L68 To avoid the error, this logic needs to be removed to keep the default network mode as `bridge`. Reviewed-on: https://gitea.com/gitea/act/pulls/55 Reviewed-by: Jason Song Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- act/container/docker_run.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/act/container/docker_run.go b/act/container/docker_run.go index 4ff00a96..419369be 100644 --- a/act/container/docker_run.go +++ b/act/container/docker_run.go @@ -366,11 +366,15 @@ func (cr *containerReference) mergeContainerConfigs(ctx context.Context, config return nil, nil, fmt.Errorf("Cannot parse container options: '%s': '%w'", input.Options, err) } - if len(copts.netMode.Value()) == 0 { - if err = copts.netMode.Set("host"); err != nil { - return nil, nil, fmt.Errorf("Cannot parse networkmode=host. This is an internal error and should not happen: '%w'", err) - } - } + // If a service container's network is set to `host`, the container will not be able to + // connect to the specified network created for the job container and the service containers. + // So comment out the following code. + + // if len(copts.netMode.Value()) == 0 { + // if err = copts.netMode.Set("host"); err != nil { + // return nil, nil, fmt.Errorf("Cannot parse networkmode=host. This is an internal error and should not happen: '%w'", err) + // } + // } containerConfig, err := parse(flags, copts, "") if err != nil {