-
Notifications
You must be signed in to change notification settings - Fork 6
Added supported Compose spec properties #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 23 commits
1f2c25f
dad7e65
e67d4d6
668a4e0
27226b6
88cc6b5
f33e5f9
74685d8
41dd1f9
39917f9
10f37b9
234db8c
77e1296
836ac63
22ff2bb
4220181
57f642a
2faa8d9
c2796f3
793e617
f37f4d0
dbda400
e9f884b
6dd6d01
0b01183
d7e6289
856397b
dd9f070
b66216a
7e602ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,35 +6,257 @@ sidebar_position: 150 | |||||
|
||||||
# Compose | ||||||
|
||||||
You might be familiar with `docker-compose.yml` files, now known as the [Compose specification](https://docs.docker.com/compose/compose-file/) and `compose.yaml` files. It's a simple way to define and run multi-container Docker applications. Defang allows you to use `compose.yaml` files to deploy your application to the cloud. | ||||||
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 come across `docker-compose.yml` files, as both are based on the [Compose specification](https://docs.docker.com/compose/compose-file/). | ||||||
|
||||||
## How it works | ||||||
## How It Works | ||||||
|
||||||
You can define your [services](./services.md) using a `compose.yaml` file in the root of your project, or use the [`defang generate` command](../tutorials/generate-new-code-using-ai.mdx) to generate one (along with other resources). This file is used to define your application's services and how they run. You can edit this file to add more services or change the configuration of existing services. | ||||||
You can create a `compose.yaml` file in the root of your project, or use the [`defang generate`](../tutorials/generate-new-code-using-ai.mdx) command to create one for you (along with other resources). This file is used to define your application's [services](./services.md) and how they run. You can edit this file to add more services or change the configuration of existing services. | ||||||
commit111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
||||||
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. | ||||||
|
||||||
## Service Name Resolution | ||||||
## Example of a Compose File | ||||||
Here is a basic `compose.yaml` file that contains all the required properties for deployment in Defang. | ||||||
|
||||||
One thing to keep in mind is that, at the time of this writing, Defang identifies services by the [user/account name](./accounts.md) and the service name (as defined in the `compose.yaml` file). This means that if you have multiple Defang projects with the same service name, they will conflict with each other. We plan to provide a more robust system for managing service names and protecting against conflicts in the future. | ||||||
```yaml | ||||||
services: | ||||||
service-example: | ||||||
image: nginx:latest # use one of: an image (shown on this line) or a build (shown below) | ||||||
commit111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
# build: | ||||||
# context: . | ||||||
# dockerfile: Dockerfile | ||||||
ports: | ||||||
- mode: ingress # specify ports to expose | ||||||
target: 8080 | ||||||
published: 80 | ||||||
commit111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
||||||
``` | ||||||
|
||||||
## Compose Top-level Properties | ||||||
Here are a list of top-level properties of the [Compose specification](https://docs.docker.com/compose/compose-file/) that Defang supports when writing a `compose.yaml` file. | ||||||
|
||||||
## Configuration | ||||||
### `networks` | ||||||
commit111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
(Optional) | ||||||
|
||||||
If you have a service that depends on a [config value](./configuration.md) (such as an API key), you can set it using the CLI: | ||||||
The networks defined in your application. This is commonly added together with a [service-level `networks`](#networks-1) property. | ||||||
|
||||||
```yaml | ||||||
networks: | ||||||
public: | ||||||
``` | ||||||
defang config set MY_API_KEY | ||||||
|
||||||
commit111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
See our [Networking](/docs/concepts/networking) page for more. | ||||||
|
||||||
### `services` | ||||||
(Required) | ||||||
|
||||||
The services defined in your application. | ||||||
|
||||||
```yaml | ||||||
services: | ||||||
service: | ||||||
# add service-level properties here | ||||||
``` | ||||||
|
||||||
and then connect it to the service by specifying it in the `compose.yaml`: | ||||||
:::info | ||||||
Defang identifies services by the [account username](./accounts.md) and the service name (as defined in the `compose.yaml` file). This means that if you have multiple Defang projects with the same service name, they will conflict with each other. See our [Services](/docs/concepts/services) page for more. | ||||||
|
||||||
::: | ||||||
|
||||||
### `version` | ||||||
(Deprecated) | ||||||
|
||||||
The version of the Compose file format being used. This property is now obsolete, and will be ignored by Defang. | ||||||
|
||||||
```yaml | ||||||
# version: '3' | ||||||
``` | ||||||
|
||||||
commit111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
### `volumes` | ||||||
(Unsupported) | ||||||
commit111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
||||||
The volume mounts for a container, reusable across services. This feature is not currently supported by Defang. | ||||||
|
||||||
```yaml | ||||||
# volumes: | ||||||
# db-data: | ||||||
``` | ||||||
|
||||||
:::warning | ||||||
Defang does not support the `secrets` top-level property. Please read our [Configuration](/docs/concepts/configuration) page for more. | ||||||
::: | ||||||
|
||||||
## Compose Service-level Properties | ||||||
Here are a list of service-level properties of the [Compose specification](https://docs.docker.com/compose/compose-file/) that Defang supports when writing a `compose.yaml` file. | ||||||
|
||||||
:::tip | ||||||
Service-level means inside your `service`. A service-level property called `build` would look like: | ||||||
```yaml | ||||||
service: | ||||||
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: | ||||||
my-service: | ||||||
environment: | ||||||
- MY_API_KEY | ||||||
service: | ||||||
build: ... | ||||||
``` | ||||||
::: | ||||||
|
||||||
### `build` | ||||||
(Required, unless `image` is defined) | ||||||
|
||||||
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 | ||||||
``` | ||||||
|
||||||
### `command` | ||||||
(Optional) | ||||||
|
||||||
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;' | ||||||
``` | ||||||
|
||||||
### `deploy` | ||||||
(Optional) | ||||||
|
||||||
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 | ||||||
``` | ||||||
|
||||||
### `depends_on` | ||||||
(Unsupported) | ||||||
commit111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
||||||
This property describes startup dependencies between services. This feature is currently unsupported by Defang, but can be useful in local developments such as Docker. | ||||||
|
||||||
```yaml | ||||||
# depends_on: | ||||||
# - db | ||||||
``` | ||||||
|
||||||
### `environment` | ||||||
(Optional) | ||||||
|
||||||
The environment variables to set. | ||||||
```yaml | ||||||
environment: | ||||||
DATABASE_USER: someuser | ||||||
DATABASE_PASSWORD: # leave blank/null to set config | ||||||
``` | ||||||
|
||||||
The above uses *map notation*. Defang also supports using *list notation*: | ||||||
```yaml | ||||||
environment: | ||||||
- DATABASE_USER=someuser | ||||||
- DATABASE_PASSWORD | ||||||
commit111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
``` | ||||||
|
||||||
commit111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
:::info | ||||||
Read more about configuration in the [Configuration page](./configuration.md). | ||||||
After you set sensitive environment variables as blank or `null` values in the `compose.yaml` file, you can securely set their actual value in the Defang CLI. See our [Configuration page](/docs/concepts/configuration) for more. | ||||||
|
After you set sensitive environment variables as blank or `null` values in the `compose.yaml` file, you can securely set their actual value in the Defang CLI. See our [Configuration page](/docs/concepts/configuration) for more. | |
After you set sensitive environment variables as blank or `null` values in the `compose.yaml` file, you can securely set their actual value with the Defang CLI. See our [Configuration page](/docs/concepts/configuration) for more. |
Uh oh!
There was an error while loading. Please reload this page.