Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions blog/2025-03-26-deploying-defang-with-defang-part-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ Some things we had to change:
```yaml
domainname: defang.io
networks:
public:
default:
aliases:
- www.defang.io
```

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.

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!
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!

---

Expand Down
126 changes: 63 additions & 63 deletions docs/concepts/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ sidebar_position: 150

# Compose

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

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.
Expand All @@ -19,20 +19,19 @@ You can create a `compose.yaml` file in the root of your project, or use the [`d
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.

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

```yaml
services:
service-example:
image: nginx:latest # use one of: image (shown on this line) or build (shown below)
# build:
# build:
# context: .
# dockerfile: Dockerfile
ports:
- mode: ingress # specify ports to expose
target: 8080
published: 8080 # this is useful for running locally

ports:
- mode: ingress # specify ports to expose
target: 8080
published: 8080 # this is useful for running locally
```

## Compose Top-level Properties
Expand All @@ -41,26 +40,26 @@ Here are a list of top-level properties of the [Compose specification](https://d
### `services`
(Required)

The services defined in your application.
The services defined in your application.

```yaml
services:
service:
# add service-level properties here
```

:::info
:::info
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.
:::

### `networks`
(Optional)

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

```yaml
networks:
public:
default: # the "default" network is always created even if not specified
```

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

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

## Compose Service-level Properties
Expand All @@ -86,14 +85,14 @@ Here are a list of service-level properties of the [Compose specification](https
Service-level means inside your `service`. A service-level property called `build` would look like:
```yaml
service:
build: ...
build: ...
```

Note that in your Compose file, you will need a top-level property called `services` to contain all of your services. For example:
```yaml
services:
service:
build: ...
service:
build: ...
```
:::

Expand All @@ -103,9 +102,9 @@ services:
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.

```yaml
build:
context: .
dockerfile: ./Dockerfile
build:
context: .
dockerfile: ./Dockerfile
```

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

```yaml
image: nginx:latest
image: nginx:latest
```

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

```yaml
ports:
- mode: ingress
target: 80
published: 80
ports:
- mode: ingress
target: 80
published: 80
```

:::info
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.
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.
:::

### `command`
(Optional)

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

```yaml
command: nginx -g 'daemon off;'
command: nginx -g 'daemon off;'
```

### `deploy`
Expand All @@ -148,34 +147,34 @@ command: nginx -g 'daemon off;'
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.).

```yaml
deploy:
replicas: 1
reservations:
cpus: '0.5'
memory: 256M
deploy:
replicas: 1
reservations:
cpus: '0.5'
memory: 256M
```

### `depends_on`
(Not yet supported)

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

```yaml
# depends_on:
# - db
# depends_on:
# - db
```

### `environment`
(Optional)

The environment variables to set.
```yaml
environment:
DATABASE_USER: someuser
environment:
DATABASE_USER: someuser
```
:::info
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.

For example:
```yaml
- DATABASE_USER=someuser # env var loaded with this literal value
Expand All @@ -191,54 +190,55 @@ For sensitive environment variables (or secret values), you should list the vari
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.

:::note
`curl` is commonly used for containers with an Ubuntu-based image, and `wget` is used for containers with an `alpine`-based image.
`curl` is commonly used for containers with an Ubuntu-based image, and `wget` is used for containers with an `alpine`-based image.
:::

```yaml
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/"]
interval: 30s
timeout: 90s
retries: 3
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/"]
interval: 30s
timeout: 90s
retries: 3
```

or

```yaml
healthcheck:
test: ["CMD", "wget", "--spider", "http://localhost:8080/"]
interval: 30s
timeout: 90s
retries: 3
healthcheck:
test: ["CMD", "wget", "--spider", "http://localhost:8080/"]
interval: 30s
timeout: 90s
retries: 3
```

### `networks`
(Optional)

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.
The service network configuration. By default, Compose will add services to the `default` network, which has external connectivity.
You can also add services to private networks. To avoid warnings, you should add them to the [top-level `networks`](#networks) property as well.

```yaml
networks:
public:
networks:
default: # when not specified, services are assigned to the "default" network
```

You can also assign an alias for a network by using `aliases`, as seen below:
```yaml
networks:
public:
aliases:
- app
networks:
default:
aliases:
- app
```

See our [Networking](/docs/concepts/networking) page for more.

### `restart`
(Optional, but highly recommended)

The restart mode for a container. Defaults to `unless-stopped` unless otherwise specified.
The restart mode for a container. Defaults to `unless-stopped` unless otherwise specified.

```yaml
restart: unless-stopped
restart: unless-stopped
```

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

```yaml
# volumes:
# - "./backend:/app"
# volumes:
# - "./backend:/app"
```
Loading