mirror of https://github.com/docker/compose.git
paulczar fixes plus example file
Signed-off-by: Patrick Chanezon <patlist@chanezon.com>
This commit is contained in:
parent
9d7b54d8fd
commit
c441ac90d6
|
@ -15,34 +15,28 @@ recommend that you use it in production yet.
|
||||||
|
|
||||||
Using Compose is basically a three-step process.
|
Using Compose is basically a three-step process.
|
||||||
|
|
||||||
First, you define your app's environment with a `Dockerfile` so it can be
|
1. Define your app's environment with a `Dockerfile` so it can be
|
||||||
reproduced anywhere:
|
reproduced anywhere.
|
||||||
|
2. Define the services that make up your app in `docker-compose.yml` so
|
||||||
```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:
|
they can be run together in an isolated environment:
|
||||||
|
3. Lastly, run `docker-compose up` and Compose will start and run your entire app.
|
||||||
|
|
||||||
|
A `docker-compose.yml` looks like this:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
web:
|
web:
|
||||||
build: .
|
build: .
|
||||||
links:
|
command: python app.py
|
||||||
- db
|
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "5000:5000"
|
||||||
db:
|
volumes:
|
||||||
image: postgres
|
- .:/code
|
||||||
|
links:
|
||||||
|
- redis
|
||||||
|
redis:
|
||||||
|
image: redis
|
||||||
```
|
```
|
||||||
|
|
||||||
Lastly, run `docker-compose up` and Compose will start and run your entire app.
|
|
||||||
|
|
||||||
Compose has commands for managing the whole lifecycle of your application:
|
Compose has commands for managing the whole lifecycle of your application:
|
||||||
|
|
||||||
* Start, stop and rebuild services
|
* Start, stop and rebuild services
|
||||||
|
@ -108,13 +102,18 @@ specify how to build the image using a file called
|
||||||
ADD . /code
|
ADD . /code
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
CMD python app.py
|
||||||
|
|
||||||
This tells Docker to include Python, your code, and your Python dependencies in
|
This tells Docker to:
|
||||||
a Docker image. For more information on how to write Dockerfiles, see the
|
|
||||||
[Docker user
|
* Build an image starting with the Python 2.7 image.
|
||||||
guide](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile)
|
* Add the curret directory `.` into the path `/code` in the image.
|
||||||
and the
|
* Set the working directory to `/code`.
|
||||||
[Dockerfile reference](http://docs.docker.com/reference/builder/).
|
* Install 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/).
|
||||||
|
|
||||||
|
You can test that this builds by running `docker build -t web .`.
|
||||||
|
|
||||||
### Define services
|
### Define services
|
||||||
|
|
||||||
|
@ -134,19 +133,21 @@ Next, define a set of services using `docker-compose.yml`:
|
||||||
|
|
||||||
This defines two services:
|
This defines two services:
|
||||||
|
|
||||||
- `web`, which is built from the `Dockerfile` in the current directory. It also
|
#### web
|
||||||
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
|
* Builds from the `Dockerfile` in the current directory.
|
||||||
Redis service, and mount the current directory inside the container so we can
|
* Defines to run the command `python app.py` inside the image on start.
|
||||||
work on code without having to rebuild the image.
|
* Forwards the exposed port 5000 on the container to port 5000 on the host machine.
|
||||||
- `redis`, which uses the public image
|
* Connects the web container to the Redis service via a link.
|
||||||
[redis](https://registry.hub.docker.com/_/redis/), which gets pulled from the
|
* Mounts the current directory on the host to `/code` inside the container allowing you to modify the code without having to rebuild the image.
|
||||||
Docker Hub registry.
|
|
||||||
|
#### redis
|
||||||
|
|
||||||
|
* Uses the public [redis](https://registry.hub.docker.com/_/redis/) image which gets pulled from the Docker Hub registry.
|
||||||
|
|
||||||
### Build and run your app with Compose
|
### Build and run your app with Compose
|
||||||
|
|
||||||
Now, when you run `docker-compose up`, Compose will pull a Redis image, build an
|
Now, when you run `docker-compose up`, Compose will pull a Redis image, build an image for your code, and start everything up:
|
||||||
image for your code, and start everything up:
|
|
||||||
|
|
||||||
$ docker-compose up
|
$ docker-compose up
|
||||||
Pulling image redis...
|
Pulling image redis...
|
||||||
|
@ -157,7 +158,12 @@ image for your code, and start everything up:
|
||||||
web_1 | * Running on http://0.0.0.0:5000/
|
web_1 | * Running on http://0.0.0.0:5000/
|
||||||
|
|
||||||
The web app should now be listening on port 5000 on your Docker daemon host (if
|
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).
|
you're using Boot2docker, `boot2docker ip` will tell you its address). In a browser,
|
||||||
|
open `http://ip-from-boot2docker:5000` and you should get a message in your browser saying:
|
||||||
|
|
||||||
|
`Hello World! I have been seen 1 times.`
|
||||||
|
|
||||||
|
Refreshing the page will see the number increment.
|
||||||
|
|
||||||
If you want to run your services in the background, you can pass the `-d` flag
|
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
|
(for daemon mode) to `docker-compose up` and use `docker-compose ps` to see what
|
||||||
|
|
Loading…
Reference in New Issue