It would be nice if the Docker container that is started could be configured to optionally use a specific Docker network, and hostname (--network and --hostname options). This allows for more flexibility when interoperability is needed between the lambda and services within other containers on the same system.
I will provide a pull request with implementation.
Sample Code
service: my-service
plugins:
- serverless-offline
provider:
stage: dev
name: aws
runtime: go1.x
region: eu-central-1
functions:
hello:
handler: bin/hello
events:
- http:
method: ANY
path: "{proxy+}"
custom:
serverless-offline:
useDocker: true
network: test
hostname: hellov1
Expected behavior/code
After running sls offline with these options, the started Docker container should be attached to the specified Docker network (test), and/or use the specified hostname (hellov1).
the network option would be useful since I'm running my databases on a docker network
I'm trying to setup a serverless lambda that connects to a local mysql database. After debugging using docker inspect ${containerid} I saw that the serverless-offline containers were placed on the default bridge. Once I knew that, I was able to connect to the database by using the network_mode of bridge on my docker-compose.yml file. The only limitation and that is on the documentation of Docker is that you need to use an IP to access other containers in the same network bridge which is a bit frustrating as that's something that can change on each developer's computer.
It would be great to be able to access other containers through their DNS by specifying a custom network & hostname.
Most helpful comment
the network option would be useful since I'm running my databases on a docker network