Description
Description of feature
Over the years, there have been a few tickets for docker compose:
- Docker-compose to dokku commands #4953
- Does Dokku have compose support? #4704
- How deploy docker-compose project #3261
- How will docker swarm, machine, compose relate to/change dokku? #1033
As well as an early MR attempt: #1596
I recently - last night when I couldn't sleep - reinvestigated potential support for Compose, and I think we can do it now based on our work with the schedulers plugin as well as the evolution of the compose spec. Here is how it would work:
New plugins
New builder-compose plugin
The builder-compose
plugin will not auto-detect, and is opt-in. Users will have to do select it to use it.
dokku builder:set selected $APP compose
During the build process, we will do the following:
- Fail if there is any use of relative paths in volumes.
- Remove any services with the label
com.dokku.compose=false
.- We could also allow folks to specify a
profile
that we use for builds and such.
- We could also allow folks to specify a
- Rewrite the
image
for any services with abuild
directive so that the image name ends up beingdokku/$APP:latest-$PROCESS_TYPE
.- The
web
process will end up being taggedlatest
. If there are multiple with the same exact build context, they will share the same tag (with the process type being that ofweb
if that is an option or whatever the first is in lexicographical order). - If there is no
web
process, an alternative labelcom.dokku.primary-image=true
can be specified on a service with abuild
context. This will force that - and any others with the same build context - to be thelatest
label. This is mutually exclusive with aweb
process, and the builder will fail if both are specified. - If there is no image that ends up being latest, the builder will fail.
- The
- Add the labels dokku uses internally for tracking images/containers to all the services with a
build
directive. - Run
docker-compose build
Dokku internals will reference the latest
image for extracting files or anything (though usually this happens in post-extract
early on).
We should be able to specify the path to a compose file (for monorepo support) separately from selecting the builder via:
dokku builder-compose:set $APP compose-path $SOME_PATH
This will apply to both the builder and the scheduler.
We can also set buildx support on:
dokku builder-compose:set $APP buildx true
Potential issue is that we can't read and write the yaml file in Golang. I've opened an issue based on this here, so maybe I'm wrong and I'll be able to do this in Go. If not, we'll do the parsing/validation logic in a small python script.
New scheduler-compose plugin
Users will need to opt into this scheduler.
dokku scheduler:set selected $APP compose
This one will take the parsed/validated compose yaml file and run docker compose up
. A user can specify a compose context to schedule apps to ACI or ECS via a scheduler-compose property:
dokku scheduler-compose:set $APP context $CONTEXT
Specifying a context may result in the proxy not working if the context does not use docker-local and the proxy mechanism is something local. We may in the future provide some fancy ingress, but users will be expected to use the networking mechanisms from the context otherwise.
Zero-downtime will be done by using compose's deployment strategies. The naive approach will be just to reload each service in a compose file one by one, which may result in downtime (not sure what compose does, we're just going to be running their commands). A future improvement might be to write our own zero-downtime code (similar to docker-rollout) but that won't be in the initial release. This may result in the proxy not routing to things before it is refreshed until we get to #5101 (but you should be great if you use an alternative proxy layer!), at which point it won't matter :)
Caveats
The above has a few caveats, and we'll consider it experimental going forward. Developers will need to opt into things and new limitations may pop up that I either won't immediately handle or will just be limits of the system. We'll need to make this clear and prominent in the docs.
Nice things
As a side-effect of this, we'll immediately support ACI and ECS, which would give quite a few users the ability to have HA Dokku fairly easily. I think we might even be able to expand this to kompose
support and have a built-in kubernetes plugin in the future.