File: compose/compose-file.md
Is there a doc in the works for version 3 of the compose file ref used in 1.13RC1 'docker deploy --compose-file=blah.yml'? It's hard to test the RC without knowing if my syntax is good.
@dnephin @nathanleclaire can you jump in here? We do have https://github.com/docker/docker.github.io/tree/vnext-compose/compose, but I don't believe much has changed there.
I have https://github.com/docker/docker/issues/28414 filed as an issue about this. There's just enough differences to be slightly infuriating, but it's pretty similar to v2. https://github.com/docker/docker.github.io/pull/672/files?short_path=ec87c9f#diff-ec87c9ff41f9b95df292d0b48170db4f is a start, meanwhile maybe I'll take a look at translating the classic Compose redis-python example.
Alright here's an example. This is the "swarm-ified" version of the classic Python-and-Redis compose app.
(I made a git repo you could easily clone for this as well)
Place Dockerfile in a new directory:
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD python app.py
and app.py:
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
@app.route('/')
def hello():
redis.incr('hits')
return 'Hello World! I have been seen %s times.' % redis.get('hits')
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
and requirements.txt:
redis
The Compose file is pretty similar. Main difference is that you shouldn't have build I think.
version: '3'
networks:
pyweb:
driver: overlay
services:
web:
image: nathanleclaire/pyweb
ports:
- "5000:5000"
networks:
- pyweb
volumes:
- .:/code
redis:
image: redis
networks:
- pyweb
docker deploy automatically converts volumes key to swarm mode service --mounts so the old standby for bind mounting still works.
docker commands to deploy the serviceUse docker deploy to deploy the Compose file and docker stack to manage the created "stacks".
$ docker deploy --compose-file docker-compose.yml pyweb
Creating network pyweb_pyweb
Creating network pyweb_default
Creating service pyweb_redis
Creating service pyweb_web
$ curl localhost:5000; echo
Hello World! I have been seen 1 times.
$ docker service ls
ID NAME MODE REPLICAS IMAGE
9qzad1wj88p8 pyweb_redis replicated 1/1 redis:latest
xrabnouskr3t pyweb_web replicated 1/1 nathanleclaire/pyweb
$ docker stack ls
NAME SERVICES
pyweb 2
$ docker stack rm pyweb
Removing service pyweb_redis
Removing service pyweb_web
Removing network pyweb_pyweb
Removing network pyweb_default
that's the basic gist. you can see available "schemas" for the Compose V3 keys here, including previously supported but (for now) unsupported ones.
good times looks like you can set service properties such as replicas in a deploy key.
e.g.:
services:
web:
image: nathanleclaire/pyweb
deploy:
replicas: 3
ports:
- "5000:5000"
networks:
- pyweb
volumes:
- .:/code
lots of these around, e.g., UlimitsConfig (I'm assuming meant to be unmarshalled from ulimits_config), not sure how many are supported first class, but if you read the schema types in that linked file, you can work your way backwards how to translate swarm settings into the file version.
@nathanleclaire this is great, thanks! I'll make the updates and ping you for review when they are ready.
I believe this is addressed by the linked PR's, so I'm closing this issue. Please re-open if needed. Thanks for the feedback.