Skip to content

Commit f392b4e

Browse files
committed
Use default network
1 parent 1c96337 commit f392b4e

File tree

2 files changed

+64
-65
lines changed

2 files changed

+64
-65
lines changed

blog/2025-03-26-deploying-defang-with-defang-part-2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ Some things we had to change:
4545
```yaml
4646
domainname: defang.io
4747
networks:
48-
public:
48+
default:
4949
aliases:
5050
- www.defang.io
5151
```
5252
5353
One other hiccup was that we used to do www to non-www redirects using S3. There are a few ways to switch that up, but for the time being we decided to use Next.js middleware.
5454
55-
Pretty soon after that, the site was up and running in an AWS account—with TLS, DNS, and both the `www` and root domains automatically configured. Pretty straightfoward!
55+
Pretty soon after that, the site was up and running in an AWS account—with TLS, DNS, and both the `www` and root domains automatically configured. Pretty straightfoward!
5656

5757
---
5858

docs/concepts/compose.md

Lines changed: 62 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ sidebar_position: 150
66

77
# Compose
88

9-
Defang allows you to use `compose.yaml` files to deploy your application to the cloud.
10-
The `compose.yaml` file is a simple way to define and run multi-container applications.
9+
Defang allows you to use `compose.yaml` files to deploy your application to the cloud.
10+
The `compose.yaml` file is a simple way to define and run multi-container applications.
1111
This file format may look familiar to you if you've used [Docker](https://docker.com).
1212

