-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Description
This is a proposal to build simple, automated container orchestration into Docker, using a file format much like fig.yml. It necessitates several new bits of functionality, some of which have been proposed already (see #7232 and #7576) and some of which need to be separately defined.
I write a Dockerfile.
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
EXPOSE 8000
CMD python app.py
I write a services.yml, which defines images and portable configuration for several services, of the type described in #7576.
web:
image: .
links:
- db
preset: preset-web.yml
db:
image: postgres(Note: this presupposes that a local path can be specified instead of an image repo/tag, and that it will be automatically built.)
I write a preset-web.yml, which defines non-portable runtime configuration for my development environment, as proposed in #7232.
ports:
- 8000:8000
volumes:
- .:/codeI type docker services up and my application starts.
$ docker services up
Reading services from services.yml...
Pulling image "postgres"...
Building image for current directory...
Starting services "db" and "web"...
db | database running
web | Listening on 0.0.0.0:8000
I can run my services in the background by passing the -d flag to docker services up and list them using docker services:
$ docker services up -d
Reading services from services.yml...
Starting services "db" and "web"...
$ docker services
NAME IMAGE CONTAINERS
db postgres 1
web . 1
If I want to run these services in a different environment, I can use a different preset:
$ cat > preset-web-production.yml
ports:
- 80:8000
$ docker services update web --preset=preset-web-production.yml
$ docker services up -d
(Note: this presupposes a service model like that defined in #7576, which stores runtime config persistently.)
I can run one-off containers in the context of a service by passing the --service option to docker run:
$ docker run --service web . env
(Note: it would be nice not to have to re-specify the image / build directory here, but that requires a bit of thought on the design of docker run’s command-line argument format.)
When finished, I can stop all running services:
$ docker services stop