Skip to content

Commit 182d17b

Browse files
authored
Merge pull request #2090 from brefphp/container-docs
Document single Docker image for all functions
2 parents 83271ea + 45a4406 commit 182d17b

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

docs/deploy/docker.mdx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,54 @@ When running `serverless deploy`, the CLI will:
119119
- Push the newly built Docker image
120120
- Deploy the Lambda function pointing to the Docker image
121121

122-
Note that you can create multiple images in the same `serverless.yml` file. For example, you can have one image for the HTTP handler and another image for a worker.
122+
### Using one image for all functions (recommended)
123+
124+
A major benefit of deploying with Docker is that you can use **a single Docker image** for all your functions (web, console, queues, etc.). Instead of setting `BREF_RUNTIME` in the Dockerfile, set it per function via the `environment` variables in `serverless.yml`:
125+
126+
```dockerfile filename="Dockerfile"
127+
FROM bref/php-84:3
128+
129+
COPY . /var/task
130+
131+
# No BREF_RUNTIME or CMD set here
132+
```
133+
134+
```yml filename="serverless.yml" {5-9,15,21,27}
135+
provider:
136+
name: aws
137+
ecr:
138+
images:
139+
my-app:
140+
path: ./
141+
file: Dockerfile
142+
platform: linux/amd64
143+
144+
functions:
145+
web:
146+
image:
147+
name: my-app
148+
environment:
149+
BREF_RUNTIME: fpm
150+
events:
151+
- httpApi: '*'
152+
153+
console:
154+
image:
155+
name: my-app
156+
environment:
157+
BREF_RUNTIME: console
158+
159+
worker:
160+
image:
161+
name: my-app
162+
environment:
163+
BREF_RUNTIME: function
164+
events:
165+
- sqs:
166+
arn: !GetAtt MyQueue.Arn
167+
```
168+
169+
This simplifies your deployment pipeline: a single Docker image is built and pushed, and each function uses the appropriate runtime.
123170

124171
You can read the detailed documentation about [all options available in the Serverless documentation](https://github.com/oss-serverless/serverless/blob/main/docs/guides/functions.md#referencing-container-image-as-a-target).
125172

0 commit comments

Comments
 (0)