|
| 1 | +--- |
| 2 | +title: Using Docker Compose with OCI artifacts |
| 3 | +linkTitle: Use Compose OCI artifacts applications |
| 4 | +weight: 20 |
| 5 | +description: How to start and publish Compose applications as OCI artifacts |
| 6 | +keywords: cli, compose, oci |
| 7 | +aliases: |
| 8 | +- /compose/oci-artifact/ |
| 9 | +--- |
| 10 | + |
| 11 | +{{% include "compose/oci-artifact.md" %}} |
| 12 | + |
| 13 | +## Starting an OCI artifact application |
| 14 | + |
| 15 | +To start a Docker Compose application using an OCI artifact, you can use the `-f` (or `--file`) flag followed by the OCI artifact reference. |
| 16 | +This allows you to specify a Compose file stored as an OCI artifact in a registry. |
| 17 | +The `oci://` prefix indicates that the Compose file should be pulled from an OCI-compliant registry rather than loaded from the local filesystem. |
| 18 | + |
| 19 | +```bash |
| 20 | +$ docker compose -f oci://docker.io/username/my-compose-app:latest up |
| 21 | +``` |
| 22 | + |
| 23 | +To run the Compose application, use the `docker compose` command with the `-f` flag pointing to your OCI artifact: |
| 24 | +```bash |
| 25 | +$ docker compose -f oci://docker.io/username/my-compose-app:latest up |
| 26 | +``` |
| 27 | + |
| 28 | +### Warnings/Messages displayed |
| 29 | + |
| 30 | +When you run an application from an OCI artifact, Compose may display warning messages requiring your confirmation to limit risks of running a malicious application: |
| 31 | +* Listing the interpolation variables used along with their values |
| 32 | +* Listing all environment variables used by the application |
| 33 | +* Let you know if your OCI artifact application is using another remote resources (via [`include`](/reference/compose-file/include/) for example) |
| 34 | + |
| 35 | +```bash |
| 36 | +$ REGISTRY=myregistry.com docker compose -f oci://docker.io/username/my-compose-app:latest up |
| 37 | + |
| 38 | +Found the following variables in configuration: |
| 39 | +VARIABLE VALUE SOURCE REQUIRED DEFAULT |
| 40 | +REGISTRY myregistry.com command-line yes |
| 41 | +TAG v1.0 environment no latest |
| 42 | +DOCKERFILE Dockerfile default no Dockerfile |
| 43 | +API_KEY <unset> none no |
| 44 | + |
| 45 | +Do you want to proceed with these variables? [Y/n]:y |
| 46 | + |
| 47 | +Warning: This Compose project includes files from remote sources: |
| 48 | +- oci://registry.example.com/stack:latest |
| 49 | +Remote includes could potentially be malicious. Make sure you trust the source. |
| 50 | +Do you want to continue? [y/N]: |
| 51 | +``` |
| 52 | + |
| 53 | +If you agree to start the application, Compose will display the directory where all the resources from the OCI artifact have been downloaded. |
| 54 | +```bash |
| 55 | +... |
| 56 | +Do you want to continue? [y/N]: y |
| 57 | + |
| 58 | +Your compose stack "oci://registry.example.com/stack:latest" is stored in "~/Library/Caches/docker-compose/964e715660d6f6c3b384e05e7338613795f7dcd3613890cfa57e3540353b9d6d" |
| 59 | +``` |
| 60 | +--- |
| 61 | + |
| 62 | +## Publishing your Compose application as an OCI artifact |
| 63 | + |
| 64 | +To distribute your Compose application as an OCI artifact, you can **publish** it to an OCI-compliant registry. |
| 65 | +This allows others to deploy your application directly from the registry. |
| 66 | + |
| 67 | +The publish function supports most of the composition capabilities of Compose, like overrides, extends or include, [with some limitations](#limitations-and-considerations) |
| 68 | + |
| 69 | +### Steps |
| 70 | + |
| 71 | +1. Navigate to Your Compose Application Directory |
| 72 | + Ensure you're in the directory containing your `compose.yml` file or that you are specifying your Compose file with the `-f` flag. |
| 73 | + |
| 74 | +2. Log in to Docker Hub |
| 75 | + Before publishing, make sure you're authenticated with Docker Hub: |
| 76 | + |
| 77 | + ```bash |
| 78 | + $ docker login |
| 79 | + ``` |
| 80 | + |
| 81 | +3. Publish the Compose application to Docker Hub |
| 82 | + Use the `docker compose publish` command to push your application as an OCI artifact: |
| 83 | + |
| 84 | + ```bash |
| 85 | + $ docker compose publish username/my-compose-app:latest |
| 86 | + ``` |
| 87 | + or passing multiple Compose files |
| 88 | + ```bash |
| 89 | + $ docker compose -f compose-base.yml -f compose-production.yml publish username/my-compose-app:latest |
| 90 | + ``` |
| 91 | +When publishing you can use options to specify the OCI version, whether to resolve image digests and if you want to include environment variables: |
| 92 | +* `--oci-version`: Specify the OCI version (default is automatically determined). |
| 93 | +* `--resolve-image-digests`: Pin image tags to digests. |
| 94 | +* `--with-env`: Include environment variables in the published OCI artifact. |
| 95 | + |
| 96 | +Compose checks for you if there isn't any sensitive data in your configuration and displays your environment variables to confirm you want to publish them. |
| 97 | + |
| 98 | +```bash |
| 99 | +... |
| 100 | +you are about to publish sensitive data within your OCI artifact. |
| 101 | +please double check that you are not leaking sensitive data |
| 102 | +AWS Client ID |
| 103 | +"services.serviceA.environment.AWS_ACCESS_KEY_ID": xxxxxxxxxx |
| 104 | +AWS Secret Key |
| 105 | +"services.serviceA.environment.AWS_SECRET_ACCESS_KEY": aws"xxxx/xxxx+xxxx+" |
| 106 | +Github authentication |
| 107 | +"GITHUB_TOKEN": ghp_xxxxxxxxxx |
| 108 | +JSON Web Token |
| 109 | +"": xxxxxxx.xxxxxxxx.xxxxxxxx |
| 110 | +Private Key |
| 111 | +"": -----BEGIN DSA PRIVATE KEY----- |
| 112 | +xxxxx |
| 113 | +-----END DSA PRIVATE KEY----- |
| 114 | +Are you ok to publish these sensitive data? [y/N]:y |
| 115 | + |
| 116 | +you are about to publish environment variables within your OCI artifact. |
| 117 | +please double check that you are not leaking sensitive data |
| 118 | +Service/Config serviceA |
| 119 | +FOO=bar |
| 120 | +Service/Config serviceB |
| 121 | +FOO=bar |
| 122 | +QUIX= |
| 123 | +BAR=baz |
| 124 | +Are you ok to publish these environment variables? [y/N]: |
| 125 | +``` |
| 126 | + |
| 127 | +If you refuse the publish process will stop without sending anything to the registry. |
| 128 | + |
| 129 | +--- |
| 130 | + |
| 131 | +## Limitations and considerations |
| 132 | + |
| 133 | +There is limitations to publishing Compose applications as OCI artifacts: |
| 134 | +* You can't publish Compose configuration with service(s) containing bind mounts |
| 135 | +* You can't publish Compose configuration with service(s) containing only `build` section |
| 136 | +* You can't publish Compose configuration using `include` of local files, publish them as well as remote `include` is supported |
0 commit comments