1313
The [Compose Specification](https://github.com/compose-spec/compose-spec/blob/main/spec.md#compose-file) lets you define a platform-agnostic application designed as a set of containers which are configured to run together with shared resources. These applications may be destined for any [OCI](https://opencontainers.org/) Container Runtime. Defang does the heavy lifting to deploy to your favourite cloud platform using this file.
@@ -19,20 +19,19 @@ You can create a `compose.yaml` file in the root of your project, or use the [`d
1919
When you run `defang compose up`, Defang will read your `compose.yaml` file and [deploy](./deployments.md) the services named in that file to the cloud.
2020

2121
## Example of a Compose File
22-
Here is a basic `compose.yaml` file that contains all the required properties for deployment in Defang.
22+
Here is a basic `compose.yaml` file that contains all the required properties for deployment in Defang.
2323

2424
```yaml
2525
services:
2626
service-example:
2727
image: nginx:latest # use one of: image (shown on this line) or build (shown below)
28-
# build:
28+
# build:
2929
# context: .
3030
# dockerfile: Dockerfile
31-
ports:
32-
- mode: ingress # specify ports to expose
33-
target: 8080
34-
published: 8080 # this is useful for running locally
35-
31+
ports:
32+
- mode: ingress # specify ports to expose
33+
target: 8080
34+
published: 8080 # this is useful for running locally
3635
```
3736
3837
## Compose Top-level Properties
@@ -41,26 +40,26 @@ Here are a list of top-level properties of the [Compose specification](https://d
4140
### `services`
4241
(Required)
4342

44-
The services defined in your application.
43+
The services defined in your application.
4544

4645
```yaml
4746
services:
4847
service:
4948
# add service-level properties here
5049
```
5150

52-
:::info
51+
:::info
5352
Defang identifies a service based on your username, project name, and the service name you've defined under the `services` property. See our [Services](/docs/concepts/services) page for more about how Defang resolves service names.
5453
:::
5554

5655
### `networks`
5756
(Optional)
5857

59-
The networks defined in your application. This is commonly added together with a [service-level `networks`](#networks-1) property.
58+
The networks defined in your application. This is commonly added together with a [service-level `networks`](#networks-1) property.
6059

6160
```yaml
6261
networks:
63-
public:
62+
default: # the "default" network is always created even if not specified
6463
```
6564

6665
See our [Networking](/docs/concepts/networking) page for more.
@@ -76,7 +75,7 @@ The volume mounts for a container, reusable across services. This feature is not
7675
```
7776

7877
:::warning
79-
Defang does not support the `secrets` top-level property. Please read our [Configuration](/docs/concepts/configuration) page for more.
78+
Defang does not support the `secrets` top-level property. Please read our [Configuration](/docs/concepts/configuration) page for more.
8079
:::
8180

8281
## Compose Service-level Properties
@@ -86,14 +85,14 @@ Here are a list of service-level properties of the [Compose specification](https
8685
Service-level means inside your `service`. A service-level property called `build` would look like:
8786
```yaml
8887
service:
89-
build: ...
88+
build: ...
9089
```
9190

9291
Note that in your Compose file, you will need a top-level property called `services` to contain all of your services. For example:
9392
```yaml
9493
services:
95-
service:
96-
build: ...
94+
service:
95+
build: ...
9796
```
9897
:::
9998

@@ -103,9 +102,9 @@ services:
103102
The [build configuration](https://github.com/compose-spec/compose-spec/blob/main/build.md). This property describes how to create an OCI container for this service.
104103

105104
```yaml
106-
build:
107-
context: .
108-
dockerfile: ./Dockerfile
105+
build:
106+
context: .
107+
dockerfile: ./Dockerfile
109108
```
110109

111110
### `image`
@@ -114,7 +113,7 @@ build:
114113
[This property](https://github.com/compose-spec/compose-spec/blob/main/05-services.md#image) describes the image from which your container should start.
115114

116115
```yaml
117-
image: nginx:latest
116+
image: nginx:latest
118117
```
119118

120119
### `ports`
@@ -123,23 +122,23 @@ image: nginx:latest
123122
The ports to expose. The default port mode is `ingress`.
124123

125124
```yaml
126-
ports:
127-
- mode: ingress
128-
target: 80
129-
published: 80
125+
ports:
126+
- mode: ingress
127+
target: 80
128+
published: 80
130129
```
131130

132131
:::info
133-
Defang ignores `published` ports in production. As such, it is common to make `target` and `published` ports the same when using Defang. However, it can be useful to include a `published` port for local development, such as Docker.
132+
Defang ignores `published` ports in production. As such, it is common to make `target` and `published` ports the same when using Defang. However, it can be useful to include a `published` port for local development, such as Docker.
134133
:::
135134

136135
### `command`
137136
(Optional)
138137

139-
The command which will be run to start your service. If left out, the command from the Docker image will be used.
138+
The command which will be run to start your service. If left out, the command from the Docker image will be used.
140139

141140
```yaml
142-
command: nginx -g 'daemon off;'
141+
command: nginx -g 'daemon off;'
143142
```
144143

145144
### `deploy`
@@ -148,34 +147,34 @@ command: nginx -g 'daemon off;'
148147
The [Deploy Specification](https://github.com/compose-spec/compose-spec/blob/main/deploy.md) describes the runtime constraints and requirements for how your services will be deployed and managed across different environments (e.g. memory reservations, replicas, number of CPUs, etc.).
149148

150149
```yaml
151-
deploy:
152-
replicas: 1
153-
reservations:
154-
cpus: '0.5'
155-
memory: 256M
150+
deploy:
151+
replicas: 1
152+
reservations:
153+
cpus: '0.5'
154+
memory: 256M
156155
```
157156

158157
### `depends_on`
159158
(Not yet supported)
160159

161-
This property describes startup dependencies between services. This feature is currently unsupported by Defang, but can be useful in local developments such as Docker.
160+
This property describes startup dependencies between services. This feature currently has limited supported by Defang, but can be useful in local development with Docker.
162161

163162
```yaml
164-
# depends_on:
165-
# - db
163+
# depends_on:
164+
# - db
166165
```
167166

168167
### `environment`
169168
(Optional)
170169

171170
The environment variables to set.
172171
```yaml
173-
environment:
174-
DATABASE_USER: someuser
172+
environment:
173+
DATABASE_USER: someuser
175174
```
176175
:::info
177176
For sensitive environment variables (or secret values), you should list the variable's name with a blank or `null` value, and then securely set their actual value with `defang config` in the CLI. See our [Configuration page](/docs/concepts/configuration) for more.
178-
177+
179178
For example:
180179
```yaml
181180
- DATABASE_USER=someuser # env var loaded with this literal value
@@ -191,54 +190,54 @@ For sensitive environment variables (or secret values), you should list the vari
191190
When using Defang, your Compose file must have a healthcheck if you want to expose an `ingress` port—even if your Dockerfile already contains one.
192191

193192
:::note
194-
`curl` is commonly used for containers with an Ubuntu-based image, and `wget` is used for containers with an `alpine`-based image.
193+
`curl` is commonly used for containers with an Ubuntu-based image, and `wget` is used for containers with an `alpine`-based image.
195194
:::
196195

197196
```yaml
198-
healthcheck:
199-
test: ["CMD", "curl", "-f", "http://localhost:8080/"]
200-
interval: 30s
201-
timeout: 90s
202-
retries: 3
197+
healthcheck:
198+
test: ["CMD", "curl", "-f", "http://localhost:8080/"]
199+
interval: 30s
200+
timeout: 90s
201+
retries: 3
203202
```
204203

205204
or
206205

207206
```yaml
208-
healthcheck:
209-
test: ["CMD", "wget", "--spider", "http://localhost:8080/"]
210-
interval: 30s
211-
timeout: 90s
212-
retries: 3
207+
healthcheck:
208+
test: ["CMD", "wget", "--spider", "http://localhost:8080/"]
209+
interval: 30s
210+
timeout: 90s
211+
retries: 3
213212
```
214213

215214
### `networks`
216215
(Optional)
217216

218-
The network configuration. Can be `public`, where Defang will assign a public IP address, or `private`, in which Defang will not. To avoid warnings, add this to the [top-level `networks`](#networks) property as well.
217+
The network configuration. Can be `public`, where Defang will assign a public IP address, or `private`, in which Defang will not. To avoid warnings, add this to the [top-level `networks`](#networks) property as well.
219218

220219
```yaml
221-
networks:
222-
public:
220+
networks:
221+
default: # when not specified, services are assigned to the default network
223222
```
224223

225224
You can also assign an alias for a network by using `aliases`, as seen below:
226225
```yaml
227-
networks:
228-
public:
229-
aliases:
230-
- app
226+
networks:
227+
default:
228+
aliases:
229+
- app
231230
```
232-
231+
233232
See our [Networking](/docs/concepts/networking) page for more.
234-
233+
235234
### `restart`
236235
(Optional, but highly recommended)
237236

238-
The restart mode for a container. Defaults to `unless-stopped` unless otherwise specified.
237+
The restart mode for a container. Defaults to `unless-stopped` unless otherwise specified.
239238

240239
```yaml
241-
restart: unless-stopped
240+
restart: unless-stopped
242241
```
243242

244243
### `volumes`
@@ -247,6 +246,6 @@ restart: unless-stopped
247246
The volume mounts for a container, specific to a service. This feature is not currently supported by Defang.
248247

249248
```yaml
250-
# volumes:
251-
# - "./backend:/app"
249+
# volumes:
250+
# - "./backend:/app"
252251
```

0 commit comments

Comments
 (0)