mirror of https://github.com/docker/docs.git
Update compose example to work better with swarm
Update the compose example: * Remove the `links` directive. This allows swarm to distribute containers across available nodes. (with the `links` directive, swarm will be forced to run both containers on the same node.) Note that the `depends_on` directive is sufficient to ensure correct container start up sequence. * Use a docker volume instead of bind mounting a local directory. * Give docker-compose commands for shutting down the Wordpress app, showing how to preserve or remove the persisted data in the volume. Verified proposed change works correctly in both a swarm and a non-swarm environment.
This commit is contained in:
parent
d94864d091
commit
186dfbb336
|
@ -33,7 +33,7 @@ with Docker containers. This quick-start guide demonstrates how to use Compose t
|
|||
db:
|
||||
image: mysql:5.7
|
||||
volumes:
|
||||
- "./.data/db:/var/lib/mysql"
|
||||
- db_data:/var/lib/mysql
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: wordpress
|
||||
|
@ -45,19 +45,17 @@ with Docker containers. This quick-start guide demonstrates how to use Compose t
|
|||
depends_on:
|
||||
- db
|
||||
image: wordpress:latest
|
||||
links:
|
||||
- db
|
||||
ports:
|
||||
- "8000:80"
|
||||
restart: always
|
||||
environment:
|
||||
WORDPRESS_DB_HOST: db:3306
|
||||
WORDPRESS_DB_PASSWORD: wordpress
|
||||
volumes:
|
||||
db_data:
|
||||
```
|
||||
|
||||
**NOTE**: The folder `./.data/db` will be automatically created in the project directory
|
||||
alongside the `docker-compose.yml` which will persist any updates made by wordpress to the
|
||||
database.
|
||||
**NOTE**: The docker volume `db_data` will persist any updates made by wordpress to the database. [Learn more about docker volumes](../engine/tutorials/dockervolumes.md)
|
||||
|
||||
### Build the project
|
||||
|
||||
|
@ -97,6 +95,10 @@ At this point, WordPress should be running on port `8000` of your Docker Host, a
|
|||
|
||||

|
||||
|
||||
### Shutdown/Clean up
|
||||
`docker-compose down` will remove the containers and default network, but preserve your wordpress database.
|
||||
`docker-compose down --volumes` will remove the containers, default network, and the wordpress database.
|
||||
|
||||
## More Compose documentation
|
||||
|
||||
- [User guide](index.md)
|
||||
|
@ -105,4 +107,4 @@ At this point, WordPress should be running on port `8000` of your Docker Host, a
|
|||
- [Get started with Django](django.md)
|
||||
- [Get started with Rails](rails.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
||||
- [Compose file reference](compose-file.md)
|
||||
|
|
Loading…
Reference in New Issue