Skip to content

Commit

Permalink
ENGDOCS-2320 (#21463)
Browse files Browse the repository at this point in the history
<!--Delete sections as needed -->

## Description

A few new Compose Spec additions 
https://docker.atlassian.net/browse/ENGDOCS-2320

## Related issues or tickets

<!-- Related issues, pull requests, or Jira tickets -->

## Reviews

<!-- Notes for reviewers here -->
<!-- List applicable reviews (optionally @tag reviewers) -->

- [ ] Technical review
- [ ] Editorial review
- [ ] Product review

---------

Co-authored-by: David Karlsson <[email protected]>
  • Loading branch information
aevesdocker and dvdksn authored Nov 20, 2024
1 parent 0de58f3 commit aa68ba2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ The paths to your `.env` file, specified in the `env_file` attribute, are relati
- path: ./override.env
required: false
```
- As of Docker Compose version 2.30.0, you can use an alternative file format for the `env_file` with the `format` attribute. For more information, see [`format`](/reference/compose-file/services.md#format).
- Values in your `.env` file can be overridden from the command line by using [`docker compose run -e`](#set-environment-variables-with-docker-compose-run---env).

## Set environment variables with `docker compose run --env`
Expand Down
4 changes: 4 additions & 0 deletions content/reference/compose-file/interpolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Interpolation can also be nested:
Other extended shell-style features, such as `${VARIABLE/foo/bar}`, are not
supported by Compose.

Compose processes any string following a `$` sign as long as it makes it
a valid variable definition - either an alphanumeric name (`[_a-zA-Z][_a-zA-Z0-9]*`)
or a braced string starting with `${`. In other circumstances, it will be preserved without attempting to interpolate a value.

You can use a `$$` (double-dollar sign) when your configuration needs a literal
dollar sign. This also prevents Compose from interpolating a value, so a `$$`
allows you to refer to environment variables that you don't want processed by
Expand Down
56 changes: 44 additions & 12 deletions content/reference/compose-file/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@ i.e. overridden to be empty.
env_file: .env
```

Relative paths are resolved from the Compose file's parent folder. As absolute paths prevent the Compose
file from being portable, Compose warns you when such a path is used to set `env_file`.

Environment variables declared in the [environment](#environment) section override these values. This holds true even if those values are
empty or undefined.

`env_file` can also be a list. The files in the list are processed from the top down. For the same variable
specified in two env files, the value from the last file in the list stands.

Expand All @@ -627,9 +633,14 @@ env_file:
- ./b.env
```

List elements can also be declared as a mapping, which then lets you set an additional
attribute `required`. This defaults to `true`. When `required` is set to `false` and the `.env` file is missing,
Compose silently ignores the entry.
List elements can also be declared as a mapping, which then lets you set additional
attributes.

#### required

{{< introduced compose 2.24.0 "/manuals/compose/releases/release-notes.md#2240" >}}

The `required` attribute defaults to `true`. When `required` is set to `false` and the `.env` file is missing, Compose silently ignores the entry.

```yml
env_file:
Expand All @@ -638,13 +649,21 @@ env_file:
- path: ./override.env
required: false
```
> `required` attribute is available with Docker Compose version 2.24.0 or later.

Relative path are resolved from the Compose file's parent folder. As absolute paths prevent the Compose
file from being portable, Compose warns you when such a path is used to set `env_file`.
#### format

Environment variables declared in the [environment](#environment) section override these values. This holds true even if those values are
empty or undefined.
{{< introduced compose 2.30.0 "/manuals/compose/releases/release-notes.md#2300" >}}

The `format` attribute lets you use an alternative file format for the `env_file`. When not set, `env_file` is parsed according to the Compose rules outlined in [Env_file format](#env_file-format).

`raw` format lets you use an `env_file` with key=value items, but without any attempt from Compose to parse the value for interpolation.
This let you pass values as-is, including quotes and `$` signs.

```yml
env_file:
- path: ./default.env
format: raw
```

#### Env_file format

Expand Down Expand Up @@ -1772,13 +1791,26 @@ parameters (sysctls) at runtime](/reference/cli/docker/container/run.md#sysctl).
`tmpfs` mounts a temporary file system inside the container. It can be a single value or a list.

```yml
tmpfs: /run
tmpfs:
- <path>
- <path>:<options>
```

- <path>: The path inside the container where the tmpfs will be mounted.
- <options>: Comma-separated list of options for the tmpfs mount.

Available options:

- `mode`: Sets the file system permissions.
- `uid`: Sets the user ID that owns the mounted tmpfs.
- `gid`: Sets the group ID that owns the mounted tmpfs.

```yml
tmpfs:
- /run
- /tmp
services:
app:
tmpfs:
- /data:mode=755,uid=1009,gid=1009
- /run
```

### tty
Expand Down

0 comments on commit aa68ba2

Please sign in to comment.