mirror of
https://github.com/docker/compose.git
synced 2026-02-12 19:49:22 +08:00
Compare commits
274 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39ae91c81c | ||
|
|
b6acb3cd8c | ||
|
|
a467a8a094 | ||
|
|
78227c3c06 | ||
|
|
e4e802d1f8 | ||
|
|
b24a60ba9f | ||
|
|
461b600068 | ||
|
|
9aab7bc242 | ||
|
|
83dcceacaf | ||
|
|
1f06070f12 | ||
|
|
35c6e0314c | ||
|
|
276e43ca6b | ||
|
|
b7046777d1 | ||
|
|
1c14fc06da | ||
|
|
f4ef2c09d6 | ||
|
|
16495c577b | ||
|
|
965426e39b | ||
|
|
02f119e4b7 | ||
|
|
721327110d | ||
|
|
d209ded13c | ||
|
|
49c2080bcd | ||
|
|
37efdb1f8b | ||
|
|
4c582e4352 | ||
|
|
5dca6c232e | ||
|
|
eef4bc3917 | ||
|
|
9931cd2c4c | ||
|
|
0226675766 | ||
|
|
ae9c965823 | ||
|
|
d7a90092c2 | ||
|
|
85fb8956f3 | ||
|
|
1e5b9dc2eb | ||
|
|
d21b8f1ba3 | ||
|
|
4c5a80f253 | ||
|
|
198598c936 | ||
|
|
8b5a882459 | ||
|
|
dae451019b | ||
|
|
dfc729b8f2 | ||
|
|
eb7ea76d6c | ||
|
|
3c8ef6a94c | ||
|
|
081afd9bbf | ||
|
|
528bed9ef6 | ||
|
|
4ecf5e01ff | ||
|
|
81a32a266f | ||
|
|
25c70c2af4 | ||
|
|
7b1f01bb52 | ||
|
|
c23189a5fa | ||
|
|
86b723e227 | ||
|
|
2534a0964f | ||
|
|
42e6296b0e | ||
|
|
74440b2f92 | ||
|
|
95f4e2c7c3 | ||
|
|
9e9a66f0f8 | ||
|
|
300234429c | ||
|
|
3384bc5fcf | ||
|
|
08f936b2e7 | ||
|
|
df925bc759 | ||
|
|
33c7b3f752 | ||
|
|
ac7a97f420 | ||
|
|
d5fcb0de67 | ||
|
|
f47431d591 | ||
|
|
8610adcaf3 | ||
|
|
8f38b28816 | ||
|
|
db3b4731cd | ||
|
|
30b7c22c71 | ||
|
|
f89f9e3190 | ||
|
|
f1fc1d7a16 | ||
|
|
0e30d0085b | ||
|
|
98f32a21e7 | ||
|
|
fa195bc829 | ||
|
|
882dc673ce | ||
|
|
44f5a3ea46 | ||
|
|
ac4e800763 | ||
|
|
2e57575a61 | ||
|
|
03535a6158 | ||
|
|
c41342501b | ||
|
|
4ac02bfca6 | ||
|
|
35d5d1a5b1 | ||
|
|
72003de737 | ||
|
|
a0db5bee3e | ||
|
|
59c45e3398 | ||
|
|
ea8364fd11 | ||
|
|
cf6b09e94b | ||
|
|
66555aa69b | ||
|
|
bb943d5cb5 | ||
|
|
178c50d46f | ||
|
|
32cdabefc2 | ||
|
|
5b07c581e0 | ||
|
|
17bbb9d357 | ||
|
|
ec2966222a | ||
|
|
8076c7d7fe | ||
|
|
b2425c1f1e | ||
|
|
34c6920b37 | ||
|
|
8d8dd37d2c | ||
|
|
b1739e703b | ||
|
|
a42f2007ea | ||
|
|
1dd5ef4133 | ||
|
|
c3215a1764 | ||
|
|
bd320b19fe | ||
|
|
0fa0131372 | ||
|
|
a7fe67e691 | ||
|
|
f78dfa7958 | ||
|
|
d95de03de9 | ||
|
|
e3eccd1047 | ||
|
|
d32994c250 | ||
|
|
a516d61b49 | ||
|
|
6eb1c8896f | ||
|
|
160e2dc7b9 | ||
|
|
5e8bcd2d29 | ||
|
|
2eb20d89af | ||
|
|
ab65c829ea | ||
|
|
83110b8e6b | ||
|
|
3a8a25b9b3 | ||
|
|
0a8f9abfae | ||
|
|
3146fe5e4b | ||
|
|
4a33686787 | ||
|
|
64239f1408 | ||
|
|
c39a0b0a2d | ||
|
|
8a7b3fb0eb | ||
|
|
4251f2b732 | ||
|
|
9f4775c554 | ||
|
|
7ff607fb7a | ||
|
|
b25ed59b1c | ||
|
|
eabca3d7b7 | ||
|
|
45b8d526ba | ||
|
|
75247e5a54 | ||
|
|
2cf1fa6c9d | ||
|
|
3b7ea5c055 | ||
|
|
461f1ad5d5 | ||
|
|
2307adc4b2 | ||
|
|
d8d0fd6dc9 | ||
|
|
e4d6a2c240 | ||
|
|
deb2de3c07 | ||
|
|
bc1f6c97d8 | ||
|
|
7c087f1c07 | ||
|
|
fd30920aac | ||
|
|
9bc7604e0e | ||
|
|
de07e0471e | ||
|
|
dfc6206d0d | ||
|
|
6c45b6ccdb | ||
|
|
d79dc85fa5 | ||
|
|
22aca1a8a5 | ||
|
|
74302560f5 | ||
|
|
bc2f6044fd | ||
|
|
1476027410 | ||
|
|
28fa49e569 | ||
|
|
27e4f982fa | ||
|
|
0bc4a28dcc | ||
|
|
bd535c76d0 | ||
|
|
ef027599f7 | ||
|
|
f1e4fb7736 | ||
|
|
df3221df61 | ||
|
|
43fdae8bc6 | ||
|
|
4869fed97f | ||
|
|
16d6018419 | ||
|
|
8297f55f2c | ||
|
|
724be54f09 | ||
|
|
e3c4a662d9 | ||
|
|
c981ce929a | ||
|
|
620e29b63f | ||
|
|
2af7693e64 | ||
|
|
7be8b4c06d | ||
|
|
cbd3ca07c4 | ||
|
|
edb6b24b8f | ||
|
|
608f29c7cb | ||
|
|
37ed743ee8 | ||
|
|
17a8a7be4b | ||
|
|
f57db078ba | ||
|
|
2dd1cc80ca | ||
|
|
55095ef488 | ||
|
|
7eb476e61d | ||
|
|
72095f54b2 | ||
|
|
26f45efea2 | ||
|
|
4827e60641 | ||
|
|
74a0c47389 | ||
|
|
aa0c43df96 | ||
|
|
4ef2e21cca | ||
|
|
3ee8437eaa | ||
|
|
b903217a4a | ||
|
|
2406a3936a | ||
|
|
69db596b5d | ||
|
|
9a90a27376 | ||
|
|
a2f3c0b5da | ||
|
|
3b638f0c43 | ||
|
|
b252300e94 | ||
|
|
be553e393a | ||
|
|
91c90a722a | ||
|
|
d399d386ae | ||
|
|
4cb47e498b | ||
|
|
3056ae4be3 | ||
|
|
5b777ee5f1 | ||
|
|
c885aaa5f8 | ||
|
|
4257707244 | ||
|
|
70c3676084 | ||
|
|
e89826fe43 | ||
|
|
0e172228d1 | ||
|
|
cb1a5e0a24 | ||
|
|
3c105c6db2 | ||
|
|
5182bd0968 | ||
|
|
200c44cff3 | ||
|
|
05544ce241 | ||
|
|
cc834aa564 | ||
|
|
a5505e7711 | ||
|
|
8f8e322de2 | ||
|
|
64762c9dea | ||
|
|
8ebec9a67f | ||
|
|
45b2712032 | ||
|
|
3c0f297ba6 | ||
|
|
c0123c7477 | ||
|
|
2a0782c660 | ||
|
|
481a8cb7ab | ||
|
|
788741025e | ||
|
|
c12d1d73f0 | ||
|
|
e794e79209 | ||
|
|
98b6d7be78 | ||
|
|
a12cf826cd | ||
|
|
d18cfa1c98 | ||
|
|
9a04ae0ddf | ||
|
|
ab77cef7ab | ||
|
|
5c58180538 | ||
|
|
429a3feabc | ||
|
|
1033439e63 | ||
|
|
e9d946b038 | ||
|
|
4e8337c168 | ||
|
|
e34a62956e | ||
|
|
0150b38b8f | ||
|
|
bb85e238e0 | ||
|
|
65ae22e79a | ||
|
|
04da6b035e | ||
|
|
d3e94f2caf | ||
|
|
4f6d02867b | ||
|
|
f98323b79e | ||
|
|
3f4b16181d | ||
|
|
5dde2a2498 | ||
|
|
06a1b32c12 | ||
|
|
46433c70b6 | ||
|
|
9260603149 | ||
|
|
9abdd337b5 | ||
|
|
8773f51583 | ||
|
|
38a3ee8d63 | ||
|
|
cb275b8633 | ||
|
|
604b370bb4 | ||
|
|
782a46fd60 | ||
|
|
1bd3d0dd77 | ||
|
|
b64ea85916 | ||
|
|
b47ab2b0f6 | ||
|
|
11280e4f30 | ||
|
|
a83876da09 | ||
|
|
e66c0452d5 | ||
|
|
899670fc6c | ||
|
|
ea45715a50 | ||
|
|
28f9c8d047 | ||
|
|
292fe6640e | ||
|
|
b759b9854a | ||
|
|
40943d5c81 | ||
|
|
93a0195dc8 | ||
|
|
7f0745d146 | ||
|
|
9813a8d5be | ||
|
|
491181ec31 | ||
|
|
e1ad5b1b99 | ||
|
|
67d4b7c587 | ||
|
|
98f663bab2 | ||
|
|
75b3dcf5fd | ||
|
|
deeb6c2236 | ||
|
|
c838f7da18 | ||
|
|
e1e2b75691 | ||
|
|
392c118bbc | ||
|
|
dbd1e56dd3 | ||
|
|
7544580b4b | ||
|
|
2efb4f5be0 | ||
|
|
5e8dc6c972 | ||
|
|
23c8ec8930 | ||
|
|
bd8affb7aa | ||
|
|
7a943739cb | ||
|
|
d3f88cace5 |
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@@ -0,0 +1,2 @@
|
||||
.git
|
||||
venv
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,4 +5,4 @@
|
||||
/dist
|
||||
/docs/_site
|
||||
/venv
|
||||
fig.spec
|
||||
docker-compose.spec
|
||||
|
||||
67
CHANGES.md
67
CHANGES.md
@@ -1,7 +1,70 @@
|
||||
Change log
|
||||
==========
|
||||
|
||||
1.0.0 (2014-10-07)
|
||||
1.2.0 (2015-04-16)
|
||||
------------------
|
||||
|
||||
- `docker-compose.yml` now supports an `extends` option, which enables a service to inherit configuration from another service in another configuration file. This is really good for sharing common configuration between apps, or for configuring the same app for different environments. Here's the [documentation](https://github.com/docker/compose/blob/master/docs/yml.md#extends).
|
||||
|
||||
- When using Compose with a Swarm cluster, containers that depend on one another will be co-scheduled on the same node. This means that most Compose apps will now work out of the box, as long as they don't use `build`.
|
||||
|
||||
- Repeated invocations of `docker-compose up` when using Compose with a Swarm cluster now work reliably.
|
||||
|
||||
- Directories passed to `build`, filenames passed to `env_file` and volume host paths passed to `volumes` are now treated as relative to the *directory of the configuration file*, not the directory that `docker-compose` is being run in. In the majority of cases, those are the same, but if you use the `-f|--file` argument to specify a configuration file in another directory, **this is a breaking change**.
|
||||
|
||||
- A service can now share another service's network namespace with `net: container:<service>`.
|
||||
|
||||
- `volumes_from` and `net: container:<service>` entries are taken into account when resolving dependencies, so `docker-compose up <service>` will correctly start all dependencies of `<service>`.
|
||||
|
||||
- `docker-compose run` now accepts a `--user` argument to specify a user to run the command as, just like `docker run`.
|
||||
|
||||
- The `up`, `stop` and `restart` commands now accept a `--timeout` (or `-t`) argument to specify how long to wait when attempting to gracefully stop containers, just like `docker stop`.
|
||||
|
||||
- `docker-compose rm` now accepts `-f` as a shorthand for `--force`, just like `docker rm`.
|
||||
|
||||
Thanks, @abesto, @albers, @alunduil, @dnephin, @funkyfuture, @gilclark, @IanVS, @KingsleyKelly, @knutwalker, @thaJeztah and @vmalloc!
|
||||
|
||||
1.1.0 (2015-02-25)
|
||||
------------------
|
||||
|
||||
Fig has been renamed to Docker Compose, or just Compose for short. This has several implications for you:
|
||||
|
||||
- The command you type is now `docker-compose`, not `fig`.
|
||||
- You should rename your fig.yml to docker-compose.yml.
|
||||
- If you’re installing via PyPi, the package is now `docker-compose`, so install it with `pip install docker-compose`.
|
||||
|
||||
Besides that, there’s a lot of new stuff in this release:
|
||||
|
||||
- We’ve made a few small changes to ensure that Compose will work with Swarm, Docker’s new clustering tool (https://github.com/docker/swarm). Eventually you'll be able to point Compose at a Swarm cluster instead of a standalone Docker host and it’ll run your containers on the cluster with no extra work from you. As Swarm is still developing, integration is rough and lots of Compose features don't work yet.
|
||||
|
||||
- `docker-compose run` now has a `--service-ports` flag for exposing ports on the given service. This is useful for e.g. running your webapp with an interactive debugger.
|
||||
|
||||
- You can now link to containers outside your app with the `external_links` option in docker-compose.yml.
|
||||
|
||||
- You can now prevent `docker-compose up` from automatically building images with the `--no-build` option. This will make fewer API calls and run faster.
|
||||
|
||||
- If you don’t specify a tag when using the `image` key, Compose will default to the `latest` tag, rather than pulling all tags.
|
||||
|
||||
- `docker-compose kill` now supports the `-s` flag, allowing you to specify the exact signal you want to send to a service’s containers.
|
||||
|
||||
- docker-compose.yml now has an `env_file` key, analogous to `docker run --env-file`, letting you specify multiple environment variables in a separate file. This is great if you have a lot of them, or if you want to keep sensitive information out of version control.
|
||||
|
||||
- docker-compose.yml now supports the `dns_search`, `cap_add`, `cap_drop`, `cpu_shares` and `restart` options, analogous to `docker run`’s `--dns-search`, `--cap-add`, `--cap-drop`, `--cpu-shares` and `--restart` options.
|
||||
|
||||
- Compose now ships with Bash tab completion - see the installation and usage docs at https://github.com/docker/compose/blob/1.1.0/docs/completion.md
|
||||
|
||||
- A number of bugs have been fixed - see the milestone for details: https://github.com/docker/compose/issues?q=milestone%3A1.1.0+
|
||||
|
||||
Thanks @dnephin, @squebe, @jbalonso, @raulcd, @benlangfield, @albers, @ggtools, @bersace, @dtenenba, @petercv, @drewkett, @TFenby, @paulRbr, @Aigeruth and @salehe!
|
||||
|
||||
1.0.1 (2014-11-04)
|
||||
------------------
|
||||
|
||||
- Added an `--allow-insecure-ssl` option to allow `fig up`, `fig run` and `fig pull` to pull from insecure registries.
|
||||
- Fixed `fig run` not showing output in Jenkins.
|
||||
- Fixed a bug where Fig couldn't build Dockerfiles with ADD statements pointing at URLs.
|
||||
|
||||
1.0.0 (2014-10-16)
|
||||
------------------
|
||||
|
||||
The highlights:
|
||||
@@ -43,6 +106,8 @@ Other things:
|
||||
- When starting a service where `volumes_from` points to a service without any containers running, that service will now be started.
|
||||
- Lots of docs improvements. Notably, environment variables are documented and official repositories are used throughout.
|
||||
|
||||
Thanks @dnephin, @d11wtq, @marksteve, @rubbish, @jbalonso, @timfreund, @alunduil, @mieciu, @shuron, @moss, @suzaku and @chmouel! Whew.
|
||||
|
||||
0.5.2 (2014-07-28)
|
||||
------------------
|
||||
|
||||
|
||||
@@ -1,22 +1,44 @@
|
||||
# Contributing to Fig
|
||||
# Contributing to Compose
|
||||
|
||||
Compose is a part of the Docker project, and follows the same rules and principles. Take a read of [Docker's contributing guidelines](https://github.com/docker/docker/blob/master/CONTRIBUTING.md) to get an overview.
|
||||
|
||||
## TL;DR
|
||||
|
||||
Pull requests will need:
|
||||
|
||||
- Tests
|
||||
- Documentation
|
||||
- [To be signed off](https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work)
|
||||
- A logical series of [well written commits](https://github.com/alphagov/styleguides/blob/master/git.md)
|
||||
|
||||
## Development environment
|
||||
|
||||
If you're looking contribute to [Fig](http://www.fig.sh/)
|
||||
If you're looking contribute to Compose
|
||||
but you're new to the project or maybe even to Python, here are the steps
|
||||
that should get you started.
|
||||
|
||||
1. Fork [https://github.com/docker/fig](https://github.com/docker/fig) to your username. kvz in this example.
|
||||
1. Clone your forked repository locally `git clone git@github.com:kvz/fig.git`.
|
||||
1. Enter the local directory `cd fig`.
|
||||
1. Set up a development environment `python setup.py develop`. That will install the dependencies and set up a symlink from your `fig` executable to the checkout of the repo. So from any of your fig projects, `fig` now refers to your development project. Time to start hacking : )
|
||||
1. Works for you? Run the test suite via `./script/test` to verify it won't break other usecases.
|
||||
1. All good? Commit and push to GitHub, and submit a pull request.
|
||||
1. Fork [https://github.com/docker/compose](https://github.com/docker/compose) to your username.
|
||||
1. Clone your forked repository locally `git clone git@github.com:yourusername/compose.git`.
|
||||
1. Enter the local directory `cd compose`.
|
||||
1. Set up a development environment by running `python setup.py develop`. This will install the dependencies and set up a symlink from your `docker-compose` executable to the checkout of the repository. When you now run `docker-compose` from anywhere on your machine, it will run your development version of Compose.
|
||||
|
||||
## Running the test suite
|
||||
|
||||
Use the test script to run linting checks and then the full test suite:
|
||||
|
||||
$ script/test
|
||||
|
||||
Tests are run against a Docker daemon inside a container, so that we can test against multiple Docker versions. By default they'll run against only the latest Docker version - set the `DOCKER_VERSIONS` environment variable to "all" to run against all supported versions:
|
||||
|
||||
$ DOCKER_VERSIONS=all script/test
|
||||
|
||||
Arguments to `script/test` are passed through to the `nosetests` executable, so you can specify a test directory, file, module, class or method:
|
||||
|
||||
$ script/test tests/unit
|
||||
$ script/test tests/unit/cli_test.py
|
||||
$ script/test tests.integration.service_test
|
||||
$ script/test tests.integration.service_test:ServiceTest.test_containers
|
||||
|
||||
## Building binaries
|
||||
|
||||
Linux:
|
||||
@@ -29,64 +51,20 @@ OS X:
|
||||
|
||||
Note that this only works on Mountain Lion, not Mavericks, due to a [bug in PyInstaller](http://www.pyinstaller.org/ticket/807).
|
||||
|
||||
## Sign your work
|
||||
|
||||
The sign-off is a simple line at the end of the explanation for the
|
||||
patch, which certifies that you wrote it or otherwise have the right to
|
||||
pass it on as an open-source patch. The rules are pretty simple: if you
|
||||
can certify the below (from [developercertificate.org](http://developercertificate.org/)):
|
||||
|
||||
Developer's Certificate of Origin 1.1
|
||||
|
||||
By making a contribution to this project, I certify that:
|
||||
|
||||
(a) The contribution was created in whole or in part by me and I
|
||||
have the right to submit it under the open source license
|
||||
indicated in the file; or
|
||||
|
||||
(b) The contribution is based upon previous work that, to the best
|
||||
of my knowledge, is covered under an appropriate open source
|
||||
license and I have the right under that license to submit that
|
||||
work with modifications, whether created in whole or in part
|
||||
by me, under the same open source license (unless I am
|
||||
permitted to submit under a different license), as indicated
|
||||
in the file; or
|
||||
|
||||
(c) The contribution was provided directly to me by some other
|
||||
person who certified (a), (b) or (c) and I have not modified
|
||||
it.
|
||||
|
||||
(d) I understand and agree that this project and the contribution
|
||||
are public and that a record of the contribution (including all
|
||||
personal information I submit with it, including my sign-off) is
|
||||
maintained indefinitely and may be redistributed consistent with
|
||||
this project or the open source license(s) involved.
|
||||
|
||||
then you just add a line saying
|
||||
|
||||
Signed-off-by: Random J Developer <random@developer.example.org>
|
||||
|
||||
using your real name (sorry, no pseudonyms or anonymous contributions.)
|
||||
|
||||
The easiest way to do this is to use the `--signoff` flag when committing. E.g.:
|
||||
|
||||
|
||||
$ git commit --signoff
|
||||
|
||||
|
||||
## Release process
|
||||
|
||||
1. Open pull request that:
|
||||
|
||||
- Updates version in `fig/__init__.py`
|
||||
- Updates version in `docs/install.md`
|
||||
- Updates the version in `compose/__init__.py`
|
||||
- Updates the binary URL in `docs/install.md`
|
||||
- Updates the script URL in `docs/completion.md`
|
||||
- Adds release notes to `CHANGES.md`
|
||||
|
||||
2. Create unpublished GitHub release with release notes
|
||||
|
||||
3. Build Linux version on any Docker host with `script/build-linux` and attach to release
|
||||
|
||||
4. Build OS X version on Mountain Lion with `script/build-osx` and attach to release as `fig-Darwin-x86_64` and `fig-Linux-x86_64`.
|
||||
4. Build OS X version on Mountain Lion with `script/build-osx` and attach to release as `docker-compose-Darwin-x86_64` and `docker-compose-Linux-x86_64`.
|
||||
|
||||
5. Publish GitHub release, creating tag
|
||||
|
||||
@@ -94,5 +72,5 @@ The easiest way to do this is to use the `--signoff` flag when committing. E.g.:
|
||||
|
||||
7. Upload PyPi package
|
||||
|
||||
$ git checkout $VERSION
|
||||
$ python setup.py sdist upload
|
||||
$ git checkout $VERSION
|
||||
$ python setup.py sdist upload
|
||||
|
||||
30
Dockerfile
30
Dockerfile
@@ -1,5 +1,31 @@
|
||||
FROM debian:wheezy
|
||||
RUN apt-get update -qq && apt-get install -qy python python-pip python-dev git && apt-get clean
|
||||
|
||||
RUN set -ex; \
|
||||
apt-get update -qq; \
|
||||
apt-get install -y \
|
||||
python \
|
||||
python-pip \
|
||||
python-dev \
|
||||
git \
|
||||
apt-transport-https \
|
||||
ca-certificates \
|
||||
curl \
|
||||
lxc \
|
||||
iptables \
|
||||
; \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ENV ALL_DOCKER_VERSIONS 1.3.3 1.4.1 1.5.0
|
||||
|
||||
RUN set -ex; \
|
||||
for v in ${ALL_DOCKER_VERSIONS}; do \
|
||||
curl https://get.docker.com/builds/Linux/x86_64/docker-$v -o /usr/local/bin/docker-$v; \
|
||||
chmod +x /usr/local/bin/docker-$v; \
|
||||
done
|
||||
|
||||
# Set the default Docker to be run
|
||||
RUN ln -s /usr/local/bin/docker-1.3.3 /usr/local/bin/docker
|
||||
|
||||
RUN useradd -d /home/user -m -s /bin/bash user
|
||||
WORKDIR /code/
|
||||
|
||||
@@ -13,3 +39,5 @@ ADD . /code/
|
||||
RUN python setup.py install
|
||||
|
||||
RUN chown -R user /code/
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/docker-compose"]
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
Aanand Prasad <aanand.prasad@gmail.com> (@aanand)
|
||||
Ben Firshman <ben@firshman.co.uk> (@bfirsh)
|
||||
Chris Corbyn <chris@w3style.co.uk> (@d11wtq)
|
||||
Nathan LeClaire <nathan.leclaire@gmail.com> (@nathanleclaire)
|
||||
Daniel Nephin <dnephin@gmail.com> (@dnephin)
|
||||
|
||||
@@ -4,7 +4,8 @@ include requirements.txt
|
||||
include requirements-dev.txt
|
||||
include tox.ini
|
||||
include *.md
|
||||
recursive-exclude tests *
|
||||
include contrib/completion/bash/docker-compose
|
||||
recursive-include tests *
|
||||
global-exclude *.pyc
|
||||
global-exclude *.pyo
|
||||
global-exclude *.un~
|
||||
|
||||
55
README.md
55
README.md
@@ -1,19 +1,32 @@
|
||||
Fig
|
||||
===
|
||||
Docker Compose
|
||||
==============
|
||||
[](http://jenkins.dockerproject.com/job/Compose%20Master/)
|
||||
*(Previously known as Fig)*
|
||||
|
||||
[](https://app.wercker.com/project/bykey/d5dbac3907301c3d5ce735e2d5e95a5b)
|
||||
Compose is a tool for defining and running complex applications with Docker.
|
||||
With Compose, you define a multi-container application in a single file, then
|
||||
spin your application up in a single command which does everything that needs to
|
||||
be done to get it running.
|
||||
|
||||
Fast, isolated development environments using Docker.
|
||||
Compose is great for development environments, staging servers, and CI. We don't
|
||||
recommend that you use it in production yet.
|
||||
|
||||
Define your app's environment with Docker so it can be reproduced anywhere:
|
||||
Using Compose is basically a three-step process.
|
||||
|
||||
FROM python:2.7
|
||||
ADD . /code
|
||||
WORKDIR /code
|
||||
RUN pip install -r requirements.txt
|
||||
CMD python app.py
|
||||
First, you define your app's environment with a `Dockerfile` so it can be
|
||||
reproduced anywhere:
|
||||
|
||||
Define the services that make up your app so they can be run together in an isolated environment:
|
||||
```Dockerfile
|
||||
FROM python:2.7
|
||||
WORKDIR /code
|
||||
ADD requirements.txt /code/
|
||||
RUN pip install -r requirements.txt
|
||||
ADD . /code
|
||||
CMD python app.py
|
||||
```
|
||||
|
||||
Next, you define the services that make up your app in `docker-compose.yml` so
|
||||
they can be run together in an isolated environment:
|
||||
|
||||
```yaml
|
||||
web:
|
||||
@@ -22,25 +35,21 @@ web:
|
||||
- db
|
||||
ports:
|
||||
- "8000:8000"
|
||||
- "49100:22"
|
||||
db:
|
||||
image: postgres
|
||||
```
|
||||
|
||||
(No more installing Postgres on your laptop!)
|
||||
Lastly, run `docker-compose up` and Compose will start and run your entire app.
|
||||
|
||||
Then type `fig up`, and Fig will start and run your entire app:
|
||||
Compose has commands for managing the whole lifecycle of your application:
|
||||
|
||||

|
||||
|
||||
There are commands to:
|
||||
|
||||
- start, stop and rebuild services
|
||||
- view the status of running services
|
||||
- tail running services' log output
|
||||
- run a one-off command on a service
|
||||
* Start, stop and rebuild services
|
||||
* View the status of running services
|
||||
* Stream the log output of running services
|
||||
* Run a one-off command on a service
|
||||
|
||||
Installation and documentation
|
||||
------------------------------
|
||||
|
||||
Full documentation is available on [Fig's website](http://www.fig.sh/).
|
||||
- Full documentation is available on [Docker's website](http://docs.docker.com/compose/).
|
||||
- Hop into #docker-compose on Freenode if you have any questions.
|
||||
|
||||
28
ROADMAP.md
Normal file
28
ROADMAP.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Roadmap
|
||||
|
||||
## More than just development environments
|
||||
|
||||
Over time we will extend Compose's remit to cover test, staging and production environments. This is not a simple task, and will take many incremental improvements such as:
|
||||
|
||||
- Compose’s brute-force “delete and recreate everything” approach is great for dev and testing, but it not sufficient for production environments. You should be able to define a "desired" state that Compose will intelligently converge to.
|
||||
- It should be possible to partially modify the config file for different environments (dev/test/staging/prod), passing in e.g. custom ports or volume mount paths. ([#426](https://github.com/docker/fig/issues/426))
|
||||
- Compose should recommend a technique for zero-downtime deploys.
|
||||
|
||||
## Integration with Swarm
|
||||
|
||||
Compose should integrate really well with Swarm so you can take an application you've developed on your laptop and run it on a Swarm cluster.
|
||||
|
||||
The current state of integration is documented in [SWARM.md](SWARM.md).
|
||||
|
||||
## Applications spanning multiple teams
|
||||
|
||||
Compose works well for applications that are in a single repository and depend on services that are hosted on Docker Hub. If your application depends on another application within your organisation, Compose doesn't work as well.
|
||||
|
||||
There are several ideas about how this could work, such as [including external files](https://github.com/docker/fig/issues/318).
|
||||
|
||||
## An even better tool for development environments
|
||||
|
||||
Compose is a great tool for development environments, but it could be even better. For example:
|
||||
|
||||
- [Compose could watch your code and automatically kick off builds when something changes.](https://github.com/docker/fig/issues/184)
|
||||
- It should be possible to define hostnames for containers which work from the host machine, e.g. “mywebcontainer.local”. This is needed by apps comprising multiple web services which generate links to one another (e.g. a frontend website and a separate admin webapp)
|
||||
51
SWARM.md
Normal file
51
SWARM.md
Normal file
@@ -0,0 +1,51 @@
|
||||
Docker Compose/Swarm integration
|
||||
================================
|
||||
|
||||
Eventually, Compose and Swarm aim to have full integration, meaning you can point a Compose app at a Swarm cluster and have it all just work as if you were using a single Docker host.
|
||||
|
||||
However, the current extent of integration is minimal: Compose can create containers on a Swarm cluster, but the majority of Compose apps won’t work out of the box unless all containers are scheduled on one host, defeating much of the purpose of using Swarm in the first place.
|
||||
|
||||
Still, Compose and Swarm can be useful in a “batch processing” scenario (where a large number of containers need to be spun up and down to do independent computation) or a “shared cluster” scenario (where multiple teams want to deploy apps on a cluster without worrying about where to put them).
|
||||
|
||||
A number of things need to happen before full integration is achieved, which are documented below.
|
||||
|
||||
Re-deploying containers with `docker-compose up`
|
||||
------------------------------------------------
|
||||
|
||||
Repeated invocations of `docker-compose up` will not work reliably when used against a Swarm cluster because of an under-the-hood design problem; [this will be fixed](https://github.com/docker/fig/pull/972) in the next version of Compose. For now, containers must be completely removed and re-created:
|
||||
|
||||
$ docker-compose kill
|
||||
$ docker-compose rm --force
|
||||
$ docker-compose up
|
||||
|
||||
Links and networking
|
||||
--------------------
|
||||
|
||||
The primary thing stopping multi-container apps from working seamlessly on Swarm is getting them to talk to one another: enabling private communication between containers on different hosts hasn’t been solved in a non-hacky way.
|
||||
|
||||
Long-term, networking is [getting overhauled](https://github.com/docker/docker/issues/9983) in such a way that it’ll fit the multi-host model much better. For now, containers on different hosts cannot be linked. In the next version of Compose, linked services will be automatically scheduled on the same host; for now, this must be done manually (see “Co-scheduling containers” below).
|
||||
|
||||
`volumes_from` and `net: container`
|
||||
-----------------------------------
|
||||
|
||||
For containers to share volumes or a network namespace, they must be scheduled on the same host - this is, after all, inherent to how both volumes and network namespaces work. In the next version of Compose, this co-scheduling will be automatic whenever `volumes_from` or `net: "container:..."` is specified; for now, containers which share volumes or a network namespace must be co-scheduled manually (see “Co-scheduling containers” below).
|
||||
|
||||
Co-scheduling containers
|
||||
------------------------
|
||||
|
||||
For now, containers can be manually scheduled on the same host using Swarm’s [affinity filters](https://github.com/docker/swarm/blob/master/scheduler/filter/README.md#affinity-filter). Here’s a simple example:
|
||||
|
||||
```yaml
|
||||
web:
|
||||
image: my-web-image
|
||||
links: ["db"]
|
||||
environment:
|
||||
- "affinity:container==myproject_db_*"
|
||||
db:
|
||||
image: postgres
|
||||
```
|
||||
|
||||
Here, we express an affinity filter on all web containers, saying that each one must run alongside a container whose name begins with `myproject_db_`.
|
||||
|
||||
- `myproject` is the common prefix Compose gives to all containers in your project, which is either generated from the name of the current directory or specified with `-p` or the `DOCKER_COMPOSE_PROJECT_NAME` environment variable.
|
||||
- `*` is a wildcard, which works just like filename wildcards in a Unix shell.
|
||||
3
bin/docker-compose
Executable file
3
bin/docker-compose
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
from compose.cli.main import main
|
||||
main()
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import unicode_literals
|
||||
from .service import Service # noqa:flake8
|
||||
|
||||
__version__ = '1.0.0'
|
||||
__version__ = '1.2.0'
|
||||
@@ -1,13 +1,12 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from requests.exceptions import ConnectionError, SSLError
|
||||
import errno
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import yaml
|
||||
import six
|
||||
|
||||
from .. import config
|
||||
from ..project import Project
|
||||
from ..service import ConfigError
|
||||
from .docopt_command import DocoptCommand
|
||||
@@ -26,7 +25,7 @@ class Command(DocoptCommand):
|
||||
def dispatch(self, *args, **kwargs):
|
||||
try:
|
||||
super(Command, self).dispatch(*args, **kwargs)
|
||||
except SSLError, e:
|
||||
except SSLError as e:
|
||||
raise errors.UserError('SSL error: %s' % e)
|
||||
except ConnectionError:
|
||||
if call_silently(['which', 'docker']) != 0:
|
||||
@@ -42,7 +41,16 @@ class Command(DocoptCommand):
|
||||
raise errors.ConnectionErrorGeneric(self.get_client().base_url)
|
||||
|
||||
def perform_command(self, options, handler, command_options):
|
||||
explicit_config_path = options.get('--file') or os.environ.get('FIG_FILE')
|
||||
if options['COMMAND'] == 'help':
|
||||
# Skip looking up the compose file.
|
||||
handler(None, command_options)
|
||||
return
|
||||
|
||||
if 'FIG_FILE' in os.environ:
|
||||
log.warn('The FIG_FILE environment variable is deprecated.')
|
||||
log.warn('Please use COMPOSE_FILE instead.')
|
||||
|
||||
explicit_config_path = options.get('--file') or os.environ.get('COMPOSE_FILE') or os.environ.get('FIG_FILE')
|
||||
project = self.get_project(
|
||||
self.get_config_path(explicit_config_path),
|
||||
project_name=options.get('--project-name'),
|
||||
@@ -54,36 +62,31 @@ class Command(DocoptCommand):
|
||||
client = docker_client()
|
||||
if verbose:
|
||||
version_info = six.iteritems(client.version())
|
||||
log.info("Fig version %s", __version__)
|
||||
log.info("Compose version %s", __version__)
|
||||
log.info("Docker base_url: %s", client.base_url)
|
||||
log.info("Docker version: %s",
|
||||
", ".join("%s=%s" % item for item in version_info))
|
||||
return verbose_proxy.VerboseProxy('docker', client)
|
||||
return client
|
||||
|
||||
def get_config(self, config_path):
|
||||
try:
|
||||
with open(config_path, 'r') as fh:
|
||||
return yaml.safe_load(fh)
|
||||
except IOError as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
raise errors.FigFileNotFound(os.path.basename(e.filename))
|
||||
raise errors.UserError(six.text_type(e))
|
||||
|
||||
def get_project(self, config_path, project_name=None, verbose=False):
|
||||
try:
|
||||
return Project.from_config(
|
||||
return Project.from_dicts(
|
||||
self.get_project_name(config_path, project_name),
|
||||
self.get_config(config_path),
|
||||
config.load(config_path),
|
||||
self.get_client(verbose=verbose))
|
||||
except ConfigError as e:
|
||||
raise errors.UserError(six.text_type(e))
|
||||
|
||||
def get_project_name(self, config_path, project_name=None):
|
||||
def normalize_name(name):
|
||||
return re.sub(r'[^a-zA-Z0-9]', '', name)
|
||||
return re.sub(r'[^a-z0-9]', '', name.lower())
|
||||
|
||||
project_name = project_name or os.environ.get('FIG_PROJECT_NAME')
|
||||
if 'FIG_PROJECT_NAME' in os.environ:
|
||||
log.warn('The FIG_PROJECT_NAME environment variable is deprecated.')
|
||||
log.warn('Please use COMPOSE_PROJECT_NAME instead.')
|
||||
|
||||
project_name = project_name or os.environ.get('COMPOSE_PROJECT_NAME') or os.environ.get('FIG_PROJECT_NAME')
|
||||
if project_name is not None:
|
||||
return normalize_name(project_name)
|
||||
|
||||
@@ -97,13 +100,34 @@ class Command(DocoptCommand):
|
||||
if file_path:
|
||||
return os.path.join(self.base_dir, file_path)
|
||||
|
||||
if os.path.exists(os.path.join(self.base_dir, 'fig.yaml')):
|
||||
log.warning("Fig just read the file 'fig.yaml' on startup, rather "
|
||||
"than 'fig.yml'")
|
||||
log.warning("Please be aware that fig.yml the expected extension "
|
||||
supported_filenames = [
|
||||
'docker-compose.yml',
|
||||
'docker-compose.yaml',
|
||||
'fig.yml',
|
||||
'fig.yaml',
|
||||
]
|
||||
|
||||
def expand(filename):
|
||||
return os.path.join(self.base_dir, filename)
|
||||
|
||||
candidates = [filename for filename in supported_filenames if os.path.exists(expand(filename))]
|
||||
|
||||
if len(candidates) == 0:
|
||||
raise errors.ComposeFileNotFound(supported_filenames)
|
||||
|
||||
winner = candidates[0]
|
||||
|
||||
if len(candidates) > 1:
|
||||
log.warning("Found multiple config files with supported names: %s", ", ".join(candidates))
|
||||
log.warning("Using %s\n", winner)
|
||||
|
||||
if winner == 'docker-compose.yaml':
|
||||
log.warning("Please be aware that .yml is the expected extension "
|
||||
"in most cases, and using .yaml can cause compatibility "
|
||||
"issues in future")
|
||||
"issues in future.\n")
|
||||
|
||||
return os.path.join(self.base_dir, 'fig.yaml')
|
||||
if winner.startswith("fig."):
|
||||
log.warning("%s is deprecated and will not be supported in future. "
|
||||
"Please rename your config file to docker-compose.yml\n" % winner)
|
||||
|
||||
return os.path.join(self.base_dir, 'fig.yml')
|
||||
return expand(winner)
|
||||
@@ -11,7 +11,7 @@ def docker_client():
|
||||
"""
|
||||
cert_path = os.environ.get('DOCKER_CERT_PATH', '')
|
||||
if cert_path == '':
|
||||
cert_path = os.path.join(os.environ.get('HOME'), '.docker')
|
||||
cert_path = os.path.join(os.environ.get('HOME', ''), '.docker')
|
||||
|
||||
base_url = os.environ.get('DOCKER_HOST')
|
||||
tls_config = None
|
||||
@@ -31,4 +31,5 @@ def docker_client():
|
||||
ca_cert=ca_cert,
|
||||
)
|
||||
|
||||
return Client(base_url=base_url, tls=tls_config)
|
||||
timeout = int(os.environ.get('DOCKER_CLIENT_TIMEOUT', 60))
|
||||
return Client(base_url=base_url, tls=tls_config, version='1.15', timeout=timeout)
|
||||
@@ -55,8 +55,10 @@ class ConnectionErrorGeneric(UserError):
|
||||
""" % url)
|
||||
|
||||
|
||||
class FigFileNotFound(UserError):
|
||||
def __init__(self, filename):
|
||||
super(FigFileNotFound, self).__init__("""
|
||||
Can't find %s. Are you in the right directory?
|
||||
""" % filename)
|
||||
class ComposeFileNotFound(UserError):
|
||||
def __init__(self, supported_filenames):
|
||||
super(ComposeFileNotFound, self).__init__("""
|
||||
Can't find a suitable configuration file. Are you in the right directory?
|
||||
|
||||
Supported filenames: %s
|
||||
""" % ", ".join(supported_filenames))
|
||||
@@ -39,11 +39,14 @@ class LogPrinter(object):
|
||||
color_fns = cycle(colors.rainbow())
|
||||
generators = []
|
||||
|
||||
def no_color(text):
|
||||
return text
|
||||
|
||||
for container in self.containers:
|
||||
if monochrome:
|
||||
color_fn = lambda s: s
|
||||
color_fn = no_color
|
||||
else:
|
||||
color_fn = color_fns.next()
|
||||
color_fn = next(color_fns)
|
||||
generators.append(self._make_log_generator(container, color_fn))
|
||||
|
||||
return generators
|
||||
@@ -1,26 +1,26 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from inspect import getdoc
|
||||
from operator import attrgetter
|
||||
import logging
|
||||
import sys
|
||||
import re
|
||||
import signal
|
||||
from operator import attrgetter
|
||||
import sys
|
||||
|
||||
from inspect import getdoc
|
||||
from fig.packages import dockerpty
|
||||
from docker.errors import APIError
|
||||
import dockerpty
|
||||
|
||||
from .. import __version__
|
||||
from ..project import NoSuchService, ConfigurationError
|
||||
from ..service import BuildError, CannotBeScaledError
|
||||
from ..config import parse_environment
|
||||
from .command import Command
|
||||
from .docopt_command import NoSuchCommand
|
||||
from .errors import UserError
|
||||
from .formatter import Formatter
|
||||
from .log_printer import LogPrinter
|
||||
from .utils import yesno
|
||||
|
||||
from docker.errors import APIError
|
||||
from .errors import UserError
|
||||
from .docopt_command import NoSuchCommand
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -68,16 +68,16 @@ def parse_doc_section(name, source):
|
||||
|
||||
|
||||
class TopLevelCommand(Command):
|
||||
"""Punctual, lightweight development environments using Docker.
|
||||
"""Fast, isolated development environments using Docker.
|
||||
|
||||
Usage:
|
||||
fig [options] [COMMAND] [ARGS...]
|
||||
fig -h|--help
|
||||
docker-compose [options] [COMMAND] [ARGS...]
|
||||
docker-compose -h|--help
|
||||
|
||||
Options:
|
||||
--verbose Show more output
|
||||
--version Print version and exit
|
||||
-f, --file FILE Specify an alternate fig file (default: fig.yml)
|
||||
-f, --file FILE Specify an alternate compose file (default: docker-compose.yml)
|
||||
-p, --project-name NAME Specify an alternate project name (default: directory name)
|
||||
|
||||
Commands:
|
||||
@@ -99,7 +99,7 @@ class TopLevelCommand(Command):
|
||||
"""
|
||||
def docopt_options(self):
|
||||
options = super(TopLevelCommand, self).docopt_options()
|
||||
options['version'] = "fig %s" % __version__
|
||||
options['version'] = "docker-compose %s" % __version__
|
||||
return options
|
||||
|
||||
def build(self, project, options):
|
||||
@@ -107,8 +107,8 @@ class TopLevelCommand(Command):
|
||||
Build or rebuild services.
|
||||
|
||||
Services are built once and then tagged as `project_service`,
|
||||
e.g. `figtest_db`. If you change a service's `Dockerfile` or the
|
||||
contents of its build directory, you can run `fig build` to rebuild it.
|
||||
e.g. `composetest_db`. If you change a service's `Dockerfile` or the
|
||||
contents of its build directory, you can run `compose build` to rebuild it.
|
||||
|
||||
Usage: build [options] [SERVICE...]
|
||||
|
||||
@@ -133,9 +133,15 @@ class TopLevelCommand(Command):
|
||||
"""
|
||||
Force stop service containers.
|
||||
|
||||
Usage: kill [SERVICE...]
|
||||
Usage: kill [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
-s SIGNAL SIGNAL to send to the container.
|
||||
Default signal is SIGKILL.
|
||||
"""
|
||||
project.kill(service_names=options['SERVICE'])
|
||||
signal = options.get('-s', 'SIGKILL')
|
||||
|
||||
project.kill(service_names=options['SERVICE'], signal=signal)
|
||||
|
||||
def logs(self, project, options):
|
||||
"""
|
||||
@@ -232,8 +238,8 @@ class TopLevelCommand(Command):
|
||||
Usage: rm [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
--force Don't ask to confirm removal
|
||||
-v Remove volumes associated with containers
|
||||
-f, --force Don't ask to confirm removal
|
||||
-v Remove volumes associated with containers
|
||||
"""
|
||||
all_containers = project.containers(service_names=options['SERVICE'], stopped=True)
|
||||
stopped_containers = [c for c in all_containers if not c.is_running]
|
||||
@@ -255,34 +261,43 @@ class TopLevelCommand(Command):
|
||||
|
||||
For example:
|
||||
|
||||
$ fig run web python manage.py shell
|
||||
$ docker-compose run web python manage.py shell
|
||||
|
||||
By default, linked services will be started, unless they are already
|
||||
running. If you do not want to start linked services, use
|
||||
`fig run --no-deps SERVICE COMMAND [ARGS...]`.
|
||||
`docker-compose run --no-deps SERVICE COMMAND [ARGS...]`.
|
||||
|
||||
Usage: run [options] [-e KEY=VAL...] SERVICE [COMMAND] [ARGS...]
|
||||
|
||||
Options:
|
||||
-d Detached mode: Run container in the background, print
|
||||
new container name.
|
||||
--entrypoint CMD Override the entrypoint of the image.
|
||||
-e KEY=VAL Set an environment variable (can be used multiple times)
|
||||
--no-deps Don't start linked services.
|
||||
--rm Remove container after run. Ignored in detached mode.
|
||||
-T Disable pseudo-tty allocation. By default `fig run`
|
||||
allocates a TTY.
|
||||
--allow-insecure-ssl Allow insecure connections to the docker
|
||||
registry
|
||||
-d Detached mode: Run container in the background, print
|
||||
new container name.
|
||||
--entrypoint CMD Override the entrypoint of the image.
|
||||
-e KEY=VAL Set an environment variable (can be used multiple times)
|
||||
-u, --user="" Run as specified username or uid
|
||||
--no-deps Don't start linked services.
|
||||
--rm Remove container after run. Ignored in detached mode.
|
||||
--service-ports Run command with the service's ports enabled and mapped
|
||||
to the host.
|
||||
-T Disable pseudo-tty allocation. By default `docker-compose run`
|
||||
allocates a TTY.
|
||||
"""
|
||||
service = project.get_service(options['SERVICE'])
|
||||
|
||||
insecure_registry = options['--allow-insecure-ssl']
|
||||
|
||||
if not options['--no-deps']:
|
||||
deps = service.get_linked_names()
|
||||
|
||||
if len(deps) > 0:
|
||||
project.up(
|
||||
service_names=deps,
|
||||
start_links=True,
|
||||
start_deps=True,
|
||||
recreate=False,
|
||||
insecure_registry=insecure_registry,
|
||||
detach=options['-d']
|
||||
)
|
||||
|
||||
tty = True
|
||||
@@ -298,25 +313,36 @@ class TopLevelCommand(Command):
|
||||
'command': command,
|
||||
'tty': tty,
|
||||
'stdin_open': not options['-d'],
|
||||
'detach': options['-d'],
|
||||
}
|
||||
|
||||
if options['-e']:
|
||||
for option in options['-e']:
|
||||
if 'environment' not in service.options:
|
||||
service.options['environment'] = {}
|
||||
k, v = option.split('=', 1)
|
||||
service.options['environment'][k] = v
|
||||
# Merge environment from config with -e command line
|
||||
container_options['environment'] = dict(
|
||||
parse_environment(service.options.get('environment')),
|
||||
**parse_environment(options['-e']))
|
||||
|
||||
if options['--entrypoint']:
|
||||
container_options['entrypoint'] = options.get('--entrypoint')
|
||||
|
||||
container = service.create_container(one_off=True, **container_options)
|
||||
if options['--user']:
|
||||
container_options['user'] = options.get('--user')
|
||||
|
||||
if not options['--service-ports']:
|
||||
container_options['ports'] = []
|
||||
|
||||
container = service.create_container(
|
||||
one_off=True,
|
||||
insecure_registry=insecure_registry,
|
||||
**container_options
|
||||
)
|
||||
|
||||
if options['-d']:
|
||||
service.start_container(container, ports=None, one_off=True)
|
||||
service.start_container(container)
|
||||
print(container.name)
|
||||
else:
|
||||
service.start_container(container, ports=None, one_off=True)
|
||||
dockerpty.start(project.client, container.id)
|
||||
service.start_container(container)
|
||||
dockerpty.start(project.client, container.id, interactive=not options['-T'])
|
||||
exit_code = container.wait()
|
||||
if options['--rm']:
|
||||
log.info("Removing %s..." % container.name)
|
||||
@@ -330,7 +356,7 @@ class TopLevelCommand(Command):
|
||||
Numbers are specified in the form `service=num` as arguments.
|
||||
For example:
|
||||
|
||||
$ fig scale web=2 worker=3
|
||||
$ docker-compose scale web=2 worker=3
|
||||
|
||||
Usage: scale [SERVICE=NUM...]
|
||||
"""
|
||||
@@ -350,7 +376,7 @@ class TopLevelCommand(Command):
|
||||
'Service "%s" cannot be scaled because it specifies a port '
|
||||
'on the host. If multiple containers for this service were '
|
||||
'created, the port would clash.\n\nRemove the ":" from the '
|
||||
'port definition in fig.yml so Docker can choose a random '
|
||||
'port definition in docker-compose.yml so Docker can choose a random '
|
||||
'port for each container.' % service_name)
|
||||
|
||||
def start(self, project, options):
|
||||
@@ -365,55 +391,77 @@ class TopLevelCommand(Command):
|
||||
"""
|
||||
Stop running containers without removing them.
|
||||
|
||||
They can be started again with `fig start`.
|
||||
They can be started again with `docker-compose start`.
|
||||
|
||||
Usage: stop [SERVICE...]
|
||||
Usage: stop [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
|
||||
(default: 10)
|
||||
"""
|
||||
project.stop(service_names=options['SERVICE'])
|
||||
timeout = options.get('--timeout')
|
||||
params = {} if timeout is None else {'timeout': int(timeout)}
|
||||
project.stop(service_names=options['SERVICE'], **params)
|
||||
|
||||
def restart(self, project, options):
|
||||
"""
|
||||
Restart running containers.
|
||||
|
||||
Usage: restart [SERVICE...]
|
||||
Usage: restart [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
|
||||
(default: 10)
|
||||
"""
|
||||
project.restart(service_names=options['SERVICE'])
|
||||
timeout = options.get('--timeout')
|
||||
params = {} if timeout is None else {'timeout': int(timeout)}
|
||||
project.restart(service_names=options['SERVICE'], **params)
|
||||
|
||||
def up(self, project, options):
|
||||
"""
|
||||
Build, (re)create, start and attach to containers for a service.
|
||||
|
||||
By default, `fig up` will aggregate the output of each container, and
|
||||
when it exits, all containers will be stopped. If you run `fig up -d`,
|
||||
By default, `docker-compose up` will aggregate the output of each container, and
|
||||
when it exits, all containers will be stopped. If you run `docker-compose up -d`,
|
||||
it'll start the containers in the background and leave them running.
|
||||
|
||||
If there are existing containers for a service, `fig up` will stop
|
||||
If there are existing containers for a service, `docker-compose up` will stop
|
||||
and recreate them (preserving mounted volumes with volumes-from),
|
||||
so that changes in `fig.yml` are picked up. If you do not want existing
|
||||
containers to be recreated, `fig up --no-recreate` will re-use existing
|
||||
so that changes in `docker-compose.yml` are picked up. If you do not want existing
|
||||
containers to be recreated, `docker-compose up --no-recreate` will re-use existing
|
||||
containers.
|
||||
|
||||
Usage: up [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
-d Detached mode: Run containers in the background,
|
||||
print new container names.
|
||||
--no-color Produce monochrome output.
|
||||
--no-deps Don't start linked services.
|
||||
--no-recreate If containers already exist, don't recreate them.
|
||||
--allow-insecure-ssl Allow insecure connections to the docker
|
||||
registry
|
||||
-d Detached mode: Run containers in the background,
|
||||
print new container names.
|
||||
--no-color Produce monochrome output.
|
||||
--no-deps Don't start linked services.
|
||||
--no-recreate If containers already exist, don't recreate them.
|
||||
--no-build Don't build an image, even if it's missing
|
||||
-t, --timeout TIMEOUT When attached, use this timeout in seconds
|
||||
for the shutdown. (default: 10)
|
||||
|
||||
"""
|
||||
insecure_registry = options['--allow-insecure-ssl']
|
||||
detached = options['-d']
|
||||
|
||||
monochrome = options['--no-color']
|
||||
|
||||
start_links = not options['--no-deps']
|
||||
start_deps = not options['--no-deps']
|
||||
recreate = not options['--no-recreate']
|
||||
service_names = options['SERVICE']
|
||||
|
||||
project.up(
|
||||
service_names=service_names,
|
||||
start_links=start_links,
|
||||
recreate=recreate
|
||||
start_deps=start_deps,
|
||||
recreate=recreate,
|
||||
insecure_registry=insecure_registry,
|
||||
detach=detached,
|
||||
do_build=not options['--no-build'],
|
||||
)
|
||||
|
||||
to_attach = [c for s in project.get_services(service_names) for c in s.containers()]
|
||||
@@ -431,7 +479,9 @@ class TopLevelCommand(Command):
|
||||
signal.signal(signal.SIGINT, handler)
|
||||
|
||||
print("Gracefully stopping... (press Ctrl+C again to force)")
|
||||
project.stop(service_names=service_names)
|
||||
timeout = options.get('--timeout')
|
||||
params = {} if timeout is None else {'timeout': int(timeout)}
|
||||
project.stop(service_names=service_names, **params)
|
||||
|
||||
|
||||
def list_containers(containers):
|
||||
432
compose/config.py
Normal file
432
compose/config.py
Normal file
@@ -0,0 +1,432 @@
|
||||
import os
|
||||
import yaml
|
||||
import six
|
||||
|
||||
|
||||
DOCKER_CONFIG_KEYS = [
|
||||
'cap_add',
|
||||
'cap_drop',
|
||||
'cpu_shares',
|
||||
'command',
|
||||
'detach',
|
||||
'dns',
|
||||
'dns_search',
|
||||
'domainname',
|
||||
'entrypoint',
|
||||
'env_file',
|
||||
'environment',
|
||||
'hostname',
|
||||
'image',
|
||||
'links',
|
||||
'mem_limit',
|
||||
'net',
|
||||
'ports',
|
||||
'privileged',
|
||||
'restart',
|
||||
'stdin_open',
|
||||
'tty',
|
||||
'user',
|
||||
'volumes',
|
||||
'volumes_from',
|
||||
'working_dir',
|
||||
]
|
||||
|
||||
ALLOWED_KEYS = DOCKER_CONFIG_KEYS + [
|
||||
'build',
|
||||
'expose',
|
||||
'external_links',
|
||||
'name',
|
||||
]
|
||||
|
||||
DOCKER_CONFIG_HINTS = {
|
||||
'cpu_share' : 'cpu_shares',
|
||||
'link' : 'links',
|
||||
'port' : 'ports',
|
||||
'privilege' : 'privileged',
|
||||
'priviliged': 'privileged',
|
||||
'privilige' : 'privileged',
|
||||
'volume' : 'volumes',
|
||||
'workdir' : 'working_dir',
|
||||
}
|
||||
|
||||
|
||||
def load(filename):
|
||||
working_dir = os.path.dirname(filename)
|
||||
return from_dictionary(load_yaml(filename), working_dir=working_dir, filename=filename)
|
||||
|
||||
|
||||
def from_dictionary(dictionary, working_dir=None, filename=None):
|
||||
service_dicts = []
|
||||
|
||||
for service_name, service_dict in list(dictionary.items()):
|
||||
if not isinstance(service_dict, dict):
|
||||
raise ConfigurationError('Service "%s" doesn\'t have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.' % service_name)
|
||||
loader = ServiceLoader(working_dir=working_dir, filename=filename)
|
||||
service_dict = loader.make_service_dict(service_name, service_dict)
|
||||
service_dicts.append(service_dict)
|
||||
|
||||
return service_dicts
|
||||
|
||||
|
||||
def make_service_dict(name, service_dict, working_dir=None):
|
||||
return ServiceLoader(working_dir=working_dir).make_service_dict(name, service_dict)
|
||||
|
||||
|
||||
class ServiceLoader(object):
|
||||
def __init__(self, working_dir, filename=None, already_seen=None):
|
||||
self.working_dir = working_dir
|
||||
self.filename = filename
|
||||
self.already_seen = already_seen or []
|
||||
|
||||
def make_service_dict(self, name, service_dict):
|
||||
if self.signature(name) in self.already_seen:
|
||||
raise CircularReference(self.already_seen)
|
||||
|
||||
service_dict = service_dict.copy()
|
||||
service_dict['name'] = name
|
||||
service_dict = resolve_environment(service_dict, working_dir=self.working_dir)
|
||||
service_dict = self.resolve_extends(service_dict)
|
||||
return process_container_options(service_dict, working_dir=self.working_dir)
|
||||
|
||||
def resolve_extends(self, service_dict):
|
||||
if 'extends' not in service_dict:
|
||||
return service_dict
|
||||
|
||||
extends_options = process_extends_options(service_dict['name'], service_dict['extends'])
|
||||
|
||||
if self.working_dir is None:
|
||||
raise Exception("No working_dir passed to ServiceLoader()")
|
||||
|
||||
other_config_path = expand_path(self.working_dir, extends_options['file'])
|
||||
other_working_dir = os.path.dirname(other_config_path)
|
||||
other_already_seen = self.already_seen + [self.signature(service_dict['name'])]
|
||||
other_loader = ServiceLoader(
|
||||
working_dir=other_working_dir,
|
||||
filename=other_config_path,
|
||||
already_seen=other_already_seen,
|
||||
)
|
||||
|
||||
other_config = load_yaml(other_config_path)
|
||||
other_service_dict = other_config[extends_options['service']]
|
||||
other_service_dict = other_loader.make_service_dict(
|
||||
service_dict['name'],
|
||||
other_service_dict,
|
||||
)
|
||||
validate_extended_service_dict(
|
||||
other_service_dict,
|
||||
filename=other_config_path,
|
||||
service=extends_options['service'],
|
||||
)
|
||||
|
||||
return merge_service_dicts(other_service_dict, service_dict)
|
||||
|
||||
def signature(self, name):
|
||||
return (self.filename, name)
|
||||
|
||||
|
||||
def process_extends_options(service_name, extends_options):
|
||||
error_prefix = "Invalid 'extends' configuration for %s:" % service_name
|
||||
|
||||
if not isinstance(extends_options, dict):
|
||||
raise ConfigurationError("%s must be a dictionary" % error_prefix)
|
||||
|
||||
if 'service' not in extends_options:
|
||||
raise ConfigurationError(
|
||||
"%s you need to specify a service, e.g. 'service: web'" % error_prefix
|
||||
)
|
||||
|
||||
for k, _ in extends_options.items():
|
||||
if k not in ['file', 'service']:
|
||||
raise ConfigurationError(
|
||||
"%s unsupported configuration option '%s'" % (error_prefix, k)
|
||||
)
|
||||
|
||||
return extends_options
|
||||
|
||||
|
||||
def validate_extended_service_dict(service_dict, filename, service):
|
||||
error_prefix = "Cannot extend service '%s' in %s:" % (service, filename)
|
||||
|
||||
if 'links' in service_dict:
|
||||
raise ConfigurationError("%s services with 'links' cannot be extended" % error_prefix)
|
||||
|
||||
if 'volumes_from' in service_dict:
|
||||
raise ConfigurationError("%s services with 'volumes_from' cannot be extended" % error_prefix)
|
||||
|
||||
if 'net' in service_dict:
|
||||
if get_service_name_from_net(service_dict['net']) is not None:
|
||||
raise ConfigurationError("%s services with 'net: container' cannot be extended" % error_prefix)
|
||||
|
||||
|
||||
def process_container_options(service_dict, working_dir=None):
|
||||
for k in service_dict:
|
||||
if k not in ALLOWED_KEYS:
|
||||
msg = "Unsupported config option for %s service: '%s'" % (service_dict['name'], k)
|
||||
if k in DOCKER_CONFIG_HINTS:
|
||||
msg += " (did you mean '%s'?)" % DOCKER_CONFIG_HINTS[k]
|
||||
raise ConfigurationError(msg)
|
||||
|
||||
service_dict = service_dict.copy()
|
||||
|
||||
if 'volumes' in service_dict:
|
||||
service_dict['volumes'] = resolve_host_paths(service_dict['volumes'], working_dir=working_dir)
|
||||
|
||||
if 'build' in service_dict:
|
||||
service_dict['build'] = resolve_build_path(service_dict['build'], working_dir=working_dir)
|
||||
|
||||
return service_dict
|
||||
|
||||
|
||||
def merge_service_dicts(base, override):
|
||||
d = base.copy()
|
||||
|
||||
if 'environment' in base or 'environment' in override:
|
||||
d['environment'] = merge_environment(
|
||||
base.get('environment'),
|
||||
override.get('environment'),
|
||||
)
|
||||
|
||||
if 'volumes' in base or 'volumes' in override:
|
||||
d['volumes'] = merge_volumes(
|
||||
base.get('volumes'),
|
||||
override.get('volumes'),
|
||||
)
|
||||
|
||||
if 'image' in override and 'build' in d:
|
||||
del d['build']
|
||||
|
||||
if 'build' in override and 'image' in d:
|
||||
del d['image']
|
||||
|
||||
list_keys = ['ports', 'expose', 'external_links']
|
||||
|
||||
for key in list_keys:
|
||||
if key in base or key in override:
|
||||
d[key] = base.get(key, []) + override.get(key, [])
|
||||
|
||||
list_or_string_keys = ['dns', 'dns_search']
|
||||
|
||||
for key in list_or_string_keys:
|
||||
if key in base or key in override:
|
||||
d[key] = to_list(base.get(key)) + to_list(override.get(key))
|
||||
|
||||
already_merged_keys = ['environment', 'volumes'] + list_keys + list_or_string_keys
|
||||
|
||||
for k in set(ALLOWED_KEYS) - set(already_merged_keys):
|
||||
if k in override:
|
||||
d[k] = override[k]
|
||||
|
||||
return d
|
||||
|
||||
|
||||
def merge_environment(base, override):
|
||||
env = parse_environment(base)
|
||||
env.update(parse_environment(override))
|
||||
return env
|
||||
|
||||
|
||||
def parse_links(links):
|
||||
return dict(parse_link(l) for l in links)
|
||||
|
||||
|
||||
def parse_link(link):
|
||||
if ':' in link:
|
||||
source, alias = link.split(':', 1)
|
||||
return (alias, source)
|
||||
else:
|
||||
return (link, link)
|
||||
|
||||
|
||||
def get_env_files(options, working_dir=None):
|
||||
if 'env_file' not in options:
|
||||
return {}
|
||||
|
||||
if working_dir is None:
|
||||
raise Exception("No working_dir passed to get_env_files()")
|
||||
|
||||
env_files = options.get('env_file', [])
|
||||
if not isinstance(env_files, list):
|
||||
env_files = [env_files]
|
||||
|
||||
return [expand_path(working_dir, path) for path in env_files]
|
||||
|
||||
|
||||
def resolve_environment(service_dict, working_dir=None):
|
||||
service_dict = service_dict.copy()
|
||||
|
||||
if 'environment' not in service_dict and 'env_file' not in service_dict:
|
||||
return service_dict
|
||||
|
||||
env = {}
|
||||
|
||||
if 'env_file' in service_dict:
|
||||
for f in get_env_files(service_dict, working_dir=working_dir):
|
||||
env.update(env_vars_from_file(f))
|
||||
del service_dict['env_file']
|
||||
|
||||
env.update(parse_environment(service_dict.get('environment')))
|
||||
env = dict(resolve_env_var(k, v) for k, v in six.iteritems(env))
|
||||
|
||||
service_dict['environment'] = env
|
||||
return service_dict
|
||||
|
||||
|
||||
def parse_environment(environment):
|
||||
if not environment:
|
||||
return {}
|
||||
|
||||
if isinstance(environment, list):
|
||||
return dict(split_env(e) for e in environment)
|
||||
|
||||
if isinstance(environment, dict):
|
||||
return environment
|
||||
|
||||
raise ConfigurationError(
|
||||
"environment \"%s\" must be a list or mapping," %
|
||||
environment
|
||||
)
|
||||
|
||||
|
||||
def split_env(env):
|
||||
if '=' in env:
|
||||
return env.split('=', 1)
|
||||
else:
|
||||
return env, None
|
||||
|
||||
|
||||
def resolve_env_var(key, val):
|
||||
if val is not None:
|
||||
return key, val
|
||||
elif key in os.environ:
|
||||
return key, os.environ[key]
|
||||
else:
|
||||
return key, ''
|
||||
|
||||
|
||||
def env_vars_from_file(filename):
|
||||
"""
|
||||
Read in a line delimited file of environment variables.
|
||||
"""
|
||||
if not os.path.exists(filename):
|
||||
raise ConfigurationError("Couldn't find env file: %s" % filename)
|
||||
env = {}
|
||||
for line in open(filename, 'r'):
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#'):
|
||||
k, v = split_env(line)
|
||||
env[k] = v
|
||||
return env
|
||||
|
||||
|
||||
def resolve_host_paths(volumes, working_dir=None):
|
||||
if working_dir is None:
|
||||
raise Exception("No working_dir passed to resolve_host_paths()")
|
||||
|
||||
return [resolve_host_path(v, working_dir) for v in volumes]
|
||||
|
||||
|
||||
def resolve_host_path(volume, working_dir):
|
||||
container_path, host_path = split_volume(volume)
|
||||
if host_path is not None:
|
||||
host_path = os.path.expanduser(host_path)
|
||||
host_path = os.path.expandvars(host_path)
|
||||
return "%s:%s" % (expand_path(working_dir, host_path), container_path)
|
||||
else:
|
||||
return container_path
|
||||
|
||||
|
||||
def resolve_build_path(build_path, working_dir=None):
|
||||
if working_dir is None:
|
||||
raise Exception("No working_dir passed to resolve_build_path")
|
||||
|
||||
_path = expand_path(working_dir, build_path)
|
||||
if not os.path.exists(_path) or not os.access(_path, os.R_OK):
|
||||
raise ConfigurationError("build path %s either does not exist or is not accessible." % _path)
|
||||
else:
|
||||
return _path
|
||||
|
||||
|
||||
def merge_volumes(base, override):
|
||||
d = dict_from_volumes(base)
|
||||
d.update(dict_from_volumes(override))
|
||||
return volumes_from_dict(d)
|
||||
|
||||
|
||||
def dict_from_volumes(volumes):
|
||||
if volumes:
|
||||
return dict(split_volume(v) for v in volumes)
|
||||
else:
|
||||
return {}
|
||||
|
||||
|
||||
def volumes_from_dict(d):
|
||||
return [join_volume(v) for v in d.items()]
|
||||
|
||||
|
||||
def split_volume(string):
|
||||
if ':' in string:
|
||||
(host, container) = string.split(':', 1)
|
||||
return (container, host)
|
||||
else:
|
||||
return (string, None)
|
||||
|
||||
|
||||
def join_volume(pair):
|
||||
(container, host) = pair
|
||||
if host is None:
|
||||
return container
|
||||
else:
|
||||
return ":".join((host, container))
|
||||
|
||||
|
||||
def expand_path(working_dir, path):
|
||||
return os.path.abspath(os.path.join(working_dir, path))
|
||||
|
||||
|
||||
def to_list(value):
|
||||
if value is None:
|
||||
return []
|
||||
elif isinstance(value, six.string_types):
|
||||
return [value]
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
def get_service_name_from_net(net_config):
|
||||
if not net_config:
|
||||
return
|
||||
|
||||
if not net_config.startswith('container:'):
|
||||
return
|
||||
|
||||
_, net_name = net_config.split(':', 1)
|
||||
return net_name
|
||||
|
||||
|
||||
def load_yaml(filename):
|
||||
try:
|
||||
with open(filename, 'r') as fh:
|
||||
return yaml.safe_load(fh)
|
||||
except IOError as e:
|
||||
raise ConfigurationError(six.text_type(e))
|
||||
|
||||
|
||||
class ConfigurationError(Exception):
|
||||
def __init__(self, msg):
|
||||
self.msg = msg
|
||||
|
||||
def __str__(self):
|
||||
return self.msg
|
||||
|
||||
|
||||
class CircularReference(ConfigurationError):
|
||||
def __init__(self, trail):
|
||||
self.trail = trail
|
||||
|
||||
@property
|
||||
def msg(self):
|
||||
lines = [
|
||||
"{} in {}".format(service_name, filename)
|
||||
for (filename, service_name) in self.trail
|
||||
]
|
||||
return "Circular reference:\n {}".format("\n extends ".join(lines))
|
||||
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
from functools import reduce
|
||||
|
||||
|
||||
class Container(object):
|
||||
@@ -22,10 +23,8 @@ class Container(object):
|
||||
new_dictionary = {
|
||||
'Id': dictionary['Id'],
|
||||
'Image': dictionary['Image'],
|
||||
'Name': '/' + get_container_name(dictionary),
|
||||
}
|
||||
for name in dictionary.get('Names', []):
|
||||
if len(name.split('/')) == 2:
|
||||
new_dictionary['Name'] = name
|
||||
return cls(client, new_dictionary, **kwargs)
|
||||
|
||||
@classmethod
|
||||
@@ -124,8 +123,8 @@ class Container(object):
|
||||
def stop(self, **options):
|
||||
return self.client.stop(self.id, **options)
|
||||
|
||||
def kill(self):
|
||||
return self.client.kill(self.id)
|
||||
def kill(self, **options):
|
||||
return self.client.kill(self.id, **options)
|
||||
|
||||
def restart(self):
|
||||
return self.client.restart(self.id)
|
||||
@@ -170,3 +169,14 @@ class Container(object):
|
||||
if type(self) != type(other):
|
||||
return False
|
||||
return self.id == other.id
|
||||
|
||||
|
||||
def get_container_name(container):
|
||||
if not container.get('Name') and not container.get('Names'):
|
||||
return None
|
||||
# inspect
|
||||
if 'Name' in container:
|
||||
return container['Name']
|
||||
# ps
|
||||
shortest_name = min(container['Names'], key=lambda n: len(n.split('/')))
|
||||
return shortest_name.split('/')[-1]
|
||||
@@ -19,7 +19,9 @@ def stream_output(output, stream):
|
||||
all_events.append(event)
|
||||
|
||||
if 'progress' in event or 'progressDetail' in event:
|
||||
image_id = event['id']
|
||||
image_id = event.get('id')
|
||||
if not image_id:
|
||||
continue
|
||||
|
||||
if image_id in lines:
|
||||
diff = len(lines) - lines[image_id]
|
||||
@@ -2,6 +2,8 @@ from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
|
||||
from functools import reduce
|
||||
from .config import get_service_name_from_net, ConfigurationError
|
||||
from .service import Service
|
||||
from .container import Container
|
||||
from docker.errors import APIError
|
||||
@@ -15,7 +17,17 @@ def sort_service_dicts(services):
|
||||
temporary_marked = set()
|
||||
sorted_services = []
|
||||
|
||||
get_service_names = lambda links: [link.split(':')[0] for link in links]
|
||||
def get_service_names(links):
|
||||
return [link.split(':')[0] for link in links]
|
||||
|
||||
def get_service_dependents(service_dict, services):
|
||||
name = service_dict['name']
|
||||
return [
|
||||
service for service in services
|
||||
if (name in get_service_names(service.get('links', [])) or
|
||||
name in service.get('volumes_from', []) or
|
||||
name == get_service_name_from_net(service.get('net')))
|
||||
]
|
||||
|
||||
def visit(n):
|
||||
if n['name'] in temporary_marked:
|
||||
@@ -27,8 +39,7 @@ def sort_service_dicts(services):
|
||||
raise DependencyError('Circular import between %s' % ' and '.join(temporary_marked))
|
||||
if n in unmarked:
|
||||
temporary_marked.add(n['name'])
|
||||
dependents = [m for m in services if (n['name'] in get_service_names(m.get('links', []))) or (n['name'] in m.get('volumes_from', []))]
|
||||
for m in dependents:
|
||||
for m in get_service_dependents(n, services):
|
||||
visit(m)
|
||||
temporary_marked.remove(n['name'])
|
||||
unmarked.remove(n)
|
||||
@@ -58,20 +69,12 @@ class Project(object):
|
||||
for service_dict in sort_service_dicts(service_dicts):
|
||||
links = project.get_links(service_dict)
|
||||
volumes_from = project.get_volumes_from(service_dict)
|
||||
net = project.get_net(service_dict)
|
||||
|
||||
project.services.append(Service(client=client, project=name, links=links, volumes_from=volumes_from, **service_dict))
|
||||
project.services.append(Service(client=client, project=name, links=links, net=net,
|
||||
volumes_from=volumes_from, **service_dict))
|
||||
return project
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, name, config, client):
|
||||
dicts = []
|
||||
for service_name, service in list(config.items()):
|
||||
if not isinstance(service, dict):
|
||||
raise ConfigurationError('Service "%s" doesn\'t have any configuration options. All top level keys in your fig.yml must map to a dictionary of configuration options.')
|
||||
service['name'] = service_name
|
||||
dicts.append(service)
|
||||
return cls.from_dicts(name, dicts, client)
|
||||
|
||||
def get_service(self, name):
|
||||
"""
|
||||
Retrieve a service by name. Raises NoSuchService
|
||||
@@ -83,31 +86,31 @@ class Project(object):
|
||||
|
||||
raise NoSuchService(name)
|
||||
|
||||
def get_services(self, service_names=None, include_links=False):
|
||||
def get_services(self, service_names=None, include_deps=False):
|
||||
"""
|
||||
Returns a list of this project's services filtered
|
||||
by the provided list of names, or all services if service_names is None
|
||||
or [].
|
||||
|
||||
If include_links is specified, returns a list including the links for
|
||||
If include_deps is specified, returns a list including the dependencies for
|
||||
service_names, in order of dependency.
|
||||
|
||||
Preserves the original order of self.services where possible,
|
||||
reordering as needed to resolve links.
|
||||
reordering as needed to resolve dependencies.
|
||||
|
||||
Raises NoSuchService if any of the named services do not exist.
|
||||
"""
|
||||
if service_names is None or len(service_names) == 0:
|
||||
return self.get_services(
|
||||
service_names=[s.name for s in self.services],
|
||||
include_links=include_links
|
||||
include_deps=include_deps
|
||||
)
|
||||
else:
|
||||
unsorted = [self.get_service(name) for name in service_names]
|
||||
services = [s for s in self.services if s in unsorted]
|
||||
|
||||
if include_links:
|
||||
services = reduce(self._inject_links, services, [])
|
||||
if include_deps:
|
||||
services = reduce(self._inject_deps, services, [])
|
||||
|
||||
uniques = []
|
||||
[uniques.append(s) for s in services if s not in uniques]
|
||||
@@ -144,6 +147,28 @@ class Project(object):
|
||||
del service_dict['volumes_from']
|
||||
return volumes_from
|
||||
|
||||
def get_net(self, service_dict):
|
||||
if 'net' in service_dict:
|
||||
net_name = get_service_name_from_net(service_dict.get('net'))
|
||||
|
||||
if net_name:
|
||||
try:
|
||||
net = self.get_service(net_name)
|
||||
except NoSuchService:
|
||||
try:
|
||||
net = Container.from_id(self.client, net_name)
|
||||
except APIError:
|
||||
raise ConfigurationError('Serivce "%s" is trying to use the network of "%s", which is not the name of a service or container.' % (service_dict['name'], net_name))
|
||||
else:
|
||||
net = service_dict['net']
|
||||
|
||||
del service_dict['net']
|
||||
|
||||
else:
|
||||
net = 'bridge'
|
||||
|
||||
return net
|
||||
|
||||
def start(self, service_names=None, **options):
|
||||
for service in self.get_services(service_names):
|
||||
service.start(**options)
|
||||
@@ -167,21 +192,32 @@ class Project(object):
|
||||
else:
|
||||
log.info('%s uses an image, skipping' % service.name)
|
||||
|
||||
def up(self, service_names=None, start_links=True, recreate=True):
|
||||
def up(self,
|
||||
service_names=None,
|
||||
start_deps=True,
|
||||
recreate=True,
|
||||
insecure_registry=False,
|
||||
detach=False,
|
||||
do_build=True):
|
||||
running_containers = []
|
||||
|
||||
for service in self.get_services(service_names, include_links=start_links):
|
||||
for service in self.get_services(service_names, include_deps=start_deps):
|
||||
if recreate:
|
||||
for (_, container) in service.recreate_containers():
|
||||
for (_, container) in service.recreate_containers(
|
||||
insecure_registry=insecure_registry,
|
||||
detach=detach,
|
||||
do_build=do_build):
|
||||
running_containers.append(container)
|
||||
else:
|
||||
for container in service.start_or_create_containers():
|
||||
for container in service.start_or_create_containers(
|
||||
insecure_registry=insecure_registry,
|
||||
detach=detach,
|
||||
do_build=do_build):
|
||||
running_containers.append(container)
|
||||
|
||||
return running_containers
|
||||
|
||||
def pull(self, service_names=None, insecure_registry=False):
|
||||
for service in self.get_services(service_names, include_links=True):
|
||||
for service in self.get_services(service_names, include_deps=True):
|
||||
service.pull(insecure_registry=insecure_registry)
|
||||
|
||||
def remove_stopped(self, service_names=None, **options):
|
||||
@@ -194,19 +230,22 @@ class Project(object):
|
||||
for service in self.get_services(service_names)
|
||||
if service.has_container(container, one_off=one_off)]
|
||||
|
||||
def _inject_links(self, acc, service):
|
||||
linked_names = service.get_linked_names()
|
||||
def _inject_deps(self, acc, service):
|
||||
net_name = service.get_net_name()
|
||||
dep_names = (service.get_linked_names() +
|
||||
service.get_volumes_from_names() +
|
||||
([net_name] if net_name else []))
|
||||
|
||||
if len(linked_names) > 0:
|
||||
linked_services = self.get_services(
|
||||
service_names=linked_names,
|
||||
include_links=True
|
||||
if len(dep_names) > 0:
|
||||
dep_services = self.get_services(
|
||||
service_names=list(set(dep_names)),
|
||||
include_deps=True
|
||||
)
|
||||
else:
|
||||
linked_services = []
|
||||
dep_services = []
|
||||
|
||||
linked_services.append(service)
|
||||
return acc + linked_services
|
||||
dep_services.append(service)
|
||||
return acc + dep_services
|
||||
|
||||
|
||||
class NoSuchService(Exception):
|
||||
@@ -218,13 +257,5 @@ class NoSuchService(Exception):
|
||||
return self.msg
|
||||
|
||||
|
||||
class ConfigurationError(Exception):
|
||||
def __init__(self, msg):
|
||||
self.msg = msg
|
||||
|
||||
def __str__(self):
|
||||
return self.msg
|
||||
|
||||
|
||||
class DependencyError(ConfigurationError):
|
||||
pass
|
||||
@@ -3,28 +3,30 @@ from __future__ import absolute_import
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import re
|
||||
import os
|
||||
from operator import attrgetter
|
||||
import sys
|
||||
import six
|
||||
|
||||
from docker.errors import APIError
|
||||
from docker.utils import create_host_config
|
||||
|
||||
from .container import Container
|
||||
from .config import DOCKER_CONFIG_KEYS
|
||||
from .container import Container, get_container_name
|
||||
from .progress_stream import stream_output, StreamOutputError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
DOCKER_CONFIG_KEYS = ['image', 'command', 'hostname', 'domainname', 'user', 'detach', 'stdin_open', 'tty', 'mem_limit', 'ports', 'environment', 'dns', 'volumes', 'entrypoint', 'privileged', 'volumes_from', 'net', 'working_dir']
|
||||
DOCKER_CONFIG_HINTS = {
|
||||
'link' : 'links',
|
||||
'port' : 'ports',
|
||||
'privilege' : 'privileged',
|
||||
'priviliged': 'privileged',
|
||||
'privilige' : 'privileged',
|
||||
'volume' : 'volumes',
|
||||
'workdir' : 'working_dir',
|
||||
}
|
||||
DOCKER_START_KEYS = [
|
||||
'cap_add',
|
||||
'cap_drop',
|
||||
'dns',
|
||||
'dns_search',
|
||||
'env_file',
|
||||
'net',
|
||||
'privileged',
|
||||
'restart',
|
||||
]
|
||||
|
||||
VALID_NAME_CHARS = '[a-zA-Z0-9]'
|
||||
|
||||
@@ -50,7 +52,7 @@ ServiceName = namedtuple('ServiceName', 'project service number')
|
||||
|
||||
|
||||
class Service(object):
|
||||
def __init__(self, name, client=None, project='default', links=None, volumes_from=None, **options):
|
||||
def __init__(self, name, client=None, project='default', links=None, external_links=None, volumes_from=None, net=None, **options):
|
||||
if not re.match('^%s+$' % VALID_NAME_CHARS, name):
|
||||
raise ConfigError('Invalid service name "%s" - only %s are allowed' % (name, VALID_NAME_CHARS))
|
||||
if not re.match('^%s+$' % VALID_NAME_CHARS, project):
|
||||
@@ -58,20 +60,13 @@ class Service(object):
|
||||
if 'image' in options and 'build' in options:
|
||||
raise ConfigError('Service %s has both an image and build path specified. A service can either be built to image or use an existing image, not both.' % name)
|
||||
|
||||
supported_options = DOCKER_CONFIG_KEYS + ['build', 'expose']
|
||||
|
||||
for k in options:
|
||||
if k not in supported_options:
|
||||
msg = "Unsupported config option for %s service: '%s'" % (name, k)
|
||||
if k in DOCKER_CONFIG_HINTS:
|
||||
msg += " (did you mean '%s'?)" % DOCKER_CONFIG_HINTS[k]
|
||||
raise ConfigError(msg)
|
||||
|
||||
self.name = name
|
||||
self.client = client
|
||||
self.project = project
|
||||
self.links = links or []
|
||||
self.external_links = external_links or []
|
||||
self.volumes_from = volumes_from or []
|
||||
self.net = net or None
|
||||
self.options = options
|
||||
|
||||
def containers(self, stopped=False, one_off=False):
|
||||
@@ -88,7 +83,7 @@ class Service(object):
|
||||
return project == self.project and name == self.name
|
||||
|
||||
def get_container(self, number=1):
|
||||
"""Return a :class:`fig.container.Container` for this service. The
|
||||
"""Return a :class:`compose.container.Container` for this service. The
|
||||
container must be active, and match `number`.
|
||||
"""
|
||||
for container in self.client.containers():
|
||||
@@ -121,7 +116,8 @@ class Service(object):
|
||||
|
||||
def scale(self, desired_num):
|
||||
"""
|
||||
Adjusts the number of containers to the specified number and ensures they are running.
|
||||
Adjusts the number of containers to the specified number and ensures
|
||||
they are running.
|
||||
|
||||
- creates containers until there are at least `desired_num`
|
||||
- stops containers until there are at most `desired_num` running
|
||||
@@ -134,7 +130,8 @@ class Service(object):
|
||||
# Create enough containers
|
||||
containers = self.containers(stopped=True)
|
||||
while len(containers) < desired_num:
|
||||
containers.append(self.create_container())
|
||||
log.info("Creating %s..." % self._next_container_name(containers))
|
||||
containers.append(self.create_container(detach=True))
|
||||
|
||||
running_containers = []
|
||||
stopped_containers = []
|
||||
@@ -168,32 +165,53 @@ class Service(object):
|
||||
log.info("Removing %s..." % c.name)
|
||||
c.remove(**options)
|
||||
|
||||
def create_container(self, one_off=False, **override_options):
|
||||
def create_container(self,
|
||||
one_off=False,
|
||||
insecure_registry=False,
|
||||
do_build=True,
|
||||
intermediate_container=None,
|
||||
**override_options):
|
||||
"""
|
||||
Create a container for this service. If the image doesn't exist, attempt to pull
|
||||
it.
|
||||
"""
|
||||
container_options = self._get_container_create_options(override_options, one_off=one_off)
|
||||
container_options = self._get_container_create_options(
|
||||
override_options,
|
||||
one_off=one_off,
|
||||
intermediate_container=intermediate_container,
|
||||
)
|
||||
|
||||
if (do_build and
|
||||
self.can_be_built() and
|
||||
not self.client.images(name=self.full_name)):
|
||||
self.build()
|
||||
|
||||
try:
|
||||
return Container.create(self.client, **container_options)
|
||||
except APIError as e:
|
||||
if e.response.status_code == 404 and e.explanation and 'No such image' in str(e.explanation):
|
||||
log.info('Pulling image %s...' % container_options['image'])
|
||||
output = self.client.pull(container_options['image'], stream=True)
|
||||
output = self.client.pull(
|
||||
container_options['image'],
|
||||
stream=True,
|
||||
insecure_registry=insecure_registry
|
||||
)
|
||||
stream_output(output, sys.stdout)
|
||||
return Container.create(self.client, **container_options)
|
||||
raise
|
||||
|
||||
def recreate_containers(self, **override_options):
|
||||
def recreate_containers(self, insecure_registry=False, do_build=True, **override_options):
|
||||
"""
|
||||
If a container for this service doesn't exist, create and start one. If there are
|
||||
any, stop them, create+start new ones, and remove the old containers.
|
||||
"""
|
||||
containers = self.containers(stopped=True)
|
||||
|
||||
if not containers:
|
||||
log.info("Creating %s..." % self._next_container_name(containers))
|
||||
container = self.create_container(**override_options)
|
||||
container = self.create_container(
|
||||
insecure_registry=insecure_registry,
|
||||
do_build=do_build,
|
||||
**override_options)
|
||||
self.start_container(container)
|
||||
return [(None, container)]
|
||||
else:
|
||||
@@ -201,7 +219,7 @@ class Service(object):
|
||||
|
||||
for c in containers:
|
||||
log.info("Recreating %s..." % c.name)
|
||||
tuples.append(self.recreate_container(c, **override_options))
|
||||
tuples.append(self.recreate_container(c, insecure_registry=insecure_registry, **override_options))
|
||||
|
||||
return tuples
|
||||
|
||||
@@ -225,57 +243,50 @@ class Service(object):
|
||||
image=container.image,
|
||||
entrypoint=['/bin/echo'],
|
||||
command=[],
|
||||
detach=True,
|
||||
host_config=create_host_config(volumes_from=[container.id]),
|
||||
)
|
||||
intermediate_container.start(volumes_from=container.id)
|
||||
intermediate_container.start()
|
||||
intermediate_container.wait()
|
||||
container.remove()
|
||||
|
||||
options = dict(override_options)
|
||||
new_container = self.create_container(**options)
|
||||
self.start_container(new_container, intermediate_container=intermediate_container)
|
||||
new_container = self.create_container(
|
||||
do_build=False,
|
||||
intermediate_container=intermediate_container,
|
||||
**options
|
||||
)
|
||||
self.start_container(new_container)
|
||||
|
||||
intermediate_container.remove()
|
||||
|
||||
return (intermediate_container, new_container)
|
||||
|
||||
def start_container_if_stopped(self, container, **options):
|
||||
def start_container_if_stopped(self, container):
|
||||
if container.is_running:
|
||||
return container
|
||||
else:
|
||||
log.info("Starting %s..." % container.name)
|
||||
return self.start_container(container, **options)
|
||||
return self.start_container(container)
|
||||
|
||||
def start_container(self, container=None, intermediate_container=None, **override_options):
|
||||
container = container or self.create_container(**override_options)
|
||||
options = dict(self.options, **override_options)
|
||||
ports = dict(split_port(port) for port in options.get('ports') or [])
|
||||
|
||||
volume_bindings = dict(
|
||||
build_volume_binding(parse_volume_spec(volume))
|
||||
for volume in options.get('volumes') or []
|
||||
if ':' in volume)
|
||||
|
||||
privileged = options.get('privileged', False)
|
||||
net = options.get('net', 'bridge')
|
||||
dns = options.get('dns', None)
|
||||
|
||||
container.start(
|
||||
links=self._get_links(link_to_self=options.get('one_off', False)),
|
||||
port_bindings=ports,
|
||||
binds=volume_bindings,
|
||||
volumes_from=self._get_volumes_from(intermediate_container),
|
||||
privileged=privileged,
|
||||
network_mode=net,
|
||||
dns=dns,
|
||||
)
|
||||
def start_container(self, container):
|
||||
container.start()
|
||||
return container
|
||||
|
||||
def start_or_create_containers(self):
|
||||
def start_or_create_containers(
|
||||
self,
|
||||
insecure_registry=False,
|
||||
detach=False,
|
||||
do_build=True):
|
||||
containers = self.containers(stopped=True)
|
||||
|
||||
if not containers:
|
||||
log.info("Creating %s..." % self._next_container_name(containers))
|
||||
new_container = self.create_container()
|
||||
new_container = self.create_container(
|
||||
insecure_registry=insecure_registry,
|
||||
detach=detach,
|
||||
do_build=do_build,
|
||||
)
|
||||
return [self.start_container(new_container)]
|
||||
else:
|
||||
return [self.start_container_if_stopped(c) for c in containers]
|
||||
@@ -283,6 +294,15 @@ class Service(object):
|
||||
def get_linked_names(self):
|
||||
return [s.name for (s, _) in self.links]
|
||||
|
||||
def get_volumes_from_names(self):
|
||||
return [s.name for s in self.volumes_from if isinstance(s, Service)]
|
||||
|
||||
def get_net_name(self):
|
||||
if isinstance(self.net, Service):
|
||||
return self.net.name
|
||||
else:
|
||||
return
|
||||
|
||||
def _next_container_name(self, all_containers, one_off=False):
|
||||
bits = [self.project, self.name]
|
||||
if one_off:
|
||||
@@ -305,6 +325,12 @@ class Service(object):
|
||||
links.append((container.name, self.name))
|
||||
links.append((container.name, container.name))
|
||||
links.append((container.name, container.name_without_project))
|
||||
for external_link in self.external_links:
|
||||
if ':' not in external_link:
|
||||
link_name = external_link
|
||||
else:
|
||||
external_link, link_name = external_link.split(':')
|
||||
links.append((external_link, link_name))
|
||||
return links
|
||||
|
||||
def _get_volumes_from(self, intermediate_container=None):
|
||||
@@ -312,7 +338,6 @@ class Service(object):
|
||||
for volume_source in self.volumes_from:
|
||||
if isinstance(volume_source, Service):
|
||||
containers = volume_source.containers(stopped=True)
|
||||
|
||||
if not containers:
|
||||
volumes_from.append(volume_source.create_container().id)
|
||||
else:
|
||||
@@ -326,8 +351,29 @@ class Service(object):
|
||||
|
||||
return volumes_from
|
||||
|
||||
def _get_container_create_options(self, override_options, one_off=False):
|
||||
container_options = dict((k, self.options[k]) for k in DOCKER_CONFIG_KEYS if k in self.options)
|
||||
def _get_net(self):
|
||||
if not self.net:
|
||||
return "bridge"
|
||||
|
||||
if isinstance(self.net, Service):
|
||||
containers = self.net.containers()
|
||||
if len(containers) > 0:
|
||||
net = 'container:' + containers[0].id
|
||||
else:
|
||||
log.warning("Warning: Service %s is trying to use reuse the network stack "
|
||||
"of another service that is not running." % (self.net.name))
|
||||
net = None
|
||||
elif isinstance(self.net, Container):
|
||||
net = 'container:' + self.net.id
|
||||
else:
|
||||
net = self.net
|
||||
|
||||
return net
|
||||
|
||||
def _get_container_create_options(self, override_options, one_off=False, intermediate_container=None):
|
||||
container_options = dict(
|
||||
(k, self.options[k])
|
||||
for k in DOCKER_CONFIG_KEYS if k in self.options)
|
||||
container_options.update(override_options)
|
||||
|
||||
container_options['name'] = self._next_container_name(
|
||||
@@ -362,29 +408,68 @@ class Service(object):
|
||||
(parse_volume_spec(v).internal, {})
|
||||
for v in container_options['volumes'])
|
||||
|
||||
if 'environment' in container_options:
|
||||
if isinstance(container_options['environment'], list):
|
||||
container_options['environment'] = dict(split_env(e) for e in container_options['environment'])
|
||||
container_options['environment'] = dict(resolve_env(k, v) for k, v in container_options['environment'].iteritems())
|
||||
|
||||
if self.can_be_built():
|
||||
if len(self.client.images(name=self._build_tag_name())) == 0:
|
||||
self.build()
|
||||
container_options['image'] = self._build_tag_name()
|
||||
container_options['image'] = self.full_name
|
||||
else:
|
||||
container_options['image'] = self._get_image_name(container_options['image'])
|
||||
|
||||
# Delete options which are only used when starting
|
||||
for key in ['privileged', 'net', 'dns']:
|
||||
if key in container_options:
|
||||
del container_options[key]
|
||||
for key in DOCKER_START_KEYS:
|
||||
container_options.pop(key, None)
|
||||
|
||||
container_options['host_config'] = self._get_container_host_config(override_options, one_off=one_off, intermediate_container=intermediate_container)
|
||||
|
||||
return container_options
|
||||
|
||||
def _get_container_host_config(self, override_options, one_off=False, intermediate_container=None):
|
||||
options = dict(self.options, **override_options)
|
||||
port_bindings = build_port_bindings(options.get('ports') or [])
|
||||
|
||||
volume_bindings = dict(
|
||||
build_volume_binding(parse_volume_spec(volume))
|
||||
for volume in options.get('volumes') or []
|
||||
if ':' in volume)
|
||||
|
||||
privileged = options.get('privileged', False)
|
||||
cap_add = options.get('cap_add', None)
|
||||
cap_drop = options.get('cap_drop', None)
|
||||
|
||||
dns = options.get('dns', None)
|
||||
if isinstance(dns, six.string_types):
|
||||
dns = [dns]
|
||||
|
||||
dns_search = options.get('dns_search', None)
|
||||
if isinstance(dns_search, six.string_types):
|
||||
dns_search = [dns_search]
|
||||
|
||||
restart = parse_restart_spec(options.get('restart', None))
|
||||
|
||||
return create_host_config(
|
||||
links=self._get_links(link_to_self=one_off),
|
||||
port_bindings=port_bindings,
|
||||
binds=volume_bindings,
|
||||
volumes_from=self._get_volumes_from(intermediate_container),
|
||||
privileged=privileged,
|
||||
network_mode=self._get_net(),
|
||||
dns=dns,
|
||||
dns_search=dns_search,
|
||||
restart_policy=restart,
|
||||
cap_add=cap_add,
|
||||
cap_drop=cap_drop,
|
||||
)
|
||||
|
||||
def _get_image_name(self, image):
|
||||
repo, tag = parse_repository_tag(image)
|
||||
if tag == "":
|
||||
tag = "latest"
|
||||
return '%s:%s' % (repo, tag)
|
||||
|
||||
def build(self, no_cache=False):
|
||||
log.info('Building %s...' % self.name)
|
||||
|
||||
build_output = self.client.build(
|
||||
self.options['build'],
|
||||
tag=self._build_tag_name(),
|
||||
tag=self.full_name,
|
||||
stream=True,
|
||||
rm=True,
|
||||
nocache=no_cache,
|
||||
@@ -392,7 +477,7 @@ class Service(object):
|
||||
|
||||
try:
|
||||
all_events = stream_output(build_output, sys.stdout)
|
||||
except StreamOutputError, e:
|
||||
except StreamOutputError as e:
|
||||
raise BuildError(self, unicode(e))
|
||||
|
||||
image_id = None
|
||||
@@ -404,14 +489,15 @@ class Service(object):
|
||||
image_id = match.group(1)
|
||||
|
||||
if image_id is None:
|
||||
raise BuildError(self)
|
||||
raise BuildError(self, event if all_events else 'Unknown')
|
||||
|
||||
return image_id
|
||||
|
||||
def can_be_built(self):
|
||||
return 'build' in self.options
|
||||
|
||||
def _build_tag_name(self):
|
||||
@property
|
||||
def full_name(self):
|
||||
"""
|
||||
The tag to give to images built for this service.
|
||||
"""
|
||||
@@ -425,9 +511,10 @@ class Service(object):
|
||||
|
||||
def pull(self, insecure_registry=False):
|
||||
if 'image' in self.options:
|
||||
log.info('Pulling %s (%s)...' % (self.name, self.options.get('image')))
|
||||
image_name = self._get_image_name(self.options['image'])
|
||||
log.info('Pulling %s (%s)...' % (self.name, image_name))
|
||||
self.client.pull(
|
||||
self.options.get('image'),
|
||||
image_name,
|
||||
insecure_registry=insecure_registry
|
||||
)
|
||||
|
||||
@@ -451,16 +538,20 @@ def parse_name(name):
|
||||
return ServiceName(project, service_name, int(suffix))
|
||||
|
||||
|
||||
def get_container_name(container):
|
||||
if not container.get('Name') and not container.get('Names'):
|
||||
def parse_restart_spec(restart_config):
|
||||
if not restart_config:
|
||||
return None
|
||||
# inspect
|
||||
if 'Name' in container:
|
||||
return container['Name']
|
||||
# ps
|
||||
for name in container['Names']:
|
||||
if len(name.split('/')) == 2:
|
||||
return name[1:]
|
||||
parts = restart_config.split(':')
|
||||
if len(parts) > 2:
|
||||
raise ConfigError("Restart %s has incorrect format, should be "
|
||||
"mode[:max_retry]" % restart_config)
|
||||
if len(parts) == 2:
|
||||
name, max_retry_count = parts
|
||||
else:
|
||||
name, = parts
|
||||
max_retry_count = 0
|
||||
|
||||
return {'Name': name, 'MaximumRetryCount': int(max_retry_count)}
|
||||
|
||||
|
||||
def parse_volume_spec(volume_config):
|
||||
@@ -483,10 +574,29 @@ def parse_volume_spec(volume_config):
|
||||
return VolumeSpec(external, internal, mode)
|
||||
|
||||
|
||||
def parse_repository_tag(s):
|
||||
if ":" not in s:
|
||||
return s, ""
|
||||
repo, tag = s.rsplit(":", 1)
|
||||
if "/" in tag:
|
||||
return s, ""
|
||||
return repo, tag
|
||||
|
||||
|
||||
def build_volume_binding(volume_spec):
|
||||
internal = {'bind': volume_spec.internal, 'ro': volume_spec.mode == 'ro'}
|
||||
external = os.path.expanduser(volume_spec.external)
|
||||
return os.path.abspath(os.path.expandvars(external)), internal
|
||||
return volume_spec.external, internal
|
||||
|
||||
|
||||
def build_port_bindings(ports):
|
||||
port_bindings = {}
|
||||
for port in ports:
|
||||
internal_port, external = split_port(port)
|
||||
if internal_port in port_bindings:
|
||||
port_bindings[internal_port].append(external)
|
||||
else:
|
||||
port_bindings[internal_port] = [external]
|
||||
return port_bindings
|
||||
|
||||
|
||||
def split_port(port):
|
||||
@@ -504,19 +614,3 @@ def split_port(port):
|
||||
|
||||
external_ip, external_port, internal_port = parts
|
||||
return internal_port, (external_ip, external_port or None)
|
||||
|
||||
|
||||
def split_env(env):
|
||||
if '=' in env:
|
||||
return env.split('=', 1)
|
||||
else:
|
||||
return env, None
|
||||
|
||||
|
||||
def resolve_env(key, val):
|
||||
if val is not None:
|
||||
return key, val
|
||||
elif key in os.environ:
|
||||
return key, os.environ[key]
|
||||
else:
|
||||
return key, ''
|
||||
358
contrib/completion/bash/docker-compose
Normal file
358
contrib/completion/bash/docker-compose
Normal file
@@ -0,0 +1,358 @@
|
||||
#!bash
|
||||
#
|
||||
# bash completion for docker-compose
|
||||
#
|
||||
# This work is based on the completion for the docker command.
|
||||
#
|
||||
# This script provides completion of:
|
||||
# - commands and their options
|
||||
# - service names
|
||||
# - filepaths
|
||||
#
|
||||
# To enable the completions either:
|
||||
# - place this file in /etc/bash_completion.d
|
||||
# or
|
||||
# - copy this file to e.g. ~/.docker-compose-completion.sh and add the line
|
||||
# below to your .bashrc after bash completion features are loaded
|
||||
# . ~/.docker-compose-completion.sh
|
||||
|
||||
|
||||
# For compatibility reasons, Compose and therefore its completion supports several
|
||||
# stack compositon files as listed here, in descending priority.
|
||||
# Support for these filenames might be dropped in some future version.
|
||||
__docker-compose_compose_file() {
|
||||
local file
|
||||
for file in docker-compose.y{,a}ml fig.y{,a}ml ; do
|
||||
[ -e $file ] && {
|
||||
echo $file
|
||||
return
|
||||
}
|
||||
done
|
||||
echo docker-compose.yml
|
||||
}
|
||||
|
||||
# Extracts all service names from the compose file.
|
||||
___docker-compose_all_services_in_compose_file() {
|
||||
awk -F: '/^[a-zA-Z0-9]/{print $1}' "${compose_file:-$(__docker-compose_compose_file)}" 2>/dev/null
|
||||
}
|
||||
|
||||
# All services, even those without an existing container
|
||||
__docker-compose_services_all() {
|
||||
COMPREPLY=( $(compgen -W "$(___docker-compose_all_services_in_compose_file)" -- "$cur") )
|
||||
}
|
||||
|
||||
# All services that have an entry with the given key in their compose_file section
|
||||
___docker-compose_services_with_key() {
|
||||
# flatten sections to one line, then filter lines containing the key and return section name.
|
||||
awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' "${compose_file:-$(__docker-compose_compose_file)}" | awk -F: -v key=": +$1:" '$0 ~ key {print $1}'
|
||||
}
|
||||
|
||||
# All services that are defined by a Dockerfile reference
|
||||
__docker-compose_services_from_build() {
|
||||
COMPREPLY=( $(compgen -W "$(___docker-compose_services_with_key build)" -- "$cur") )
|
||||
}
|
||||
|
||||
# All services that are defined by an image
|
||||
__docker-compose_services_from_image() {
|
||||
COMPREPLY=( $(compgen -W "$(___docker-compose_services_with_key image)" -- "$cur") )
|
||||
}
|
||||
|
||||
# The services for which containers have been created, optionally filtered
|
||||
# by a boolean expression passed in as argument.
|
||||
__docker-compose_services_with() {
|
||||
local containers names
|
||||
containers="$(docker-compose 2>/dev/null ${compose_file:+-f $compose_file} ${compose_project:+-p $compose_project} ps -q)"
|
||||
names=( $(docker 2>/dev/null inspect --format "{{if ${1:-true}}} {{ .Name }} {{end}}" $containers) )
|
||||
names=( ${names[@]%_*} ) # strip trailing numbers
|
||||
names=( ${names[@]#*_} ) # strip project name
|
||||
COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") )
|
||||
}
|
||||
|
||||
# The services for which at least one running container exists
|
||||
__docker-compose_services_running() {
|
||||
__docker-compose_services_with '.State.Running'
|
||||
}
|
||||
|
||||
# The services for which at least one stopped container exists
|
||||
__docker-compose_services_stopped() {
|
||||
__docker-compose_services_with 'not .State.Running'
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_build() {
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--no-cache" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker-compose_services_from_build
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_docker-compose() {
|
||||
case "$prev" in
|
||||
--file|-f)
|
||||
_filedir y?(a)ml
|
||||
return
|
||||
;;
|
||||
--project-name|-p)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--help -h --verbose --version --file -f --project-name -p" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_help() {
|
||||
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_kill() {
|
||||
case "$prev" in
|
||||
-s)
|
||||
COMPREPLY=( $( compgen -W "SIGHUP SIGINT SIGKILL SIGUSR1 SIGUSR2" -- "$(echo $cur | tr '[:lower:]' '[:upper:]')" ) )
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "-s" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker-compose_services_running
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_logs() {
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--no-color" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker-compose_services_all
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_port() {
|
||||
case "$prev" in
|
||||
--protocol)
|
||||
COMPREPLY=( $( compgen -W "tcp udp" -- "$cur" ) )
|
||||
return;
|
||||
;;
|
||||
--index)
|
||||
return;
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--protocol --index" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker-compose_services_all
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_ps() {
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "-q" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker-compose_services_all
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_pull() {
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--allow-insecure-ssl" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker-compose_services_from_image
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_restart() {
|
||||
case "$prev" in
|
||||
-t | --timeout)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "-t --timeout" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker-compose_services_running
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_rm() {
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--force -f -v" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker-compose_services_stopped
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_run() {
|
||||
case "$prev" in
|
||||
-e)
|
||||
COMPREPLY=( $( compgen -e -- "$cur" ) )
|
||||
compopt -o nospace
|
||||
return
|
||||
;;
|
||||
--entrypoint|--user|-u)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--allow-insecure-ssl -d --entrypoint -e --no-deps --rm --service-ports -T --user -u" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker-compose_services_all
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_scale() {
|
||||
case "$prev" in
|
||||
=)
|
||||
COMPREPLY=("$cur")
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=( $(compgen -S "=" -W "$(___docker-compose_all_services_in_compose_file)" -- "$cur") )
|
||||
compopt -o nospace
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_start() {
|
||||
__docker-compose_services_stopped
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_stop() {
|
||||
case "$prev" in
|
||||
-t | --timeout)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "-t --timeout" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker-compose_services_running
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose_up() {
|
||||
case "$prev" in
|
||||
-t | --timeout)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--allow-insecure-ssl -d --no-build --no-color --no-deps --no-recreate -t --timeout" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker-compose_services_all
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker-compose() {
|
||||
local commands=(
|
||||
build
|
||||
help
|
||||
kill
|
||||
logs
|
||||
port
|
||||
ps
|
||||
pull
|
||||
restart
|
||||
rm
|
||||
run
|
||||
scale
|
||||
start
|
||||
stop
|
||||
up
|
||||
)
|
||||
|
||||
COMPREPLY=()
|
||||
local cur prev words cword
|
||||
_get_comp_words_by_ref -n : cur prev words cword
|
||||
|
||||
# search subcommand and invoke its handler.
|
||||
# special treatment of some top-level options
|
||||
local command='docker-compose'
|
||||
local counter=1
|
||||
local compose_file compose_project
|
||||
while [ $counter -lt $cword ]; do
|
||||
case "${words[$counter]}" in
|
||||
-f|--file)
|
||||
(( counter++ ))
|
||||
compose_file="${words[$counter]}"
|
||||
;;
|
||||
-p|--project-name)
|
||||
(( counter++ ))
|
||||
compose_project="${words[$counter]}"
|
||||
;;
|
||||
-*)
|
||||
;;
|
||||
*)
|
||||
command="${words[$counter]}"
|
||||
break
|
||||
;;
|
||||
esac
|
||||
(( counter++ ))
|
||||
done
|
||||
|
||||
local completions_func=_docker-compose_${command}
|
||||
declare -F $completions_func >/dev/null && $completions_func
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
complete -F _docker-compose docker-compose
|
||||
@@ -1 +0,0 @@
|
||||
/_site
|
||||
@@ -1 +0,0 @@
|
||||
www.fig.sh
|
||||
@@ -1,10 +1,15 @@
|
||||
FROM ubuntu:13.10
|
||||
RUN apt-get -qq update && apt-get install -y ruby1.8 bundler python
|
||||
RUN locale-gen en_US.UTF-8
|
||||
ADD Gemfile /code/
|
||||
ADD Gemfile.lock /code/
|
||||
WORKDIR /code
|
||||
RUN bundle install
|
||||
ADD . /code
|
||||
EXPOSE 4000
|
||||
CMD bundle exec jekyll build
|
||||
FROM docs/base:latest
|
||||
MAINTAINER Sven Dowideit <SvenDowideit@docker.com> (@SvenDowideit)
|
||||
|
||||
# to get the git info for this repo
|
||||
COPY . /src
|
||||
|
||||
# Reset the /docs dir so we can replace the theme meta with the new repo's git info
|
||||
RUN git reset --hard
|
||||
|
||||
RUN grep "__version" /src/compose/__init__.py | sed "s/.*'\(.*\)'/\1/" > /docs/VERSION
|
||||
COPY docs/* /docs/sources/compose/
|
||||
COPY docs/mkdocs.yml /docs/mkdocs-compose.yml
|
||||
|
||||
# Then build everything together, ready for mkdocs
|
||||
RUN /docs/build.sh
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'github-pages'
|
||||
@@ -1,62 +0,0 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
RedCloth (4.2.9)
|
||||
blankslate (2.1.2.4)
|
||||
classifier (1.3.3)
|
||||
fast-stemmer (>= 1.0.0)
|
||||
colorator (0.1)
|
||||
commander (4.1.5)
|
||||
highline (~> 1.6.11)
|
||||
fast-stemmer (1.0.2)
|
||||
ffi (1.9.3)
|
||||
github-pages (12)
|
||||
RedCloth (= 4.2.9)
|
||||
jekyll (= 1.4.2)
|
||||
kramdown (= 1.2.0)
|
||||
liquid (= 2.5.4)
|
||||
maruku (= 0.7.0)
|
||||
rdiscount (= 2.1.7)
|
||||
redcarpet (= 2.3.0)
|
||||
highline (1.6.20)
|
||||
jekyll (1.4.2)
|
||||
classifier (~> 1.3)
|
||||
colorator (~> 0.1)
|
||||
commander (~> 4.1.3)
|
||||
liquid (~> 2.5.2)
|
||||
listen (~> 1.3)
|
||||
maruku (~> 0.7.0)
|
||||
pygments.rb (~> 0.5.0)
|
||||
redcarpet (~> 2.3.0)
|
||||
safe_yaml (~> 0.9.7)
|
||||
toml (~> 0.1.0)
|
||||
kramdown (1.2.0)
|
||||
liquid (2.5.4)
|
||||
listen (1.3.1)
|
||||
rb-fsevent (>= 0.9.3)
|
||||
rb-inotify (>= 0.9)
|
||||
rb-kqueue (>= 0.2)
|
||||
maruku (0.7.0)
|
||||
parslet (1.5.0)
|
||||
blankslate (~> 2.0)
|
||||
posix-spawn (0.3.8)
|
||||
pygments.rb (0.5.4)
|
||||
posix-spawn (~> 0.3.6)
|
||||
yajl-ruby (~> 1.1.0)
|
||||
rb-fsevent (0.9.4)
|
||||
rb-inotify (0.9.3)
|
||||
ffi (>= 0.5.0)
|
||||
rb-kqueue (0.2.0)
|
||||
ffi (>= 0.5.0)
|
||||
rdiscount (2.1.7)
|
||||
redcarpet (2.3.0)
|
||||
safe_yaml (0.9.7)
|
||||
toml (0.1.0)
|
||||
parslet (~> 1.5.0)
|
||||
yajl-ruby (1.1.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
github-pages
|
||||
@@ -1,3 +0,0 @@
|
||||
markdown: redcarpet
|
||||
encoding: utf-8
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-gb">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{ page.title }}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href='http://fonts.googleapis.com/css?family=Lilita+One|Lato:300,400,700' rel='stylesheet' type='text/css'>
|
||||
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/fig.css?{{ site.time | date:'%Y%m%d%U%H%N%S' }}">
|
||||
<link rel="canonical" href="http://www.fig.sh{% if page.url =="/index.html" %}/{% else %}{{ page.url }}{% endif %}">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="logo mobile-logo">
|
||||
<a href="index.html">
|
||||
<img src="img/logo.png">
|
||||
Fig
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="content">{{ content }}</div>
|
||||
|
||||
<div class="sidebar">
|
||||
<h1 class="logo">
|
||||
<a href="index.html">
|
||||
<img src="img/logo.png">
|
||||
Fig
|
||||
</a>
|
||||
</h1>
|
||||
|
||||
<ul class="nav">
|
||||
<li><a href="index.html">Home</a></li>
|
||||
<li><a href="install.html">Install</a></li>
|
||||
<li><a href="rails.html">Get started with Rails</a></li>
|
||||
<li><a href="django.html">Get started with Django</a></li>
|
||||
<li><a href="wordpress.html">Get started with Wordpress</a></li>
|
||||
</ul>
|
||||
<ul class="nav">
|
||||
<li>Reference:</li>
|
||||
<ul>
|
||||
<li><a href="yml.html">fig.yml</a></li>
|
||||
<li><a href="cli.html">Commands</a></li>
|
||||
<li><a href="env.html">Environment variables</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
<ul class="nav">
|
||||
<li><a href="https://github.com/docker/fig">Fig on GitHub</a></li>
|
||||
<li><a href="http://webchat.freenode.net/?channels=%23docker-fig&uio=d4">#docker-fig on Freenode</a></li>
|
||||
</ul>
|
||||
|
||||
<p>Fig is a project from <a href="https://www.docker.com">Docker</a>.</p>
|
||||
|
||||
<div class="badges">
|
||||
<iframe src="http://ghbtns.com/github-btn.html?user=docker&repo=fig&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="100" height="20"></iframe>
|
||||
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://orchardup.github.io/fig/">Tweet</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-43996733-3', 'orchardup.github.io');
|
||||
ga('send', 'pageview');
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
143
docs/cli.md
143
docs/cli.md
@@ -1,42 +1,47 @@
|
||||
---
|
||||
layout: default
|
||||
title: Fig CLI reference
|
||||
---
|
||||
page_title: Compose CLI reference
|
||||
page_description: Compose CLI reference
|
||||
page_keywords: fig, composition, compose, docker, orchestration, cli, reference
|
||||
|
||||
CLI reference
|
||||
=============
|
||||
|
||||
Most commands are run against one or more services. If the service is omitted, it will apply to all services.
|
||||
# CLI reference
|
||||
|
||||
Run `fig [COMMAND] --help` for full usage.
|
||||
Most Docker Compose commands are run against one or more services. If
|
||||
the service is not specified, the command will apply to all services.
|
||||
|
||||
For full usage information, run `docker-compose [COMMAND] --help`.
|
||||
|
||||
## Commands
|
||||
|
||||
### build
|
||||
|
||||
Build or rebuild services.
|
||||
Builds or rebuilds services.
|
||||
|
||||
Services are built once and then tagged as `project_service`, e.g. `figtest_db`. If you change a service's `Dockerfile` or the contents of its build directory, you can run `fig build` to rebuild it.
|
||||
Services are built once and then tagged as `project_service`, e.g.,
|
||||
`composetest_db`. If you change a service's Dockerfile or the contents of its
|
||||
build directory, run `docker-compose build` to rebuild it.
|
||||
|
||||
### help
|
||||
|
||||
Get help on a command.
|
||||
Displays help and usage instructions for a command.
|
||||
|
||||
### kill
|
||||
|
||||
Force stop service containers.
|
||||
Forces running containers to stop by sending a `SIGKILL` signal. Optionally the
|
||||
signal can be passed, for example:
|
||||
|
||||
$ docker-compose kill -s SIGINT
|
||||
|
||||
### logs
|
||||
|
||||
View output from services.
|
||||
Displays log output from services.
|
||||
|
||||
### port
|
||||
|
||||
Print the public port for a port binding
|
||||
Prints the public port for a port binding
|
||||
|
||||
### ps
|
||||
|
||||
List containers.
|
||||
Lists containers.
|
||||
|
||||
### pull
|
||||
|
||||
@@ -44,81 +49,133 @@ Pulls service images.
|
||||
|
||||
### rm
|
||||
|
||||
Remove stopped service containers.
|
||||
Removes stopped service containers.
|
||||
|
||||
|
||||
### run
|
||||
|
||||
Run a one-off command on a service.
|
||||
Runs a one-off command on a service.
|
||||
|
||||
For example:
|
||||
For example,
|
||||
|
||||
$ fig run web python manage.py shell
|
||||
$ docker-compose run web python manage.py shell
|
||||
|
||||
By default, linked services will be started, unless they are already running.
|
||||
will start the `web` service and then run `manage.py shell` in python.
|
||||
Note that by default, linked services will also be started, unless they are
|
||||
already running.
|
||||
|
||||
One-off commands are started in new containers with the same config as a normal container for that service, so volumes, links, etc will all be created as expected. The only thing different to a normal container is the command will be overridden with the one specified and no ports will be created in case they collide.
|
||||
One-off commands are started in new containers with the same configuration as a
|
||||
normal container for that service, so volumes, links, etc will all be created as
|
||||
expected. When using `run`, there are two differences from bringing up a
|
||||
container normally:
|
||||
|
||||
Links are also created between one-off commands and the other containers for that service so you can do stuff like this:
|
||||
1. the command will be overridden with the one specified. So, if you run
|
||||
`docker-compose run web bash`, the container's web command (which could default
|
||||
to, e.g., `python app.py`) will be overridden to `bash`
|
||||
|
||||
$ fig run db psql -h db -U docker
|
||||
2. by default no ports will be created in case they collide with already opened
|
||||
ports.
|
||||
|
||||
If you do not want linked containers to be started when running the one-off command, specify the `--no-deps` flag:
|
||||
Links are also created between one-off commands and the other containers which
|
||||
are part of that service. So, for example, you could run:
|
||||
|
||||
$ fig run --no-deps web python manage.py shell
|
||||
$ docker-compose run db psql -h db -U docker
|
||||
|
||||
This would open up an interactive PostgreSQL shell for the linked `db` container
|
||||
(which would get created or started as needed).
|
||||
|
||||
If you do not want linked containers to start when running the one-off command,
|
||||
specify the `--no-deps` flag:
|
||||
|
||||
$ docker-compose run --no-deps web python manage.py shell
|
||||
|
||||
Similarly, if you do want the service's ports to be created and mapped to the
|
||||
host, specify the `--service-ports` flag:
|
||||
$ docker-compose run --service-ports web python manage.py shell
|
||||
|
||||
### scale
|
||||
|
||||
Set number of containers to run for a service.
|
||||
Sets the number of containers to run for a service.
|
||||
|
||||
Numbers are specified in the form `service=num` as arguments.
|
||||
For example:
|
||||
Numbers are specified as arguments in the form `service=num`. For example:
|
||||
|
||||
$ fig scale web=2 worker=3
|
||||
$ docker-compose scale web=2 worker=3
|
||||
|
||||
### start
|
||||
|
||||
Start existing containers for a service.
|
||||
Starts existing containers for a service.
|
||||
|
||||
### stop
|
||||
|
||||
Stop running containers without removing them. They can be started again with `fig start`.
|
||||
Stops running containers without removing them. They can be started again with
|
||||
`docker-compose start`.
|
||||
|
||||
### up
|
||||
|
||||
Build, (re)create, start and attach to containers for a service.
|
||||
Builds, (re)creates, starts, and attaches to containers for a service.
|
||||
|
||||
Linked services will be started, unless they are already running.
|
||||
|
||||
By default, `fig up` will aggregate the output of each container, and when it exits, all containers will be stopped. If you run `fig up -d`, it'll start the containers in the background and leave them running.
|
||||
By default, `docker-compose up` will aggregate the output of each container and,
|
||||
when it exits, all containers will be stopped. Running `docker-compose up -d`,
|
||||
will start the containers in the background and leave them running.
|
||||
|
||||
By default if there are existing containers for a service, `fig up` will stop and recreate them (preserving mounted volumes with [volumes-from]), so that changes in `fig.yml` are picked up. If you do no want containers to be stopped and recreated, use `fig up --no-recreate`. This will still start any stopped containers, if needed.
|
||||
By default, if there are existing containers for a service, `docker-compose up` will stop and recreate them (preserving mounted volumes with [volumes-from]), so that changes in `docker-compose.yml` are picked up. If you do not want containers stopped and recreated, use `docker-compose up --no-recreate`. This will still start any stopped containers, if needed.
|
||||
|
||||
[volumes-from]: http://docs.docker.io/en/latest/use/working_with_volumes/
|
||||
|
||||
## Options
|
||||
|
||||
### --verbose
|
||||
|
||||
Shows more output
|
||||
|
||||
### --version
|
||||
|
||||
Prints version and exits
|
||||
|
||||
### -f, --file FILE
|
||||
|
||||
Specifies an alternate Compose yaml file (default: `docker-compose.yml`)
|
||||
|
||||
### -p, --project-name NAME
|
||||
|
||||
Specifies an alternate project name (default: current directory name)
|
||||
|
||||
|
||||
## Environment Variables
|
||||
|
||||
Several environment variables can be used to configure Fig's behaviour.
|
||||
Several environment variables are available for you to configure Compose's behaviour.
|
||||
|
||||
Variables starting with `DOCKER_` are the same as those used to configure the Docker command-line client. If you're using boot2docker, `$(boot2docker shellinit)` will set them to their correct values.
|
||||
Variables starting with `DOCKER_` are the same as those used to configure the
|
||||
Docker command-line client. If you're using boot2docker, `$(boot2docker shellinit)`
|
||||
will set them to their correct values.
|
||||
|
||||
### FIG\_PROJECT\_NAME
|
||||
### COMPOSE\_PROJECT\_NAME
|
||||
|
||||
Set the project name, which is prepended to the name of every container started by Fig. Defaults to the `basename` of the current working directory.
|
||||
Sets the project name, which is prepended to the name of every container started by Compose. Defaults to the `basename` of the current working directory.
|
||||
|
||||
### FIG\_FILE
|
||||
### COMPOSE\_FILE
|
||||
|
||||
Set the path to the `fig.yml` to use. Defaults to `fig.yml` in the current working directory.
|
||||
Sets the path to the `docker-compose.yml` to use. Defaults to `docker-compose.yml` in the current working directory.
|
||||
|
||||
### DOCKER\_HOST
|
||||
|
||||
Set the URL to the docker daemon. Defaults to `unix:///var/run/docker.sock`, as with the docker client.
|
||||
Sets the URL of the docker daemon. As with the Docker client, defaults to `unix:///var/run/docker.sock`.
|
||||
|
||||
### DOCKER\_TLS\_VERIFY
|
||||
|
||||
When set to anything other than an empty string, enables TLS communication with the daemon.
|
||||
When set to anything other than an empty string, enables TLS communication with
|
||||
the daemon.
|
||||
|
||||
### DOCKER\_CERT\_PATH
|
||||
|
||||
Configure the path to the `ca.pem`, `cert.pem` and `key.pem` files used for TLS verification. Defaults to `~/.docker`.
|
||||
Configures the path to the `ca.pem`, `cert.pem`, and `key.pem` files used for TLS verification. Defaults to `~/.docker`.
|
||||
|
||||
## Compose documentation
|
||||
|
||||
- [Installing Compose](install.md)
|
||||
- [User guide](index.md)
|
||||
- [Yaml file reference](yml.md)
|
||||
- [Compose environment variables](env.md)
|
||||
- [Compose command line completion](completion.md)
|
||||
|
||||
41
docs/completion.md
Normal file
41
docs/completion.md
Normal file
@@ -0,0 +1,41 @@
|
||||
---
|
||||
layout: default
|
||||
title: Command Completion
|
||||
---
|
||||
|
||||
Command Completion
|
||||
==================
|
||||
|
||||
Compose comes with [command completion](http://en.wikipedia.org/wiki/Command-line_completion)
|
||||
for the bash shell.
|
||||
|
||||
Installing Command Completion
|
||||
-----------------------------
|
||||
|
||||
Make sure bash completion is installed. If you use a current Linux in a non-minimal installation, bash completion should be available.
|
||||
On a Mac, install with `brew install bash-completion`
|
||||
|
||||
Place the completion script in `/etc/bash_completion.d/` (`/usr/local/etc/bash_completion.d/` on a Mac), using e.g.
|
||||
|
||||
curl -L https://raw.githubusercontent.com/docker/compose/1.2.0/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
|
||||
|
||||
Completion will be available upon next login.
|
||||
|
||||
Available completions
|
||||
---------------------
|
||||
Depending on what you typed on the command line so far, it will complete
|
||||
|
||||
- available docker-compose commands
|
||||
- options that are available for a particular command
|
||||
- service names that make sense in a given context (e.g. services with running or stopped instances or services based on images vs. services based on Dockerfiles). For `docker-compose scale`, completed service names will automatically have "=" appended.
|
||||
- arguments for selected options, e.g. `docker-compose kill -s` will complete some signals like SIGHUP and SIGUSR1.
|
||||
|
||||
Enjoy working with Compose faster and with less typos!
|
||||
|
||||
## Compose documentation
|
||||
|
||||
- [Installing Compose](install.md)
|
||||
- [User guide](index.md)
|
||||
- [Command line reference](cli.md)
|
||||
- [Yaml file reference](yml.md)
|
||||
- [Compose environment variables](env.md)
|
||||
7
docs/css/bootstrap.min.css
vendored
7
docs/css/bootstrap.min.css
vendored
File diff suppressed because one or more lines are too long
187
docs/css/fig.css
187
docs/css/fig.css
@@ -1,187 +0,0 @@
|
||||
body {
|
||||
padding-top: 20px;
|
||||
padding-bottom: 60px;
|
||||
font-family: 'Lato', sans-serif;
|
||||
font-weight: 300;
|
||||
font-size: 18px;
|
||||
color: #362;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-family: 'Lato', sans-serif;
|
||||
font-weight: 400;
|
||||
color: #25594D;
|
||||
}
|
||||
|
||||
h2, h3, h4, h5, h6 {
|
||||
margin-top: 1.5em;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
a, a:hover, a:visited {
|
||||
color: #4D9900;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
pre, code {
|
||||
border: none;
|
||||
background: #D5E1B4;
|
||||
}
|
||||
|
||||
code, pre code {
|
||||
color: #484F40;
|
||||
}
|
||||
|
||||
pre {
|
||||
border-bottom: 2px solid #bec9a1;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 0.84em;
|
||||
}
|
||||
|
||||
pre code {
|
||||
background: none;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.container {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-family: 'Lilita One', sans-serif;
|
||||
font-size: 64px;
|
||||
margin: 20px 0 40px 0;
|
||||
}
|
||||
|
||||
.logo a {
|
||||
color: #a41211;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.logo img {
|
||||
width: 60px;
|
||||
vertical-align: -8px;
|
||||
}
|
||||
|
||||
.mobile-logo {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
font-size: 15px;
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.sidebar a {
|
||||
color: #a41211;
|
||||
}
|
||||
|
||||
.sidebar p {
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.sidebar {
|
||||
text-align: center;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.sidebar .logo {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.mobile-logo {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.logo {
|
||||
margin-top: 30px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.content h1 {
|
||||
margin: 60px 0 55px 0;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
width: 280px;
|
||||
overflow-y: auto;
|
||||
padding-left: 40px;
|
||||
padding-right: 10px;
|
||||
border-right: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.content {
|
||||
margin-left: 320px;
|
||||
max-width: 650px;
|
||||
}
|
||||
}
|
||||
|
||||
.nav {
|
||||
margin: 15px 0;
|
||||
}
|
||||
|
||||
.nav li a {
|
||||
display: block;
|
||||
padding: 5px 0;
|
||||
line-height: 1.2;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.nav li a:hover, .nav li a:focus {
|
||||
text-decoration: underline;
|
||||
background: none;
|
||||
}
|
||||
|
||||
.nav ul {
|
||||
padding-left: 20px;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.badges {
|
||||
margin: 40px 0;
|
||||
}
|
||||
|
||||
a.btn {
|
||||
background: #25594D;
|
||||
color: white;
|
||||
text-transform: uppercase;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a.btn:hover {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.strapline {
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.strapline {
|
||||
font-size: 40px;
|
||||
display: block;
|
||||
line-height: 1.2;
|
||||
margin-top: 25px;
|
||||
margin-bottom: 35px;
|
||||
}
|
||||
}
|
||||
|
||||
strong {
|
||||
font-weight: 700;
|
||||
}
|
||||
@@ -1,14 +1,23 @@
|
||||
---
|
||||
layout: default
|
||||
title: Getting started with Fig and Django
|
||||
---
|
||||
page_title: Quickstart Guide: Compose and Django
|
||||
page_description: Getting started with Docker Compose and Django
|
||||
page_keywords: documentation, docs, docker, compose, orchestration, containers,
|
||||
django
|
||||
|
||||
Getting started with Fig and Django
|
||||
===================================
|
||||
|
||||
Let's use Fig to set up and run a Django/PostgreSQL app. Before starting, you'll need to have [Fig installed](install.html).
|
||||
## Getting started with Compose and Django
|
||||
|
||||
Let's set up the three files that'll get us started. First, our app is going to be running inside a Docker container which contains all of its dependencies. We can define what goes inside that Docker container using a file called `Dockerfile`. It'll contain this to start with:
|
||||
|
||||
This Quick-start Guide will demonstrate how to use Compose to set up and run a
|
||||
simple Django/PostgreSQL app. Before starting, you'll need to have
|
||||
[Compose installed](install.md).
|
||||
|
||||
### Define the project
|
||||
|
||||
Start by setting up the three files you'll need to build the app. First, since
|
||||
your app is going to run inside a Docker container containing all of its
|
||||
dependencies, you'll need to define exactly what needs to be included in the
|
||||
container. This is done using a file called `Dockerfile`. To begin with, the
|
||||
Dockerfile consists of:
|
||||
|
||||
FROM python:2.7
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
@@ -18,14 +27,21 @@ Let's set up the three files that'll get us started. First, our app is going to
|
||||
RUN pip install -r requirements.txt
|
||||
ADD . /code/
|
||||
|
||||
That'll install our application inside an image with Python installed alongside all of our Python dependencies. For more information on how to write Dockerfiles, see the [Docker user guide](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile) and the [Dockerfile reference](http://docs.docker.com/reference/builder/).
|
||||
This Dockerfile will define an image that is used to build a container that
|
||||
includes your application and has Python installed alongside all of your Python
|
||||
dependencies. For more information on how to write Dockerfiles, see the
|
||||
[Docker user guide](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile) and the [Dockerfile reference](http://docs.docker.com/reference/builder/).
|
||||
|
||||
Second, we define our Python dependencies in a file called `requirements.txt`:
|
||||
Second, you'll define your Python dependencies in a file called
|
||||
`requirements.txt`:
|
||||
|
||||
Django
|
||||
psycopg2
|
||||
|
||||
Simple enough. Finally, this is all tied together with a file called `fig.yml`. It describes the services that our app comprises of (a web server and database), what Docker images they use, how they link together, what volumes will be mounted inside the containers and what ports they expose.
|
||||
Finally, this is all tied together with a file called `docker-compose.yml`. It
|
||||
describes the services that comprise your app (here, a web server and database),
|
||||
which Docker images they use, how they link together, what volumes will be
|
||||
mounted inside the containers, and what ports they expose.
|
||||
|
||||
db:
|
||||
image: postgres
|
||||
@@ -39,20 +55,28 @@ Simple enough. Finally, this is all tied together with a file called `fig.yml`.
|
||||
links:
|
||||
- db
|
||||
|
||||
See the [`fig.yml` reference](yml.html) for more information on how it works.
|
||||
See the [`docker-compose.yml` reference](yml.html) for more information on how
|
||||
this file works.
|
||||
|
||||
We can now start a Django project using `fig run`:
|
||||
### Build the project
|
||||
|
||||
$ fig run web django-admin.py startproject figexample .
|
||||
You can now start a Django project with `docker-compose run`:
|
||||
|
||||
First, Fig will build an image for the `web` service using the `Dockerfile`. It will then run `django-admin.py startproject figexample .` inside a container using that image.
|
||||
$ docker-compose run web django-admin.py startproject composeexample .
|
||||
|
||||
First, Compose will build an image for the `web` service using the `Dockerfile`.
|
||||
It will then run `django-admin.py startproject composeexample .` inside a
|
||||
container built using that image.
|
||||
|
||||
This will generate a Django app inside the current directory:
|
||||
|
||||
$ ls
|
||||
Dockerfile fig.yml figexample manage.py requirements.txt
|
||||
Dockerfile docker-compose.yml composeexample manage.py requirements.txt
|
||||
|
||||
First thing we need to do is set up the database connection. Replace the `DATABASES = ...` definition in `figexample/settings.py` to read:
|
||||
### Connect the database
|
||||
|
||||
Now you need to set up the database connection. Replace the `DATABASES = ...`
|
||||
definition in `composeexample/settings.py` to read:
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
@@ -64,9 +88,11 @@ First thing we need to do is set up the database connection. Replace the `DATABA
|
||||
}
|
||||
}
|
||||
|
||||
These settings are determined by the [postgres](https://registry.hub.docker.com/_/postgres/) Docker image we are using.
|
||||
These settings are determined by the
|
||||
[postgres](https://registry.hub.docker.com/_/postgres/) Docker image specified
|
||||
in the Dockerfile.
|
||||
|
||||
Then, run `fig up`:
|
||||
Then, run `docker-compose up`:
|
||||
|
||||
Recreating myapp_db_1...
|
||||
Recreating myapp_web_1...
|
||||
@@ -79,13 +105,23 @@ Then, run `fig up`:
|
||||
myapp_web_1 |
|
||||
myapp_web_1 | 0 errors found
|
||||
myapp_web_1 | January 27, 2014 - 12:12:40
|
||||
myapp_web_1 | Django version 1.6.1, using settings 'figexample.settings'
|
||||
myapp_web_1 | Django version 1.6.1, using settings 'composeexample.settings'
|
||||
myapp_web_1 | Starting development server at http://0.0.0.0:8000/
|
||||
myapp_web_1 | Quit the server with CONTROL-C.
|
||||
|
||||
And your Django app should be running at port 8000 on your docker daemon (if you're using boot2docker, `boot2docker ip` will tell you its address).
|
||||
Your Django app should nw be running at port 8000 on your Docker daemon (if
|
||||
you're using Boot2docker, `boot2docker ip` will tell you its address).
|
||||
|
||||
You can also run management commands with Docker. To set up your database, for example, run `fig up` and in another terminal run:
|
||||
You can also run management commands with Docker. To set up your database, for
|
||||
example, run `docker-compose up` and in another terminal run:
|
||||
|
||||
$ fig run web python manage.py syncdb
|
||||
$ docker-compose run web python manage.py syncdb
|
||||
|
||||
## More Compose documentation
|
||||
|
||||
- [Installing Compose](install.md)
|
||||
- [User guide](index.md)
|
||||
- [Command line reference](cli.md)
|
||||
- [Yaml file reference](yml.md)
|
||||
- [Compose environment variables](env.md)
|
||||
- [Compose command line completion](completion.md)
|
||||
|
||||
16
docs/env.md
16
docs/env.md
@@ -1,16 +1,16 @@
|
||||
---
|
||||
layout: default
|
||||
title: Fig environment variables reference
|
||||
title: Compose environment variables reference
|
||||
---
|
||||
|
||||
Environment variables reference
|
||||
===============================
|
||||
|
||||
**Note:** Environment variables are no longer the recommended method for connecting to linked services. Instead, you should use the link name (by default, the name of the linked service) as the hostname to connect to. See the [fig.yml documentation](yml.html#links) for details.
|
||||
**Note:** Environment variables are no longer the recommended method for connecting to linked services. Instead, you should use the link name (by default, the name of the linked service) as the hostname to connect to. See the [docker-compose.yml documentation](yml.md#links) for details.
|
||||
|
||||
Fig uses [Docker links] to expose services' containers to one another. Each linked container injects a set of environment variables, each of which begins with the uppercase name of the container.
|
||||
Compose uses [Docker links] to expose services' containers to one another. Each linked container injects a set of environment variables, each of which begins with the uppercase name of the container.
|
||||
|
||||
To see what environment variables are available to a service, run `fig run SERVICE env`.
|
||||
To see what environment variables are available to a service, run `docker-compose run SERVICE env`.
|
||||
|
||||
<b><i>name</i>\_PORT</b><br>
|
||||
Full URL, e.g. `DB_PORT=tcp://172.17.0.5:5432`
|
||||
@@ -31,3 +31,11 @@ Protocol (tcp or udp), e.g. `DB_PORT_5432_TCP_PROTO=tcp`
|
||||
Fully qualified container name, e.g. `DB_1_NAME=/myapp_web_1/myapp_db_1`
|
||||
|
||||
[Docker links]: http://docs.docker.com/userguide/dockerlinks/
|
||||
|
||||
## Compose documentation
|
||||
|
||||
- [Installing Compose](install.md)
|
||||
- [User guide](index.md)
|
||||
- [Command line reference](cli.md)
|
||||
- [Yaml file reference](yml.md)
|
||||
- [Compose command line completion](completion.md)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
jekyll:
|
||||
build: .
|
||||
ports:
|
||||
- "4000:4000"
|
||||
volumes:
|
||||
- .:/code
|
||||
environment:
|
||||
- LANG=en_US.UTF-8
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 130 KiB |
159
docs/index.md
159
docs/index.md
@@ -1,23 +1,38 @@
|
||||
---
|
||||
layout: default
|
||||
title: Fig | Fast, isolated development environments using Docker
|
||||
---
|
||||
page_title: Compose: Multi-container orchestration for Docker
|
||||
page_description: Introduction and Overview of Compose
|
||||
page_keywords: documentation, docs, docker, compose, orchestration, containers
|
||||
|
||||
<strong class="strapline">Fast, isolated development environments using Docker.</strong>
|
||||
|
||||
Define your app's environment with Docker so it can be reproduced anywhere:
|
||||
# Docker Compose
|
||||
|
||||
FROM python:2.7
|
||||
ADD . /code
|
||||
WORKDIR /code
|
||||
RUN pip install -r requirements.txt
|
||||
Compose is a tool for defining and running complex applications with Docker.
|
||||
With Compose, you define a multi-container application in a single file, then
|
||||
spin your application up in a single command which does everything that needs to
|
||||
be done to get it running.
|
||||
|
||||
Define the services that make up your app so they can be run together in an isolated environment:
|
||||
Compose is great for development environments, staging servers, and CI. We don't
|
||||
recommend that you use it in production yet.
|
||||
|
||||
Using Compose is basically a three-step process.
|
||||
|
||||
First, you define your app's environment with a `Dockerfile` so it can be
|
||||
reproduced anywhere:
|
||||
|
||||
```Dockerfile
|
||||
FROM python:2.7
|
||||
WORKDIR /code
|
||||
ADD requirements.txt /code/
|
||||
RUN pip install -r requirements.txt
|
||||
ADD . /code
|
||||
CMD python app.py
|
||||
```
|
||||
|
||||
Next, you define the services that make up your app in `docker-compose.yml` so
|
||||
they can be run together in an isolated environment:
|
||||
|
||||
```yaml
|
||||
web:
|
||||
build: .
|
||||
command: python app.py
|
||||
links:
|
||||
- db
|
||||
ports:
|
||||
@@ -26,33 +41,41 @@ db:
|
||||
image: postgres
|
||||
```
|
||||
|
||||
(No more installing Postgres on your laptop!)
|
||||
Lastly, run `docker-compose up` and Compose will start and run your entire app.
|
||||
|
||||
Then type `fig up`, and Fig will start and run your entire app:
|
||||
Compose has commands for managing the whole lifecycle of your application:
|
||||
|
||||

|
||||
* Start, stop and rebuild services
|
||||
* View the status of running services
|
||||
* Stream the log output of running services
|
||||
* Run a one-off command on a service
|
||||
|
||||
There are commands to:
|
||||
## Compose documentation
|
||||
|
||||
- start, stop and rebuild services
|
||||
- view the status of running services
|
||||
- tail running services' log output
|
||||
- run a one-off command on a service
|
||||
- [Installing Compose](install.md)
|
||||
- [Command line reference](cli.md)
|
||||
- [Yaml file reference](yml.md)
|
||||
- [Compose environment variables](env.md)
|
||||
- [Compose command line completion](completion.md)
|
||||
|
||||
## Quick start
|
||||
|
||||
Quick start
|
||||
-----------
|
||||
Let's get started with a walkthrough of getting a simple Python web app running
|
||||
on Compose. It assumes a little knowledge of Python, but the concepts
|
||||
demonstrated here should be understandable even if you're not familiar with
|
||||
Python.
|
||||
|
||||
Let's get a basic Python web app running on Fig. It assumes a little knowledge of Python, but the concepts should be clear if you're not familiar with it.
|
||||
### Installation and set-up
|
||||
|
||||
First, [install Docker and Fig](install.html).
|
||||
First, [install Docker and Compose](install.md).
|
||||
|
||||
You'll want to make a directory for the project:
|
||||
Next, you'll want to make a directory for the project:
|
||||
|
||||
$ mkdir figtest
|
||||
$ cd figtest
|
||||
$ mkdir composetest
|
||||
$ cd composetest
|
||||
|
||||
Inside this directory, create `app.py`, a simple web app that uses the Flask framework and increments a value in Redis:
|
||||
Inside this directory, create `app.py`, a simple web app that uses the Flask
|
||||
framework and increments a value in Redis:
|
||||
|
||||
```python
|
||||
from flask import Flask
|
||||
@@ -70,21 +93,32 @@ if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", debug=True)
|
||||
```
|
||||
|
||||
We define our Python dependencies in a file called `requirements.txt`:
|
||||
Next, define the Python dependencies in a file called `requirements.txt`:
|
||||
|
||||
flask
|
||||
redis
|
||||
|
||||
Next, we want to create a Docker image containing all of our app's dependencies. We specify how to build one using a file called `Dockerfile`:
|
||||
### Create a Docker image
|
||||
|
||||
Now, create a Docker image containing all of your app's dependencies. You
|
||||
specify how to build the image using a file called
|
||||
[`Dockerfile`](http://docs.docker.com/reference/builder/):
|
||||
|
||||
FROM python:2.7
|
||||
ADD . /code
|
||||
WORKDIR /code
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
This tells Docker to install Python, our code and our Python dependencies inside a Docker image. For more information on how to write Dockerfiles, see the [Docker user guide](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile) and the [Dockerfile reference](http://docs.docker.com/reference/builder/).
|
||||
This tells Docker to include Python, your code, and your Python dependencies in
|
||||
a Docker image. For more information on how to write Dockerfiles, see the
|
||||
[Docker user
|
||||
guide](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile)
|
||||
and the
|
||||
[Dockerfile reference](http://docs.docker.com/reference/builder/).
|
||||
|
||||
We then define a set of services using `fig.yml`:
|
||||
### Define services
|
||||
|
||||
Next, define a set of services using `docker-compose.yml`:
|
||||
|
||||
web:
|
||||
build: .
|
||||
@@ -100,41 +134,60 @@ We then define a set of services using `fig.yml`:
|
||||
|
||||
This defines two services:
|
||||
|
||||
- `web`, which is built from `Dockerfile` in the current directory. It also says to run the command `python app.py` inside the image, forward the exposed port 5000 on the container to port 5000 on the host machine, connect up the Redis service, and mount the current directory inside the container so we can work on code without having to rebuild the image.
|
||||
- `redis`, which uses the public image [redis](https://registry.hub.docker.com/_/redis/).
|
||||
- `web`, which is built from the `Dockerfile` in the current directory. It also
|
||||
says to run the command `python app.py` inside the image, forward the exposed
|
||||
port 5000 on the container to port 5000 on the host machine, connect up the
|
||||
Redis service, and mount the current directory inside the container so we can
|
||||
work on code without having to rebuild the image.
|
||||
- `redis`, which uses the public image
|
||||
[redis](https://registry.hub.docker.com/_/redis/), which gets pulled from the
|
||||
Docker Hub registry.
|
||||
|
||||
Now if we run `fig up`, it'll pull a Redis image, build an image for our own code, and start everything up:
|
||||
### Build and run your app with Compose
|
||||
|
||||
$ fig up
|
||||
Now, when you run `docker-compose up`, Compose will pull a Redis image, build an
|
||||
image for your code, and start everything up:
|
||||
|
||||
$ docker-compose up
|
||||
Pulling image redis...
|
||||
Building web...
|
||||
Starting figtest_redis_1...
|
||||
Starting figtest_web_1...
|
||||
Starting composetest_redis_1...
|
||||
Starting composetest_web_1...
|
||||
redis_1 | [8] 02 Jan 18:43:35.576 # Server started, Redis version 2.8.3
|
||||
web_1 | * Running on http://0.0.0.0:5000/
|
||||
|
||||
The web app should now be listening on port 5000 on your docker daemon (if you're using boot2docker, `boot2docker ip` will tell you its address).
|
||||
The web app should now be listening on port 5000 on your Docker daemon host (if
|
||||
you're using Boot2docker, `boot2docker ip` will tell you its address).
|
||||
|
||||
If you want to run your services in the background, you can pass the `-d` flag to `fig up` and use `fig ps` to see what is currently running:
|
||||
If you want to run your services in the background, you can pass the `-d` flag
|
||||
(for daemon mode) to `docker-compose up` and use `docker-compose ps` to see what
|
||||
is currently running:
|
||||
|
||||
$ fig up -d
|
||||
Starting figtest_redis_1...
|
||||
Starting figtest_web_1...
|
||||
$ fig ps
|
||||
Name Command State Ports
|
||||
$ docker-compose up -d
|
||||
Starting composetest_redis_1...
|
||||
Starting composetest_web_1...
|
||||
$ docker-compose ps
|
||||
Name Command State Ports
|
||||
-------------------------------------------------------------------
|
||||
figtest_redis_1 /usr/local/bin/run Up
|
||||
figtest_web_1 /bin/sh -c python app.py Up 5000->5000/tcp
|
||||
composetest_redis_1 /usr/local/bin/run Up
|
||||
composetest_web_1 /bin/sh -c python app.py Up 5000->5000/tcp
|
||||
|
||||
`fig run` allows you to run one-off commands for your services. For example, to see what environment variables are available to the `web` service:
|
||||
The `docker-compose run` command allows you to run one-off commands for your
|
||||
services. For example, to see what environment variables are available to the
|
||||
`web` service:
|
||||
|
||||
$ fig run web env
|
||||
$ docker-compose run web env
|
||||
|
||||
See `docker-compose --help` to see other available commands.
|
||||
|
||||
See `fig --help` other commands that are available.
|
||||
If you started Compose with `docker-compose up -d`, you'll probably want to stop
|
||||
your services once you've finished with them:
|
||||
|
||||
If you started Fig with `fig up -d`, you'll probably want to stop your services once you've finished with them:
|
||||
$ docker-compose stop
|
||||
|
||||
$ fig stop
|
||||
At this point, you have seen the basics of how Compose works.
|
||||
|
||||
That's more-or-less how Fig works. See the reference section below for full details on the commands, configuration file and environment variables. If you have any thoughts or suggestions, [open an issue on GitHub](https://github.com/docker/fig).
|
||||
- Next, try the quick start guide for [Django](django.md),
|
||||
[Rails](rails.md), or [Wordpress](wordpress.md).
|
||||
- See the reference guides for complete details on the [commands](cli.md), the
|
||||
[configuration file](yml.md) and [environment variables](env.md).
|
||||
|
||||
@@ -1,27 +1,43 @@
|
||||
---
|
||||
layout: default
|
||||
title: Installing Fig
|
||||
---
|
||||
page_title: Installing Compose
|
||||
page_description: How to intall Docker Compose
|
||||
page_keywords: compose, orchestration, install, installation, docker, documentation
|
||||
|
||||
Installing Fig
|
||||
==============
|
||||
|
||||
First, install Docker version 1.3 or greater.
|
||||
## Installing Compose
|
||||
|
||||
If you're on OS X, you can use the [OS X installer](https://docs.docker.com/installation/mac/) to install both Docker and boot2docker. Once boot2docker is running, set the environment variables that'll configure Docker and Fig to talk to it:
|
||||
To install Compose, you'll need to install Docker first. You'll then install
|
||||
Compose with a `curl` command.
|
||||
|
||||
$(boot2docker shellinit)
|
||||
### Install Docker
|
||||
|
||||
To persist the environment variables across shell sessions, you can add that line to your `~/.bashrc` file.
|
||||
First, install Docker version 1.3 or greater:
|
||||
|
||||
There are also guides for [Ubuntu](https://docs.docker.com/installation/ubuntulinux/) and [other platforms](https://docs.docker.com/installation/) in Docker’s documentation.
|
||||
- [Instructions for Mac OS X](http://docs.docker.com/installation/mac/)
|
||||
- [Instructions for Ubuntu](http://docs.docker.com/installation/ubuntulinux/)
|
||||
- [Instructions for other systems](http://docs.docker.com/installation/)
|
||||
|
||||
Next, install Fig:
|
||||
### Install Compose
|
||||
|
||||
curl -L https://github.com/docker/fig/releases/download/1.0.0/fig-`uname -s`-`uname -m` > /usr/local/bin/fig; chmod +x /usr/local/bin/fig
|
||||
To install Compose, run the following commands:
|
||||
|
||||
Releases are available for OS X and 64-bit Linux. Fig is also available as a Python package if you're on another platform (or if you prefer that sort of thing):
|
||||
curl -L https://github.com/docker/compose/releases/download/1.2.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
|
||||
$ sudo pip install -U fig
|
||||
Optionally, you can also install [command completion](completion.md) for the
|
||||
bash shell.
|
||||
|
||||
That should be all you need! Run `fig --version` to see if it worked.
|
||||
Compose is available for OS X and 64-bit Linux. If you're on another platform,
|
||||
Compose can also be installed as a Python package:
|
||||
|
||||
$ sudo pip install -U docker-compose
|
||||
|
||||
No further steps are required; Compose should now be successfully installed.
|
||||
You can test the installation by running `docker-compose --version`.
|
||||
|
||||
## Compose documentation
|
||||
|
||||
- [User guide](index.md)
|
||||
- [Command line reference](cli.md)
|
||||
- [Yaml file reference](yml.md)
|
||||
- [Compose environment variables](env.md)
|
||||
- [Compose command line completion](completion.md)
|
||||
|
||||
10
docs/mkdocs.yml
Normal file
10
docs/mkdocs.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
- ['compose/index.md', 'User Guide', 'Docker Compose' ]
|
||||
- ['compose/install.md', 'Installation', 'Docker Compose']
|
||||
- ['compose/cli.md', 'Reference', 'Compose command line']
|
||||
- ['compose/yml.md', 'Reference', 'Compose yml']
|
||||
- ['compose/env.md', 'Reference', 'Compose ENV variables']
|
||||
- ['compose/completion.md', 'Reference', 'Compose commandline completion']
|
||||
- ['compose/django.md', 'Examples', 'Getting started with Compose and Django']
|
||||
- ['compose/rails.md', 'Examples', 'Getting started with Compose and Rails']
|
||||
- ['compose/wordpress.md', 'Examples', 'Getting started with Compose and Wordpress']
|
||||
@@ -1,16 +1,22 @@
|
||||
---
|
||||
layout: default
|
||||
title: Getting started with Fig and Rails
|
||||
---
|
||||
page_title: Quickstart Guide: Compose and Rails
|
||||
page_description: Getting started with Docker Compose and Rails
|
||||
page_keywords: documentation, docs, docker, compose, orchestration, containers,
|
||||
rails
|
||||
|
||||
Getting started with Fig and Rails
|
||||
==================================
|
||||
|
||||
We're going to use Fig to set up and run a Rails/PostgreSQL app. Before starting, you'll need to have [Fig installed](install.html).
|
||||
## Getting started with Compose and Rails
|
||||
|
||||
Let's set up the three files that'll get us started. First, our app is going to be running inside a Docker container which contains all of its dependencies. We can define what goes inside that Docker container using a file called `Dockerfile`. It'll contain this to start with:
|
||||
This Quickstart guide will show you how to use Compose to set up and run a Rails/PostgreSQL app. Before starting, you'll need to have [Compose installed](install.md).
|
||||
|
||||
FROM ruby
|
||||
### Define the project
|
||||
|
||||
Start by setting up the three files you'll need to build the app. First, since
|
||||
your app is going to run inside a Docker container containing all of its
|
||||
dependencies, you'll need to define exactly what needs to be included in the
|
||||
container. This is done using a file called `Dockerfile`. To begin with, the
|
||||
Dockerfile consists of:
|
||||
|
||||
FROM ruby:2.2.0
|
||||
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
|
||||
RUN mkdir /myapp
|
||||
WORKDIR /myapp
|
||||
@@ -18,14 +24,14 @@ Let's set up the three files that'll get us started. First, our app is going to
|
||||
RUN bundle install
|
||||
ADD . /myapp
|
||||
|
||||
That'll put our application code inside an image with Ruby, Bundler and all our dependencies. For more information on how to write Dockerfiles, see the [Docker user guide](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile) and the [Dockerfile reference](http://docs.docker.com/reference/builder/).
|
||||
That'll put your application code inside an image that will build a container with Ruby, Bundler and all your dependencies inside it. For more information on how to write Dockerfiles, see the [Docker user guide](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile) and the [Dockerfile reference](http://docs.docker.com/reference/builder/).
|
||||
|
||||
Next, we have a bootstrap `Gemfile` which just loads Rails. It'll be overwritten in a moment by `rails new`.
|
||||
Next, create a bootstrap `Gemfile` which just loads Rails. It'll be overwritten in a moment by `rails new`.
|
||||
|
||||
source 'https://rubygems.org'
|
||||
gem 'rails', '4.0.2'
|
||||
gem 'rails', '4.2.0'
|
||||
|
||||
Finally, `fig.yml` is where the magic happens. It describes what services our app comprises (a database and a web app), how to get each one's Docker image (the database just runs on a pre-made PostgreSQL image, and the web app is built from the current directory), and the configuration we need to link them together and expose the web app's port.
|
||||
Finally, `docker-compose.yml` is where the magic happens. This file describes the services that comprise your app (a database and a web app), how to get each one's Docker image (the database just runs on a pre-made PostgreSQL image, and the web app is built from the current directory), and the configuration needed to link them together and expose the web app's port.
|
||||
|
||||
db:
|
||||
image: postgres
|
||||
@@ -33,7 +39,7 @@ Finally, `fig.yml` is where the magic happens. It describes what services our ap
|
||||
- "5432"
|
||||
web:
|
||||
build: .
|
||||
command: bundle exec rackup -p 3000
|
||||
command: bundle exec rails s -p 3000 -b '0.0.0.0'
|
||||
volumes:
|
||||
- .:/myapp
|
||||
ports:
|
||||
@@ -41,30 +47,44 @@ Finally, `fig.yml` is where the magic happens. It describes what services our ap
|
||||
links:
|
||||
- db
|
||||
|
||||
With those files in place, we can now generate the Rails skeleton app using `fig run`:
|
||||
### Build the project
|
||||
|
||||
$ fig run web rails new . --force --database=postgresql --skip-bundle
|
||||
With those three files in place, you can now generate the Rails skeleton app
|
||||
using `docker-compose run`:
|
||||
|
||||
First, Fig will build the image for the `web` service using the `Dockerfile`. Then it'll run `rails new` inside a new container, using that image. Once it's done, you should have a fresh app generated:
|
||||
$ docker-compose run web rails new . --force --database=postgresql --skip-bundle
|
||||
|
||||
First, Compose will build the image for the `web` service using the
|
||||
`Dockerfile`. Then it'll run `rails new` inside a new container, using that
|
||||
image. Once it's done, you should have generated a fresh app:
|
||||
|
||||
$ ls
|
||||
Dockerfile app fig.yml tmp
|
||||
Dockerfile app docker-compose.yml tmp
|
||||
Gemfile bin lib vendor
|
||||
Gemfile.lock config log
|
||||
README.rdoc config.ru public
|
||||
Rakefile db test
|
||||
|
||||
Uncomment the line in your new `Gemfile` which loads `therubyracer`, so we've got a Javascript runtime:
|
||||
Uncomment the line in your new `Gemfile` which loads `therubyracer`, so you've
|
||||
got a Javascript runtime:
|
||||
|
||||
gem 'therubyracer', platforms: :ruby
|
||||
|
||||
Now that we've got a new `Gemfile`, we need to build the image again. (This, and changes to the Dockerfile itself, should be the only times you'll need to rebuild).
|
||||
Now that you've got a new `Gemfile`, you need to build the image again. (This,
|
||||
and changes to the Dockerfile itself, should be the only times you'll need to
|
||||
rebuild.)
|
||||
|
||||
$ fig build
|
||||
$ docker-compose build
|
||||
|
||||
The app is now bootable, but we're not quite there yet. By default, Rails expects a database to be running on `localhost` - we need to point it at the `db` container instead. We also need to change the database and username to align with the defaults set by the `postgres` image.
|
||||
### Connect the database
|
||||
|
||||
Open up your newly-generated `database.yml`. Replace its contents with the following:
|
||||
The app is now bootable, but you're not quite there yet. By default, Rails
|
||||
expects a database to be running on `localhost` - so you need to point it at the
|
||||
`db` container instead. You also need to change the database and username to
|
||||
align with the defaults set by the `postgres` image.
|
||||
|
||||
Open up your newly-generated `database.yml` file. Replace its contents with the
|
||||
following:
|
||||
|
||||
development: &default
|
||||
adapter: postgresql
|
||||
@@ -79,20 +99,29 @@ Open up your newly-generated `database.yml`. Replace its contents with the follo
|
||||
<<: *default
|
||||
database: myapp_test
|
||||
|
||||
We can now boot the app.
|
||||
You can now boot the app with:
|
||||
|
||||
$ fig up
|
||||
$ docker-compose up
|
||||
|
||||
If all's well, you should see some PostgreSQL output, and then—after a few seconds—the familiar refrain:
|
||||
If all's well, you should see some PostgreSQL output, and then—after a few
|
||||
seconds—the familiar refrain:
|
||||
|
||||
myapp_web_1 | [2014-01-17 17:16:29] INFO WEBrick 1.3.1
|
||||
myapp_web_1 | [2014-01-17 17:16:29] INFO ruby 2.0.0 (2013-11-22) [x86_64-linux-gnu]
|
||||
myapp_web_1 | [2014-01-17 17:16:29] INFO ruby 2.2.0 (2014-12-25) [x86_64-linux-gnu]
|
||||
myapp_web_1 | [2014-01-17 17:16:29] INFO WEBrick::HTTPServer#start: pid=1 port=3000
|
||||
|
||||
Finally, we just need to create the database. In another terminal, run:
|
||||
Finally, you need to create the database. In another terminal, run:
|
||||
|
||||
$ fig run web rake db:create
|
||||
$ docker-compose run web rake db:create
|
||||
|
||||
And we're rolling—your app should now be running on port 3000 on your docker daemon (if you're using boot2docker, `boot2docker ip` will tell you its address).
|
||||
That's it. Your app should now be running on port 3000 on your Docker daemon (if
|
||||
you're using Boot2docker, `boot2docker ip` will tell you its address).
|
||||
|
||||

|
||||
## More Compose documentation
|
||||
|
||||
- [Installing Compose](install.md)
|
||||
- [User guide](index.md)
|
||||
- [Command line reference](cli.md)
|
||||
- [Yaml file reference](yml.md)
|
||||
- [Compose environment variables](env.md)
|
||||
- [Compose command line completion](completion.md)
|
||||
|
||||
@@ -1,25 +1,40 @@
|
||||
---
|
||||
layout: default
|
||||
title: Getting started with Fig and Wordpress
|
||||
---
|
||||
page_title: Quickstart Guide: Compose and Wordpress
|
||||
page_description: Getting started with Docker Compose and Rails
|
||||
page_keywords: documentation, docs, docker, compose, orchestration, containers,
|
||||
wordpress
|
||||
|
||||
Getting started with Fig and Wordpress
|
||||
======================================
|
||||
## Getting started with Compose and Wordpress
|
||||
|
||||
Fig makes it nice and easy to run Wordpress in an isolated environment. [Install Fig](install.html), then download Wordpress into the current directory:
|
||||
You can use Compose to easily run Wordpress in an isolated environment built
|
||||
with Docker containers.
|
||||
|
||||
$ curl http://wordpress.org/wordpress-3.8.1.tar.gz | tar -xvzf -
|
||||
### Define the project
|
||||
|
||||
This will create a directory called `wordpress`, which you can rename to the name of your project if you wish. Inside that directory, we create `Dockerfile`, a file that defines what environment your app is going to run in:
|
||||
First, [Install Compose](install.md) and then download Wordpress into the
|
||||
current directory:
|
||||
|
||||
$ curl https://wordpress.org/latest.tar.gz | tar -xvzf -
|
||||
|
||||
This will create a directory called `wordpress`. If you wish, you can rename it
|
||||
to the name of your project.
|
||||
|
||||
Next, inside that directory, create a `Dockerfile`, a file that defines what
|
||||
environment your app is going to run in. For more information on how to write
|
||||
Dockerfiles, see the
|
||||
[Docker user guide](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile) and the
|
||||
[Dockerfile reference](http://docs.docker.com/reference/builder/). In this case,
|
||||
your Dockerfile should be:
|
||||
|
||||
```
|
||||
FROM orchardup/php5
|
||||
ADD . /code
|
||||
```
|
||||
|
||||
This instructs Docker on how to build an image that contains PHP and Wordpress. For more information on how to write Dockerfiles, see the [Docker user guide](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile) and the [Dockerfile reference](http://docs.docker.com/reference/builder/).
|
||||
This tells Docker how to build an image defining a container that contains PHP
|
||||
and Wordpress.
|
||||
|
||||
Next up, `fig.yml` starts our web service and a separate MySQL instance:
|
||||
Next you'll create a `docker-compose.yml` file that will start your web service
|
||||
and a separate MySQL instance:
|
||||
|
||||
```
|
||||
web:
|
||||
@@ -37,7 +52,9 @@ db:
|
||||
MYSQL_DATABASE: wordpress
|
||||
```
|
||||
|
||||
Two supporting files are needed to get this working - first up, `wp-config.php` is the standard Wordpress config file with a single change to make it read the MySQL host and port from the environment variables passed in by Fig:
|
||||
Two supporting files are needed to get this working - first, `wp-config.php` is
|
||||
the standard Wordpress config file with a single change to point the database
|
||||
configuration at the `db` container:
|
||||
|
||||
```
|
||||
<?php
|
||||
@@ -67,7 +84,7 @@ if ( !defined('ABSPATH') )
|
||||
require_once(ABSPATH . 'wp-settings.php');
|
||||
```
|
||||
|
||||
Finally, `router.php` tells PHP's built-in web server how to run Wordpress:
|
||||
Second, `router.php` tells PHP's built-in web server how to run Wordpress:
|
||||
|
||||
```
|
||||
<?php
|
||||
@@ -87,5 +104,19 @@ if(file_exists($root.$path))
|
||||
}
|
||||
}else include_once 'index.php';
|
||||
```
|
||||
### Build the project
|
||||
|
||||
With those four files in place, run `fig up` inside your Wordpress directory and it'll pull and build the images we need, and then start the web and database containers. You'll then be able to visit Wordpress at port 8000 on your docker daemon (if you're using boot2docker, `boot2docker ip` will tell you its address).
|
||||
With those four files in place, run `docker-compose up` inside your Wordpress
|
||||
directory and it'll pull and build the needed images, and then start the web and
|
||||
database containers. You'll then be able to visit Wordpress at port 8000 on your
|
||||
Docker daemon (if you're using Boot2docker, `boot2docker ip` will tell you its
|
||||
address).
|
||||
|
||||
## More Compose documentation
|
||||
|
||||
- [Installing Compose](install.md)
|
||||
- [User guide](index.md)
|
||||
- [Command line reference](cli.md)
|
||||
- [Yaml file reference](yml.md)
|
||||
- [Compose environment variables](env.md)
|
||||
- [Compose command line completion](completion.md)
|
||||
|
||||
209
docs/yml.md
209
docs/yml.md
@@ -1,18 +1,25 @@
|
||||
---
|
||||
layout: default
|
||||
title: fig.yml reference
|
||||
title: docker-compose.yml reference
|
||||
page_title: docker-compose.yml reference
|
||||
page_description: docker-compose.yml reference
|
||||
page_keywords: fig, composition, compose, docker
|
||||
---
|
||||
|
||||
fig.yml reference
|
||||
=================
|
||||
# docker-compose.yml reference
|
||||
|
||||
Each service defined in `fig.yml` must specify exactly one of `image` or `build`. Other keys are optional, and are analogous to their `docker run` command-line counterparts.
|
||||
Each service defined in `docker-compose.yml` must specify exactly one of
|
||||
`image` or `build`. Other keys are optional, and are analogous to their
|
||||
`docker run` command-line counterparts.
|
||||
|
||||
As with `docker run`, options specified in the Dockerfile (e.g. `CMD`, `EXPOSE`, `VOLUME`, `ENV`) are respected by default - you don't need to specify them again in `fig.yml`.
|
||||
As with `docker run`, options specified in the Dockerfile (e.g., `CMD`,
|
||||
`EXPOSE`, `VOLUME`, `ENV`) are respected by default - you don't need to
|
||||
specify them again in `docker-compose.yml`.
|
||||
|
||||
###image
|
||||
### image
|
||||
|
||||
Tag or partial image ID. Can be local or remote - Fig will attempt to pull if it doesn't exist locally.
|
||||
Tag or partial image ID. Can be local or remote - Compose will attempt to
|
||||
pull if it doesn't exist locally.
|
||||
|
||||
```
|
||||
image: ubuntu
|
||||
@@ -22,7 +29,11 @@ image: a4bc65fd
|
||||
|
||||
### build
|
||||
|
||||
Path to a directory containing a Dockerfile. Fig will build and tag it with a generated name, and use that image thereafter.
|
||||
Path to a directory containing a Dockerfile. When the value supplied is a
|
||||
relative path, it is interpreted as relative to the location of the yml file
|
||||
itself. This directory is also the build context that is sent to the Docker daemon.
|
||||
|
||||
Compose will build and tag it with a generated name, and use that image thereafter.
|
||||
|
||||
```
|
||||
build: /path/to/build/dir
|
||||
@@ -39,7 +50,9 @@ command: bundle exec thin -p 3000
|
||||
<a name="links"></a>
|
||||
### links
|
||||
|
||||
Link to containers in another service. Either specify both the service name and the link alias (`SERVICE:ALIAS`), or just the service name (which will also be used for the alias).
|
||||
Link to containers in another service. Either specify both the service name and
|
||||
the link alias (`SERVICE:ALIAS`), or just the service name (which will also be
|
||||
used for the alias).
|
||||
|
||||
```
|
||||
links:
|
||||
@@ -48,7 +61,8 @@ links:
|
||||
- redis
|
||||
```
|
||||
|
||||
An entry with the alias' name will be created in `/etc/hosts` inside containers for this service, e.g:
|
||||
An entry with the alias' name will be created in `/etc/hosts` inside containers
|
||||
for this service, e.g:
|
||||
|
||||
```
|
||||
172.17.2.186 db
|
||||
@@ -56,13 +70,32 @@ An entry with the alias' name will be created in `/etc/hosts` inside containers
|
||||
172.17.2.187 redis
|
||||
```
|
||||
|
||||
Environment variables will also be created - see the [environment variable reference](env.html) for details.
|
||||
Environment variables will also be created - see the [environment variable
|
||||
reference](env.md) for details.
|
||||
|
||||
### external_links
|
||||
|
||||
Link to containers started outside this `docker-compose.yml` or even outside
|
||||
of Compose, especially for containers that provide shared or common services.
|
||||
`external_links` follow semantics similar to `links` when specifying both the
|
||||
container name and the link alias (`CONTAINER:ALIAS`).
|
||||
|
||||
```
|
||||
external_links:
|
||||
- redis_1
|
||||
- project_db_1:mysql
|
||||
- project_db_1:postgresql
|
||||
```
|
||||
|
||||
### ports
|
||||
|
||||
Expose ports. Either specify both ports (`HOST:CONTAINER`), or just the container port (a random host port will be chosen).
|
||||
Expose ports. Either specify both ports (`HOST:CONTAINER`), or just the container
|
||||
port (a random host port will be chosen).
|
||||
|
||||
**Note:** When mapping ports in the `HOST:CONTAINER` format, you may experience erroneous results when using a container port lower than 60, because YAML will parse numbers in the format `xx:yy` as sexagesimal (base 60). For this reason, we recommend always explicitly specifying your port mappings as strings.
|
||||
> **Note:** When mapping ports in the `HOST:CONTAINER` format, you may experience
|
||||
> erroneous results when using a container port lower than 60, because YAML will
|
||||
> parse numbers in the format `xx:yy` as sexagesimal (base 60). For this reason,
|
||||
> we recommend always explicitly specifying your port mappings as strings.
|
||||
|
||||
```
|
||||
ports:
|
||||
@@ -74,7 +107,8 @@ ports:
|
||||
|
||||
### expose
|
||||
|
||||
Expose ports without publishing them to the host machine - they'll only be accessible to linked services. Only the internal port can be specified.
|
||||
Expose ports without publishing them to the host machine - they'll only be
|
||||
accessible to linked services. Only the internal port can be specified.
|
||||
|
||||
```
|
||||
expose:
|
||||
@@ -108,7 +142,8 @@ volumes_from:
|
||||
|
||||
Add environment variables. You can use either an array or a dictionary.
|
||||
|
||||
Environment variables with only a key are resolved to their values on the machine Fig is running on, which can be helpful for secret or host-specific values.
|
||||
Environment variables with only a key are resolved to their values on the
|
||||
machine Compose is running on, which can be helpful for secret or host-specific values.
|
||||
|
||||
```
|
||||
environment:
|
||||
@@ -120,6 +155,105 @@ environment:
|
||||
- SESSION_SECRET
|
||||
```
|
||||
|
||||
### env_file
|
||||
|
||||
Add environment variables from a file. Can be a single value or a list.
|
||||
|
||||
If you have specified a Compose file with `docker-compose -f FILE`, paths in
|
||||
`env_file` are relative to the directory that file is in.
|
||||
|
||||
Environment variables specified in `environment` override these values.
|
||||
|
||||
```
|
||||
env_file: .env
|
||||
|
||||
env_file:
|
||||
- ./common.env
|
||||
- ./apps/web.env
|
||||
- /opt/secrets.env
|
||||
```
|
||||
|
||||
```
|
||||
RACK_ENV: development
|
||||
```
|
||||
|
||||
### extends
|
||||
|
||||
Extend another service, in the current file or another, optionally overriding
|
||||
configuration.
|
||||
|
||||
Here's a simple example. Suppose we have 2 files - **common.yml** and
|
||||
**development.yml**. We can use `extends` to define a service in
|
||||
**development.yml** which uses configuration defined in **common.yml**:
|
||||
|
||||
**common.yml**
|
||||
|
||||
```
|
||||
webapp:
|
||||
build: ./webapp
|
||||
environment:
|
||||
- DEBUG=false
|
||||
- SEND_EMAILS=false
|
||||
```
|
||||
|
||||
**development.yml**
|
||||
|
||||
```
|
||||
web:
|
||||
extends:
|
||||
file: common.yml
|
||||
service: webapp
|
||||
ports:
|
||||
- "8000:8000"
|
||||
links:
|
||||
- db
|
||||
environment:
|
||||
- DEBUG=true
|
||||
db:
|
||||
image: postgres
|
||||
```
|
||||
|
||||
Here, the `web` service in **development.yml** inherits the configuration of
|
||||
the `webapp` service in **common.yml** - the `build` and `environment` keys -
|
||||
and adds `ports` and `links` configuration. It overrides one of the defined
|
||||
environment variables (DEBUG) with a new value, and the other one
|
||||
(SEND_EMAILS) is left untouched. It's exactly as if you defined `web` like
|
||||
this:
|
||||
|
||||
```yaml
|
||||
web:
|
||||
build: ./webapp
|
||||
ports:
|
||||
- "8000:8000"
|
||||
links:
|
||||
- db
|
||||
environment:
|
||||
- DEBUG=true
|
||||
- SEND_EMAILS=false
|
||||
```
|
||||
|
||||
The `extends` option is great for sharing configuration between different
|
||||
apps, or for configuring the same app differently for different environments.
|
||||
You could write a new file for a staging environment, **staging.yml**, which
|
||||
binds to a different port and doesn't turn on debugging:
|
||||
|
||||
```
|
||||
web:
|
||||
extends:
|
||||
file: common.yml
|
||||
service: webapp
|
||||
ports:
|
||||
- "80:8000"
|
||||
links:
|
||||
- db
|
||||
db:
|
||||
image: postgres
|
||||
```
|
||||
|
||||
> **Note:** When you extend a service, `links` and `volumes_from`
|
||||
> configuration options are **not** inherited - you will have to define
|
||||
> those manually each time you extend it.
|
||||
|
||||
### net
|
||||
|
||||
Networking mode. Use the same values as the docker client `--net` parameter.
|
||||
@@ -142,11 +276,39 @@ dns:
|
||||
- 9.9.9.9
|
||||
```
|
||||
|
||||
### working\_dir, entrypoint, user, hostname, domainname, mem\_limit, privileged
|
||||
### cap_add, cap_drop
|
||||
|
||||
Each of these is a single value, analogous to its [docker run](https://docs.docker.com/reference/run/) counterpart.
|
||||
Add or drop container capabilities.
|
||||
See `man 7 capabilities` for a full list.
|
||||
|
||||
```
|
||||
cap_add:
|
||||
- ALL
|
||||
|
||||
cap_drop:
|
||||
- NET_ADMIN
|
||||
- SYS_ADMIN
|
||||
```
|
||||
|
||||
### dns_search
|
||||
|
||||
Custom DNS search domains. Can be a single value or a list.
|
||||
|
||||
```
|
||||
dns_search: example.com
|
||||
dns_search:
|
||||
- dc1.example.com
|
||||
- dc2.example.com
|
||||
```
|
||||
|
||||
### working\_dir, entrypoint, user, hostname, domainname, mem\_limit, privileged, restart, stdin\_open, tty, cpu\_shares
|
||||
|
||||
Each of these is a single value, analogous to its
|
||||
[docker run](https://docs.docker.com/reference/run/) counterpart.
|
||||
|
||||
```
|
||||
cpu_shares: 73
|
||||
|
||||
working_dir: /code
|
||||
entrypoint: /code/entrypoint.sh
|
||||
user: postgresql
|
||||
@@ -156,4 +318,17 @@ domainname: foo.com
|
||||
|
||||
mem_limit: 1000000000
|
||||
privileged: true
|
||||
|
||||
restart: always
|
||||
|
||||
stdin_open: true
|
||||
tty: true
|
||||
```
|
||||
|
||||
## Compose documentation
|
||||
|
||||
- [Installing Compose](install.md)
|
||||
- [User guide](index.md)
|
||||
- [Command line reference](cli.md)
|
||||
- [Compose environment variables](env.md)
|
||||
- [Compose command line completion](completion.md)
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
# dockerpty.
|
||||
#
|
||||
# Copyright 2014 Chris Corbyn <chris@w3style.co.uk>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from .pty import PseudoTerminal
|
||||
|
||||
|
||||
def start(client, container):
|
||||
"""
|
||||
Present the PTY of the container inside the current process.
|
||||
|
||||
This is just a wrapper for PseudoTerminal(client, container).start()
|
||||
"""
|
||||
|
||||
PseudoTerminal(client, container).start()
|
||||
@@ -1,294 +0,0 @@
|
||||
# dockerpty: io.py
|
||||
#
|
||||
# Copyright 2014 Chris Corbyn <chris@w3style.co.uk>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import fcntl
|
||||
import errno
|
||||
import struct
|
||||
import select as builtin_select
|
||||
|
||||
|
||||
def set_blocking(fd, blocking=True):
|
||||
"""
|
||||
Set the given file-descriptor blocking or non-blocking.
|
||||
|
||||
Returns the original blocking status.
|
||||
"""
|
||||
|
||||
old_flag = fcntl.fcntl(fd, fcntl.F_GETFL)
|
||||
|
||||
if blocking:
|
||||
new_flag = old_flag &~ os.O_NONBLOCK
|
||||
else:
|
||||
new_flag = old_flag | os.O_NONBLOCK
|
||||
|
||||
fcntl.fcntl(fd, fcntl.F_SETFL, new_flag)
|
||||
|
||||
return not bool(old_flag & os.O_NONBLOCK)
|
||||
|
||||
|
||||
def select(read_streams, timeout=0):
|
||||
"""
|
||||
Select the streams from `read_streams` that are ready for reading.
|
||||
|
||||
Uses `select.select()` internally but returns a flat list of streams.
|
||||
"""
|
||||
|
||||
write_streams = []
|
||||
exception_streams = []
|
||||
|
||||
try:
|
||||
return builtin_select.select(
|
||||
read_streams,
|
||||
write_streams,
|
||||
exception_streams,
|
||||
timeout,
|
||||
)[0]
|
||||
except builtin_select.error as e:
|
||||
# POSIX signals interrupt select()
|
||||
if e[0] == errno.EINTR:
|
||||
return []
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
class Stream(object):
|
||||
"""
|
||||
Generic Stream class.
|
||||
|
||||
This is a file-like abstraction on top of os.read() and os.write(), which
|
||||
add consistency to the reading of sockets and files alike.
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
Recoverable IO/OS Errors.
|
||||
"""
|
||||
ERRNO_RECOVERABLE = [
|
||||
errno.EINTR,
|
||||
errno.EDEADLK,
|
||||
errno.EWOULDBLOCK,
|
||||
]
|
||||
|
||||
|
||||
def __init__(self, fd):
|
||||
"""
|
||||
Initialize the Stream for the file descriptor `fd`.
|
||||
|
||||
The `fd` object must have a `fileno()` method.
|
||||
"""
|
||||
self.fd = fd
|
||||
|
||||
|
||||
def fileno(self):
|
||||
"""
|
||||
Return the fileno() of the file descriptor.
|
||||
"""
|
||||
|
||||
return self.fd.fileno()
|
||||
|
||||
|
||||
def set_blocking(self, value):
|
||||
if hasattr(self.fd, 'setblocking'):
|
||||
self.fd.setblocking(value)
|
||||
return True
|
||||
else:
|
||||
return set_blocking(self.fd, value)
|
||||
|
||||
|
||||
def read(self, n=4096):
|
||||
"""
|
||||
Return `n` bytes of data from the Stream, or None at end of stream.
|
||||
"""
|
||||
|
||||
try:
|
||||
if hasattr(self.fd, 'recv'):
|
||||
return self.fd.recv(n)
|
||||
return os.read(self.fd.fileno(), n)
|
||||
except EnvironmentError as e:
|
||||
if e.errno not in Stream.ERRNO_RECOVERABLE:
|
||||
raise e
|
||||
|
||||
|
||||
def write(self, data):
|
||||
"""
|
||||
Write `data` to the Stream.
|
||||
"""
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
while True:
|
||||
try:
|
||||
if hasattr(self.fd, 'send'):
|
||||
self.fd.send(data)
|
||||
return len(data)
|
||||
os.write(self.fd.fileno(), data)
|
||||
return len(data)
|
||||
except EnvironmentError as e:
|
||||
if e.errno not in Stream.ERRNO_RECOVERABLE:
|
||||
raise e
|
||||
|
||||
def __repr__(self):
|
||||
return "{cls}({fd})".format(cls=type(self).__name__, fd=self.fd)
|
||||
|
||||
|
||||
class Demuxer(object):
|
||||
"""
|
||||
Wraps a multiplexed Stream to read in data demultiplexed.
|
||||
|
||||
Docker multiplexes streams together when there is no PTY attached, by
|
||||
sending an 8-byte header, followed by a chunk of data.
|
||||
|
||||
The first 4 bytes of the header denote the stream from which the data came
|
||||
(i.e. 0x01 = stdout, 0x02 = stderr). Only the first byte of these initial 4
|
||||
bytes is used.
|
||||
|
||||
The next 4 bytes indicate the length of the following chunk of data as an
|
||||
integer in big endian format. This much data must be consumed before the
|
||||
next 8-byte header is read.
|
||||
"""
|
||||
|
||||
def __init__(self, stream):
|
||||
"""
|
||||
Initialize a new Demuxer reading from `stream`.
|
||||
"""
|
||||
|
||||
self.stream = stream
|
||||
self.remain = 0
|
||||
|
||||
|
||||
def fileno(self):
|
||||
"""
|
||||
Returns the fileno() of the underlying Stream.
|
||||
|
||||
This is useful for select() to work.
|
||||
"""
|
||||
|
||||
return self.stream.fileno()
|
||||
|
||||
|
||||
def set_blocking(self, value):
|
||||
return self.stream.set_blocking(value)
|
||||
|
||||
|
||||
def read(self, n=4096):
|
||||
"""
|
||||
Read up to `n` bytes of data from the Stream, after demuxing.
|
||||
|
||||
Less than `n` bytes of data may be returned depending on the available
|
||||
payload, but the number of bytes returned will never exceed `n`.
|
||||
|
||||
Because demuxing involves scanning 8-byte headers, the actual amount of
|
||||
data read from the underlying stream may be greater than `n`.
|
||||
"""
|
||||
|
||||
size = self._next_packet_size(n)
|
||||
|
||||
if size <= 0:
|
||||
return
|
||||
else:
|
||||
return self.stream.read(size)
|
||||
|
||||
|
||||
def write(self, data):
|
||||
"""
|
||||
Delegates the the underlying Stream.
|
||||
"""
|
||||
|
||||
return self.stream.write(data)
|
||||
|
||||
|
||||
def _next_packet_size(self, n=0):
|
||||
size = 0
|
||||
|
||||
if self.remain > 0:
|
||||
size = min(n, self.remain)
|
||||
self.remain -= size
|
||||
else:
|
||||
data = self.stream.read(8)
|
||||
if data is None:
|
||||
return 0
|
||||
if len(data) == 8:
|
||||
__, actual = struct.unpack('>BxxxL', data)
|
||||
size = min(n, actual)
|
||||
self.remain = actual - size
|
||||
|
||||
return size
|
||||
|
||||
def __repr__(self):
|
||||
return "{cls}({stream})".format(cls=type(self).__name__,
|
||||
stream=self.stream)
|
||||
|
||||
|
||||
class Pump(object):
|
||||
"""
|
||||
Stream pump class.
|
||||
|
||||
A Pump wraps two Streams, reading from one and and writing its data into
|
||||
the other, much like a pipe but manually managed.
|
||||
|
||||
This abstraction is used to facilitate piping data between the file
|
||||
descriptors associated with the tty and those associated with a container's
|
||||
allocated pty.
|
||||
|
||||
Pumps are selectable based on the 'read' end of the pipe.
|
||||
"""
|
||||
|
||||
def __init__(self, from_stream, to_stream):
|
||||
"""
|
||||
Initialize a Pump with a Stream to read from and another to write to.
|
||||
"""
|
||||
|
||||
self.from_stream = from_stream
|
||||
self.to_stream = to_stream
|
||||
|
||||
|
||||
def fileno(self):
|
||||
"""
|
||||
Returns the `fileno()` of the reader end of the Pump.
|
||||
|
||||
This is useful to allow Pumps to function with `select()`.
|
||||
"""
|
||||
|
||||
return self.from_stream.fileno()
|
||||
|
||||
|
||||
def set_blocking(self, value):
|
||||
return self.from_stream.set_blocking(value)
|
||||
|
||||
|
||||
def flush(self, n=4096):
|
||||
"""
|
||||
Flush `n` bytes of data from the reader Stream to the writer Stream.
|
||||
|
||||
Returns the number of bytes that were actually flushed. A return value
|
||||
of zero is not an error.
|
||||
|
||||
If EOF has been reached, `None` is returned.
|
||||
"""
|
||||
|
||||
try:
|
||||
return self.to_stream.write(self.from_stream.read(n))
|
||||
except OSError as e:
|
||||
if e.errno != errno.EPIPE:
|
||||
raise e
|
||||
|
||||
def __repr__(self):
|
||||
return "{cls}(from={from_stream}, to={to_stream})".format(
|
||||
cls=type(self).__name__,
|
||||
from_stream=self.from_stream,
|
||||
to_stream=self.to_stream)
|
||||
@@ -1,235 +0,0 @@
|
||||
# dockerpty: pty.py
|
||||
#
|
||||
# Copyright 2014 Chris Corbyn <chris@w3style.co.uk>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
import signal
|
||||
from ssl import SSLError
|
||||
|
||||
from . import io
|
||||
from . import tty
|
||||
|
||||
|
||||
class WINCHHandler(object):
|
||||
"""
|
||||
WINCH Signal handler to keep the PTY correctly sized.
|
||||
"""
|
||||
|
||||
def __init__(self, pty):
|
||||
"""
|
||||
Initialize a new WINCH handler for the given PTY.
|
||||
|
||||
Initializing a handler has no immediate side-effects. The `start()`
|
||||
method must be invoked for the signals to be trapped.
|
||||
"""
|
||||
|
||||
self.pty = pty
|
||||
self.original_handler = None
|
||||
|
||||
|
||||
def __enter__(self):
|
||||
"""
|
||||
Invoked on entering a `with` block.
|
||||
"""
|
||||
|
||||
self.start()
|
||||
return self
|
||||
|
||||
|
||||
def __exit__(self, *_):
|
||||
"""
|
||||
Invoked on exiting a `with` block.
|
||||
"""
|
||||
|
||||
self.stop()
|
||||
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Start trapping WINCH signals and resizing the PTY.
|
||||
|
||||
This method saves the previous WINCH handler so it can be restored on
|
||||
`stop()`.
|
||||
"""
|
||||
|
||||
def handle(signum, frame):
|
||||
if signum == signal.SIGWINCH:
|
||||
self.pty.resize()
|
||||
|
||||
self.original_handler = signal.signal(signal.SIGWINCH, handle)
|
||||
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stop trapping WINCH signals and restore the previous WINCH handler.
|
||||
"""
|
||||
|
||||
if self.original_handler is not None:
|
||||
signal.signal(signal.SIGWINCH, self.original_handler)
|
||||
|
||||
|
||||
class PseudoTerminal(object):
|
||||
"""
|
||||
Wraps the pseudo-TTY (PTY) allocated to a docker container.
|
||||
|
||||
The PTY is managed via the current process' TTY until it is closed.
|
||||
|
||||
Example:
|
||||
|
||||
import docker
|
||||
from dockerpty import PseudoTerminal
|
||||
|
||||
client = docker.Client()
|
||||
container = client.create_container(
|
||||
image='busybox:latest',
|
||||
stdin_open=True,
|
||||
tty=True,
|
||||
command='/bin/sh',
|
||||
)
|
||||
|
||||
# hijacks the current tty until the pty is closed
|
||||
PseudoTerminal(client, container).start()
|
||||
|
||||
Care is taken to ensure all file descriptors are restored on exit. For
|
||||
example, you can attach to a running container from within a Python REPL
|
||||
and when the container exits, the user will be returned to the Python REPL
|
||||
without adverse effects.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, client, container):
|
||||
"""
|
||||
Initialize the PTY using the docker.Client instance and container dict.
|
||||
"""
|
||||
|
||||
self.client = client
|
||||
self.container = container
|
||||
self.raw = None
|
||||
|
||||
|
||||
def start(self, **kwargs):
|
||||
"""
|
||||
Present the PTY of the container inside the current process.
|
||||
|
||||
This will take over the current process' TTY until the container's PTY
|
||||
is closed.
|
||||
"""
|
||||
|
||||
pty_stdin, pty_stdout, pty_stderr = self.sockets()
|
||||
|
||||
mappings = [
|
||||
(io.Stream(sys.stdin), pty_stdin),
|
||||
(pty_stdout, io.Stream(sys.stdout)),
|
||||
(pty_stderr, io.Stream(sys.stderr)),
|
||||
]
|
||||
|
||||
pumps = [io.Pump(a, b) for (a, b) in mappings if a and b]
|
||||
|
||||
if not self.container_info()['State']['Running']:
|
||||
self.client.start(self.container, **kwargs)
|
||||
|
||||
flags = [p.set_blocking(False) for p in pumps]
|
||||
|
||||
try:
|
||||
with WINCHHandler(self):
|
||||
self._hijack_tty(pumps)
|
||||
finally:
|
||||
if flags:
|
||||
for (pump, flag) in zip(pumps, flags):
|
||||
io.set_blocking(pump, flag)
|
||||
|
||||
|
||||
def israw(self):
|
||||
"""
|
||||
Returns True if the PTY should operate in raw mode.
|
||||
|
||||
If the container was not started with tty=True, this will return False.
|
||||
"""
|
||||
|
||||
if self.raw is None:
|
||||
info = self.container_info()
|
||||
self.raw = sys.stdout.isatty() and info['Config']['Tty']
|
||||
|
||||
return self.raw
|
||||
|
||||
|
||||
def sockets(self):
|
||||
"""
|
||||
Returns a tuple of sockets connected to the pty (stdin,stdout,stderr).
|
||||
|
||||
If any of the sockets are not attached in the container, `None` is
|
||||
returned in the tuple.
|
||||
"""
|
||||
|
||||
info = self.container_info()
|
||||
|
||||
def attach_socket(key):
|
||||
if info['Config']['Attach{0}'.format(key.capitalize())]:
|
||||
socket = self.client.attach_socket(
|
||||
self.container,
|
||||
{key: 1, 'stream': 1, 'logs': 1},
|
||||
)
|
||||
stream = io.Stream(socket)
|
||||
|
||||
if info['Config']['Tty']:
|
||||
return stream
|
||||
else:
|
||||
return io.Demuxer(stream)
|
||||
else:
|
||||
return None
|
||||
|
||||
return map(attach_socket, ('stdin', 'stdout', 'stderr'))
|
||||
|
||||
|
||||
def resize(self, size=None):
|
||||
"""
|
||||
Resize the container's PTY.
|
||||
|
||||
If `size` is not None, it must be a tuple of (height,width), otherwise
|
||||
it will be determined by the size of the current TTY.
|
||||
"""
|
||||
|
||||
if not self.israw():
|
||||
return
|
||||
|
||||
size = size or tty.size(sys.stdout)
|
||||
|
||||
if size is not None:
|
||||
rows, cols = size
|
||||
try:
|
||||
self.client.resize(self.container, height=rows, width=cols)
|
||||
except IOError: # Container already exited
|
||||
pass
|
||||
|
||||
|
||||
def container_info(self):
|
||||
"""
|
||||
Thin wrapper around client.inspect_container().
|
||||
"""
|
||||
|
||||
return self.client.inspect_container(self.container)
|
||||
|
||||
|
||||
def _hijack_tty(self, pumps):
|
||||
with tty.Terminal(sys.stdin, raw=self.israw()):
|
||||
self.resize()
|
||||
while True:
|
||||
_ready = io.select(pumps, timeout=60)
|
||||
try:
|
||||
if all([p.flush() is None for p in pumps]):
|
||||
break
|
||||
except SSLError as e:
|
||||
if 'The operation did not complete' not in e.strerror:
|
||||
raise e
|
||||
@@ -1,130 +0,0 @@
|
||||
# dockerpty: tty.py
|
||||
#
|
||||
# Copyright 2014 Chris Corbyn <chris@w3style.co.uk>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import termios
|
||||
import tty
|
||||
import fcntl
|
||||
import struct
|
||||
|
||||
|
||||
def size(fd):
|
||||
"""
|
||||
Return a tuple (rows,cols) representing the size of the TTY `fd`.
|
||||
|
||||
The provided file descriptor should be the stdout stream of the TTY.
|
||||
|
||||
If the TTY size cannot be determined, returns None.
|
||||
"""
|
||||
|
||||
if not os.isatty(fd.fileno()):
|
||||
return None
|
||||
|
||||
try:
|
||||
dims = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, 'hhhh'))
|
||||
except:
|
||||
try:
|
||||
dims = (os.environ['LINES'], os.environ['COLUMNS'])
|
||||
except:
|
||||
return None
|
||||
|
||||
return dims
|
||||
|
||||
|
||||
class Terminal(object):
|
||||
"""
|
||||
Terminal provides wrapper functionality to temporarily make the tty raw.
|
||||
|
||||
This is useful when streaming data from a pseudo-terminal into the tty.
|
||||
|
||||
Example:
|
||||
|
||||
with Terminal(sys.stdin, raw=True):
|
||||
do_things_in_raw_mode()
|
||||
"""
|
||||
|
||||
def __init__(self, fd, raw=True):
|
||||
"""
|
||||
Initialize a terminal for the tty with stdin attached to `fd`.
|
||||
|
||||
Initializing the Terminal has no immediate side effects. The `start()`
|
||||
method must be invoked, or `with raw_terminal:` used before the
|
||||
terminal is affected.
|
||||
"""
|
||||
|
||||
self.fd = fd
|
||||
self.raw = raw
|
||||
self.original_attributes = None
|
||||
|
||||
|
||||
def __enter__(self):
|
||||
"""
|
||||
Invoked when a `with` block is first entered.
|
||||
"""
|
||||
|
||||
self.start()
|
||||
return self
|
||||
|
||||
|
||||
def __exit__(self, *_):
|
||||
"""
|
||||
Invoked when a `with` block is finished.
|
||||
"""
|
||||
|
||||
self.stop()
|
||||
|
||||
|
||||
def israw(self):
|
||||
"""
|
||||
Returns True if the TTY should operate in raw mode.
|
||||
"""
|
||||
|
||||
return self.raw
|
||||
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Saves the current terminal attributes and makes the tty raw.
|
||||
|
||||
This method returns None immediately.
|
||||
"""
|
||||
|
||||
if os.isatty(self.fd.fileno()) and self.israw():
|
||||
self.original_attributes = termios.tcgetattr(self.fd)
|
||||
tty.setraw(self.fd)
|
||||
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Restores the terminal attributes back to before setting raw mode.
|
||||
|
||||
If the raw terminal was not started, does nothing.
|
||||
"""
|
||||
|
||||
if self.original_attributes is not None:
|
||||
termios.tcsetattr(
|
||||
self.fd,
|
||||
termios.TCSADRAIN,
|
||||
self.original_attributes,
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return "{cls}({fd}, raw={raw})".format(
|
||||
cls=type(self).__name__,
|
||||
fd=self.fd,
|
||||
raw=self.raw)
|
||||
@@ -1,5 +1,6 @@
|
||||
mock >= 1.0.1
|
||||
nose
|
||||
nose==1.3.4
|
||||
git+https://github.com/pyinstaller/pyinstaller.git@12e40471c77f588ea5be352f7219c873ddaae056#egg=pyinstaller
|
||||
unittest2
|
||||
flake8
|
||||
unittest2==0.8.0
|
||||
flake8==2.3.0
|
||||
pep8==1.6.1
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
PyYAML==3.10
|
||||
docker-py==0.5.3
|
||||
docker-py==1.0.0
|
||||
dockerpty==0.3.2
|
||||
docopt==0.6.1
|
||||
requests==2.2.1
|
||||
six==1.7.3
|
||||
texttable==0.8.1
|
||||
texttable==0.8.2
|
||||
websocket-client==0.11.0
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
pushd docs
|
||||
fig run jekyll jekyll build
|
||||
popd
|
||||
@@ -1,8 +1,12 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
mkdir -p `pwd`/dist
|
||||
chmod 777 `pwd`/dist
|
||||
docker build -t fig .
|
||||
docker run -u user -v `pwd`/dist:/code/dist fig pyinstaller -F bin/fig
|
||||
mv dist/fig dist/fig-Linux-x86_64
|
||||
docker run -u user -v `pwd`/dist:/code/dist fig dist/fig-Linux-x86_64 --version
|
||||
|
||||
TAG="docker-compose"
|
||||
docker build -t "$TAG" .
|
||||
docker run \
|
||||
--rm \
|
||||
--user=user \
|
||||
--volume="$(pwd):/code" \
|
||||
--entrypoint="script/build-linux-inner" \
|
||||
"$TAG"
|
||||
|
||||
10
script/build-linux-inner
Executable file
10
script/build-linux-inner
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
mkdir -p `pwd`/dist
|
||||
chmod 777 `pwd`/dist
|
||||
|
||||
pyinstaller -F bin/docker-compose
|
||||
mv dist/docker-compose dist/docker-compose-Linux-x86_64
|
||||
dist/docker-compose-Linux-x86_64 --version
|
||||
@@ -5,6 +5,6 @@ virtualenv venv
|
||||
venv/bin/pip install -r requirements.txt
|
||||
venv/bin/pip install -r requirements-dev.txt
|
||||
venv/bin/pip install .
|
||||
venv/bin/pyinstaller -F bin/fig
|
||||
mv dist/fig dist/fig-Darwin-x86_64
|
||||
dist/fig-Darwin-x86_64 --version
|
||||
venv/bin/pyinstaller -F bin/docker-compose
|
||||
mv dist/docker-compose dist/docker-compose-Darwin-x86_64
|
||||
dist/docker-compose-Darwin-x86_64 --version
|
||||
|
||||
18
script/ci
Executable file
18
script/ci
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
# This should be run inside a container built from the Dockerfile
|
||||
# at the root of the repo:
|
||||
#
|
||||
# $ TAG="docker-compose:$(git rev-parse --short HEAD)"
|
||||
# $ docker build -t "$TAG" .
|
||||
# $ docker run --rm --volume="/var/run/docker.sock:/var/run/docker.sock" --volume="$(pwd)/.git:/code/.git" -e "TAG=$TAG" --entrypoint="script/ci" "$TAG"
|
||||
|
||||
set -e
|
||||
|
||||
>&2 echo "Validating DCO"
|
||||
script/validate-dco
|
||||
|
||||
export DOCKER_VERSIONS=all
|
||||
. script/test-versions
|
||||
|
||||
>&2 echo "Building Linux binary"
|
||||
su -c script/build-linux-inner user
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/sh
|
||||
find . -type f -name '*.pyc' -delete
|
||||
rm -rf docs/_site build dist fig.egg-info
|
||||
rm -rf docs/_site build dist docker-compose.egg-info
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
script/build-docs
|
||||
|
||||
pushd docs/_site
|
||||
|
||||
export GIT_DIR=.git-gh-pages
|
||||
export GIT_WORK_TREE=.
|
||||
|
||||
if [ ! -d "$GIT_DIR" ]; then
|
||||
git init
|
||||
fi
|
||||
|
||||
if !(git remote | grep origin); then
|
||||
git remote add origin git@github.com:docker/fig.git
|
||||
fi
|
||||
|
||||
git fetch origin
|
||||
git reset --soft origin/gh-pages
|
||||
|
||||
echo ".git-gh-pages" > .gitignore
|
||||
|
||||
git add -A .
|
||||
|
||||
git commit -m "update" || echo "didn't commit"
|
||||
git push origin master:gh-pages
|
||||
|
||||
popd
|
||||
21
script/dev
Executable file
21
script/dev
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
# This is a script for running Compose inside a Docker container. It's handy for
|
||||
# development.
|
||||
#
|
||||
# $ ln -s `pwd`/script/dev /usr/local/bin/docker-compose
|
||||
# $ cd /a/compose/project
|
||||
# $ docker-compose up
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
# Follow symbolic links
|
||||
if [ -h "$0" ]; then
|
||||
DIR=$(readlink "$0")
|
||||
else
|
||||
DIR=$0
|
||||
fi
|
||||
DIR="$(dirname "$DIR")"/..
|
||||
|
||||
docker build -t docker-compose $DIR
|
||||
exec docker run -i -t -v /var/run/docker.sock:/var/run/docker.sock -v `pwd`:`pwd` -w `pwd` docker-compose $@
|
||||
88
script/dind
Executable file
88
script/dind
Executable file
@@ -0,0 +1,88 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# DinD: a wrapper script which allows docker to be run inside a docker container.
|
||||
# Original version by Jerome Petazzoni <jerome@docker.com>
|
||||
# See the blog post: http://blog.docker.com/2013/09/docker-can-now-run-within-docker/
|
||||
#
|
||||
# This script should be executed inside a docker container in privilieged mode
|
||||
# ('docker run --privileged', introduced in docker 0.6).
|
||||
|
||||
# Usage: dind CMD [ARG...]
|
||||
|
||||
# apparmor sucks and Docker needs to know that it's in a container (c) @tianon
|
||||
export container=docker
|
||||
|
||||
# First, make sure that cgroups are mounted correctly.
|
||||
CGROUP=/cgroup
|
||||
|
||||
mkdir -p "$CGROUP"
|
||||
|
||||
if ! mountpoint -q "$CGROUP"; then
|
||||
mount -n -t tmpfs -o uid=0,gid=0,mode=0755 cgroup $CGROUP || {
|
||||
echo >&2 'Could not make a tmpfs mount. Did you use --privileged?'
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
|
||||
if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security; then
|
||||
mount -t securityfs none /sys/kernel/security || {
|
||||
echo >&2 'Could not mount /sys/kernel/security.'
|
||||
echo >&2 'AppArmor detection and -privileged mode might break.'
|
||||
}
|
||||
fi
|
||||
|
||||
# Mount the cgroup hierarchies exactly as they are in the parent system.
|
||||
for SUBSYS in $(cut -d: -f2 /proc/1/cgroup); do
|
||||
mkdir -p "$CGROUP/$SUBSYS"
|
||||
if ! mountpoint -q $CGROUP/$SUBSYS; then
|
||||
mount -n -t cgroup -o "$SUBSYS" cgroup "$CGROUP/$SUBSYS"
|
||||
fi
|
||||
|
||||
# The two following sections address a bug which manifests itself
|
||||
# by a cryptic "lxc-start: no ns_cgroup option specified" when
|
||||
# trying to start containers withina container.
|
||||
# The bug seems to appear when the cgroup hierarchies are not
|
||||
# mounted on the exact same directories in the host, and in the
|
||||
# container.
|
||||
|
||||
# Named, control-less cgroups are mounted with "-o name=foo"
|
||||
# (and appear as such under /proc/<pid>/cgroup) but are usually
|
||||
# mounted on a directory named "foo" (without the "name=" prefix).
|
||||
# Systemd and OpenRC (and possibly others) both create such a
|
||||
# cgroup. To avoid the aforementioned bug, we symlink "foo" to
|
||||
# "name=foo". This shouldn't have any adverse effect.
|
||||
name="${SUBSYS#name=}"
|
||||
if [ "$name" != "$SUBSYS" ]; then
|
||||
ln -s "$SUBSYS" "$CGROUP/$name"
|
||||
fi
|
||||
|
||||
# Likewise, on at least one system, it has been reported that
|
||||
# systemd would mount the CPU and CPU accounting controllers
|
||||
# (respectively "cpu" and "cpuacct") with "-o cpuacct,cpu"
|
||||
# but on a directory called "cpu,cpuacct" (note the inversion
|
||||
# in the order of the groups). This tries to work around it.
|
||||
if [ "$SUBSYS" = 'cpuacct,cpu' ]; then
|
||||
ln -s "$SUBSYS" "$CGROUP/cpu,cpuacct"
|
||||
fi
|
||||
done
|
||||
|
||||
# Note: as I write those lines, the LXC userland tools cannot setup
|
||||
# a "sub-container" properly if the "devices" cgroup is not in its
|
||||
# own hierarchy. Let's detect this and issue a warning.
|
||||
if ! grep -q :devices: /proc/1/cgroup; then
|
||||
echo >&2 'WARNING: the "devices" cgroup should be in its own hierarchy.'
|
||||
fi
|
||||
if ! grep -qw devices /proc/1/cgroup; then
|
||||
echo >&2 'WARNING: it looks like the "devices" cgroup is not mounted.'
|
||||
fi
|
||||
|
||||
# Mount /tmp
|
||||
mount -t tmpfs none /tmp
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
echo >&2 'ERROR: No command specified.'
|
||||
echo >&2 'You probably want to run hack/make.sh, or maybe a shell?'
|
||||
11
script/docs
Executable file
11
script/docs
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
set -ex
|
||||
|
||||
# import the existing docs build cmds from docker/docker
|
||||
DOCSPORT=8000
|
||||
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
|
||||
DOCKER_DOCS_IMAGE="compose-docs$GIT_BRANCH"
|
||||
DOCKER_RUN_DOCS="docker run --rm -it -e NOCACHE"
|
||||
|
||||
docker build -t "$DOCKER_DOCS_IMAGE" -f docs/Dockerfile .
|
||||
$DOCKER_RUN_DOCS -p $DOCSPORT:8000 "$DOCKER_DOCS_IMAGE" mkdocs serve
|
||||
@@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
open file://`pwd`/docs/_site/index.html
|
||||
4
script/shell
Executable file
4
script/shell
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
set -ex
|
||||
docker build -t docker-compose .
|
||||
exec docker run -v /var/run/docker.sock:/var/run/docker.sock -v `pwd`:/code -ti --rm --entrypoint bash docker-compose
|
||||
23
script/test
23
script/test
@@ -1,12 +1,17 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# See CONTRIBUTING.md for usage.
|
||||
|
||||
set -ex
|
||||
|
||||
target="tests"
|
||||
TAG="docker-compose:$(git rev-parse --short HEAD)"
|
||||
|
||||
if [[ -n "$@" ]]; then
|
||||
target="$@"
|
||||
fi
|
||||
|
||||
docker build -t fig .
|
||||
docker run -v /var/run/docker.sock:/var/run/docker.sock fig flake8 --exclude=packages fig
|
||||
docker run -v /var/run/docker.sock:/var/run/docker.sock fig nosetests $target
|
||||
docker build -t "$TAG" .
|
||||
docker run \
|
||||
--rm \
|
||||
--volume="/var/run/docker.sock:/var/run/docker.sock" \
|
||||
--volume="$(pwd):/code" \
|
||||
-e DOCKER_VERSIONS \
|
||||
-e "TAG=$TAG" \
|
||||
--entrypoint="script/test-versions" \
|
||||
"$TAG" \
|
||||
"$@"
|
||||
|
||||
26
script/test-versions
Executable file
26
script/test-versions
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
# This should be run inside a container built from the Dockerfile
|
||||
# at the root of the repo - script/test will do it automatically.
|
||||
|
||||
set -e
|
||||
|
||||
>&2 echo "Running lint checks"
|
||||
flake8 compose
|
||||
|
||||
if [ "$DOCKER_VERSIONS" == "" ]; then
|
||||
DOCKER_VERSIONS="1.5.0"
|
||||
elif [ "$DOCKER_VERSIONS" == "all" ]; then
|
||||
DOCKER_VERSIONS="$ALL_DOCKER_VERSIONS"
|
||||
fi
|
||||
|
||||
for version in $DOCKER_VERSIONS; do
|
||||
>&2 echo "Running tests against Docker $version"
|
||||
docker run \
|
||||
--rm \
|
||||
--privileged \
|
||||
--volume="/var/lib/docker" \
|
||||
-e "DOCKER_VERSION=$version" \
|
||||
--entrypoint="script/dind" \
|
||||
"$TAG" \
|
||||
script/wrapdocker nosetests "$@"
|
||||
done
|
||||
@@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
source "$(dirname "$BASH_SOURCE")/.validate"
|
||||
|
||||
adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }')
|
||||
|
||||
20
script/wrapdocker
Executable file
20
script/wrapdocker
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$DOCKER_VERSION" == "" ]; then
|
||||
DOCKER_VERSION="1.5.0"
|
||||
fi
|
||||
|
||||
ln -fs "/usr/local/bin/docker-$DOCKER_VERSION" "/usr/local/bin/docker"
|
||||
|
||||
# If a pidfile is still around (for example after a container restart),
|
||||
# delete it so that docker can start.
|
||||
rm -rf /var/run/docker.pid
|
||||
docker -d $DOCKER_DAEMON_ARGS &>/var/log/docker.log &
|
||||
|
||||
>&2 echo "Waiting for Docker to start..."
|
||||
while ! docker ps &>/dev/null; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
>&2 echo ">" "$@"
|
||||
exec "$@"
|
||||
17
setup.py
17
setup.py
@@ -27,10 +27,11 @@ def find_version(*file_paths):
|
||||
install_requires = [
|
||||
'docopt >= 0.6.1, < 0.7',
|
||||
'PyYAML >= 3.10, < 4',
|
||||
'requests >= 2.2.1, < 3',
|
||||
'requests >= 2.2.1, < 2.6',
|
||||
'texttable >= 0.8.1, < 0.9',
|
||||
'websocket-client >= 0.11.0, < 0.12',
|
||||
'docker-py >= 0.5, < 0.6',
|
||||
'websocket-client >= 0.11.0, < 1.0',
|
||||
'docker-py >= 1.0.0, < 1.2',
|
||||
'dockerpty >= 0.3.2, < 0.4',
|
||||
'six >= 1.3.0, < 2',
|
||||
]
|
||||
|
||||
@@ -47,10 +48,10 @@ if sys.version_info < (2, 7):
|
||||
|
||||
|
||||
setup(
|
||||
name='fig',
|
||||
version=find_version("fig", "__init__.py"),
|
||||
description='Punctual, lightweight development environments using Docker',
|
||||
url='http://www.fig.sh/',
|
||||
name='docker-compose',
|
||||
version=find_version("compose", "__init__.py"),
|
||||
description='Multi-container orchestration for Docker',
|
||||
url='https://www.docker.com/',
|
||||
author='Docker, Inc.',
|
||||
license='Apache License 2.0',
|
||||
packages=find_packages(exclude=[ 'tests.*', 'tests' ]),
|
||||
@@ -60,6 +61,6 @@ setup(
|
||||
tests_require=tests_require,
|
||||
entry_points="""
|
||||
[console_scripts]
|
||||
fig=fig.cli.main:main
|
||||
docker-compose=compose.cli.main:main
|
||||
""",
|
||||
)
|
||||
|
||||
2
tests/fixtures/build-ctx/Dockerfile
vendored
Normal file
2
tests/fixtures/build-ctx/Dockerfile
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
FROM busybox:latest
|
||||
CMD echo "success"
|
||||
2
tests/fixtures/build-path/docker-compose.yml
vendored
Normal file
2
tests/fixtures/build-path/docker-compose.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
foo:
|
||||
build: ../build-ctx/
|
||||
5
tests/fixtures/commands-composefile/docker-compose.yml
vendored
Normal file
5
tests/fixtures/commands-composefile/docker-compose.yml
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
implicit:
|
||||
image: composetest_test
|
||||
explicit:
|
||||
image: composetest_test
|
||||
command: [ "/bin/true" ]
|
||||
5
tests/fixtures/commands-figfile/fig.yml
vendored
5
tests/fixtures/commands-figfile/fig.yml
vendored
@@ -1,5 +0,0 @@
|
||||
implicit:
|
||||
image: figtest_test
|
||||
explicit:
|
||||
image: figtest_test
|
||||
command: [ "/bin/true" ]
|
||||
3
tests/fixtures/dockerfile-with-volume/Dockerfile
vendored
Normal file
3
tests/fixtures/dockerfile-with-volume/Dockerfile
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM busybox
|
||||
VOLUME /data
|
||||
CMD sleep 3000
|
||||
2
tests/fixtures/dockerfile_with_entrypoint/docker-compose.yml
vendored
Normal file
2
tests/fixtures/dockerfile_with_entrypoint/docker-compose.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
service:
|
||||
build: .
|
||||
@@ -1,2 +0,0 @@
|
||||
service:
|
||||
build: tests/fixtures/dockerfile_with_entrypoint
|
||||
4
tests/fixtures/env-file/docker-compose.yml
vendored
Normal file
4
tests/fixtures/env-file/docker-compose.yml
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
web:
|
||||
image: busybox
|
||||
command: /bin/true
|
||||
env_file: ./test.env
|
||||
1
tests/fixtures/env-file/test.env
vendored
Normal file
1
tests/fixtures/env-file/test.env
vendored
Normal file
@@ -0,0 +1 @@
|
||||
FOO=1
|
||||
11
tests/fixtures/env/one.env
vendored
Normal file
11
tests/fixtures/env/one.env
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Keep the blank lines and comments in this file, please
|
||||
|
||||
ONE=2
|
||||
TWO=1
|
||||
|
||||
# (thanks)
|
||||
|
||||
THREE=3
|
||||
|
||||
FOO=bar
|
||||
# FOO=somethingelse
|
||||
4
tests/fixtures/env/resolve.env
vendored
Normal file
4
tests/fixtures/env/resolve.env
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
FILE_DEF=F1
|
||||
FILE_DEF_EMPTY=
|
||||
ENV_DEF
|
||||
NO_DEF
|
||||
2
tests/fixtures/env/two.env
vendored
Normal file
2
tests/fixtures/env/two.env
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
FOO=baz
|
||||
DOO=dah
|
||||
12
tests/fixtures/extends/circle-1.yml
vendored
Normal file
12
tests/fixtures/extends/circle-1.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
foo:
|
||||
image: busybox
|
||||
bar:
|
||||
image: busybox
|
||||
web:
|
||||
extends:
|
||||
file: circle-2.yml
|
||||
service: web
|
||||
baz:
|
||||
image: busybox
|
||||
quux:
|
||||
image: busybox
|
||||
12
tests/fixtures/extends/circle-2.yml
vendored
Normal file
12
tests/fixtures/extends/circle-2.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
foo:
|
||||
image: busybox
|
||||
bar:
|
||||
image: busybox
|
||||
web:
|
||||
extends:
|
||||
file: circle-1.yml
|
||||
service: web
|
||||
baz:
|
||||
image: busybox
|
||||
quux:
|
||||
image: busybox
|
||||
6
tests/fixtures/extends/common.yml
vendored
Normal file
6
tests/fixtures/extends/common.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
web:
|
||||
image: busybox
|
||||
command: /bin/true
|
||||
environment:
|
||||
- FOO=1
|
||||
- BAR=1
|
||||
16
tests/fixtures/extends/docker-compose.yml
vendored
Normal file
16
tests/fixtures/extends/docker-compose.yml
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
myweb:
|
||||
extends:
|
||||
file: common.yml
|
||||
service: web
|
||||
command: sleep 300
|
||||
links:
|
||||
- "mydb:db"
|
||||
environment:
|
||||
# leave FOO alone
|
||||
# override BAR
|
||||
BAR: "2"
|
||||
# add BAZ
|
||||
BAZ: "2"
|
||||
mydb:
|
||||
image: busybox
|
||||
command: sleep 300
|
||||
6
tests/fixtures/extends/nested-intermediate.yml
vendored
Normal file
6
tests/fixtures/extends/nested-intermediate.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
webintermediate:
|
||||
extends:
|
||||
file: common.yml
|
||||
service: web
|
||||
environment:
|
||||
- "FOO=2"
|
||||
6
tests/fixtures/extends/nested.yml
vendored
Normal file
6
tests/fixtures/extends/nested.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
myweb:
|
||||
extends:
|
||||
file: nested-intermediate.yml
|
||||
service: webintermediate
|
||||
environment:
|
||||
- "BAR=2"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user