aws / aws/aws-sam-cli

Setting --docker-network option on sam build command has no effect

Open
#3,609 8 comments 8 reactions 0 assignees View on GitHub
area/docker maintainer/need-followup stage/bug-repro
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Description:
When running `sam build --docker-network host` I am expecting the Docker container that is under build to use the network specified by the `docker-network` flag.

### Steps to reproduce:
1. Create a simple SAM project w/ PackageType=Image
2. Add a `RUN SLEEP 100` to the Dockerfile to force the build process to pause so it can be inspected
3. Run `sam build --docker-network host`
4. While the Docker image is building, run `docker inspect --format='{{range $k, $v := .NetworkSettings.Networks}}{{$k}}{{end}}' [container]`

### Observed result:
Regardless of what is passed to the `--docker-network` flag, the under-build Docker container always uses the `bridge` network.

### Expected result:
I would expect the under-build Docker container to use the network specified by the `--docker-network` option.

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

SAM CLI version: 1.36.0
OS: CentOS 7
AWS region: us-east-2
PackageType: Image

```
$ sam build --docker-network host --debug
2022-01-31 14:01:52,006 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-01-31 14:01:52,006 | Using config file: samconfig.toml, config environment: default
2022-01-31 14:01:52,006 | Expand command line arguments to:
2022-01-31 14:01:52,006 | --template_file=/home/bryan.cornies/repos/git/bids/teamcity-agent-authorizer/template.yaml --docker_network=host --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache
2022-01-31 14:01:52,173 | 'build' command is called
2022-01-31 14:01:52,180 | No Parameters detected in the template
2022-01-31 14:01:52,204 | 2 stacks found in the template
2022-01-31 14:01:52,204 | No Parameters detected in the template
2022-01-31 14:01:52,251 | 2 resources found in the stack
2022-01-31 14:01:52,251 | No Parameters detected in the template
2022-01-31 14:01:52,286 | Found Serverless function with name='TeamCityAgentAuthorizer' and ImageUri='None'
2022-01-31 14:01:52,286 | --base-dir is not presented, adjusting uri ./TeamCityAgentAuthorizer relative to /home/bryan.cornies/repos/git/bids/teamcity-agent-authorizer/template.yaml
2022-01-31 14:01:52,287 | --base-dir is not presented, adjusting uri . relative to /home/bryan.cornies/repos/git/bids/teamcity-agent-authorizer/template.yaml
2022-01-31 14:01:52,287 | No Parameters detected in the template
2022-01-31 14:01:52,327 | Instantiating build definitions
2022-01-31 14:01:52,338 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(None, /home/bryan.cornies/repos/git/bids/teamcity-agent-authorizer, Image, , a9f8019e-0096-44eb-bfcc-2c4be9e5504b, {'DockerTag': 'dev', 'DockerContext': '/home/bryan.cornies/repos/git/bids/teamcity-agent-authorizer/TeamCityAgentAuthorizer', 'Dockerfile': 'Dockerfile'}, {}, x86_64, []), Function: Function(name='TeamCityAgentAuthorizer', functionname='TeamCityAgentAuthorizer', runtime=None, memory=None, timeout=10, handler=None, imageuri=None, packagetype='Image', imageconfig=None, codeuri='/home/bryan.cornies/repos/git/bids/teamcity-agent-authorizer', environment=None, rolearn=None, layers=[], events={'HelloWorld': {'Type': 'Api', 'Properties': {'Path': '/hello', 'Method': 'get', 'RestApiId': 'ServerlessRestApi'}}}, metadata={'DockerTag': 'dev', 'DockerContext': '/home/bryan.cornies/repos/git/bids/teamcity-agent-authorizer/TeamCityAgentAuthorizer', 'Dockerfile': 'Dockerfile'}, inlinecode=None, codesign_config_arn=None, architectures=['x86_64'], stack_path=''))
2022-01-31 14:01:52,339 | Building codeuri: /home/bryan.cornies/repos/git/bids/teamcity-agent-authorizer runtime: None metadata: {'DockerTag': 'dev', 'DockerContext': '/home/bryan.cornies/repos/git/bids/teamcity-agent-authorizer/TeamCityAgentAuthorizer', 'Dockerfile': 'Dockerfile'} architecture: x86_64 functions: ['TeamCityAgentAuthorizer']
2022-01-31 14:01:52,339 | Building to following folder /home/bryan.cornies/repos/git/bids/teamcity-agent-authorizer/.aws-sam/build/TeamCityAgentAuthorizer
2022-01-31 14:01:52,340 | Building image for TeamCityAgentAuthorizer function
2022-01-31 14:01:52,344 | Setting DockerBuildArgs: {} for TeamCityAgentAuthorizer function
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.