mirror of https://github.com/docker/docs.git
Replace backtick code blocks with indentation
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
911cd60360
commit
511fc4a05c
188
docs/extends.md
188
docs/extends.md
|
@ -28,25 +28,21 @@ the configuration around.
|
||||||
When defining any service in `docker-compose.yml`, you can declare that you are
|
When defining any service in `docker-compose.yml`, you can declare that you are
|
||||||
extending another service like this:
|
extending another service like this:
|
||||||
|
|
||||||
```yaml
|
web:
|
||||||
web:
|
extends:
|
||||||
extends:
|
file: common-services.yml
|
||||||
file: common-services.yml
|
service: webapp
|
||||||
service: webapp
|
|
||||||
```
|
|
||||||
|
|
||||||
This instructs Compose to re-use the configuration for the `webapp` service
|
This instructs Compose to re-use the configuration for the `webapp` service
|
||||||
defined in the `common-services.yml` file. Suppose that `common-services.yml`
|
defined in the `common-services.yml` file. Suppose that `common-services.yml`
|
||||||
looks like this:
|
looks like this:
|
||||||
|
|
||||||
```yaml
|
webapp:
|
||||||
webapp:
|
build: .
|
||||||
build: .
|
ports:
|
||||||
ports:
|
- "8000:8000"
|
||||||
- "8000:8000"
|
volumes:
|
||||||
volumes:
|
- "/data"
|
||||||
- "/data"
|
|
||||||
```
|
|
||||||
|
|
||||||
In this case, you'll get exactly the same result as if you wrote
|
In this case, you'll get exactly the same result as if you wrote
|
||||||
`docker-compose.yml` with that `build`, `ports` and `volumes` configuration
|
`docker-compose.yml` with that `build`, `ports` and `volumes` configuration
|
||||||
|
@ -55,31 +51,27 @@ defined directly under `web`.
|
||||||
You can go further and define (or re-define) configuration locally in
|
You can go further and define (or re-define) configuration locally in
|
||||||
`docker-compose.yml`:
|
`docker-compose.yml`:
|
||||||
|
|
||||||
```yaml
|
web:
|
||||||
web:
|
extends:
|
||||||
extends:
|
file: common-services.yml
|
||||||
file: common-services.yml
|
service: webapp
|
||||||
service: webapp
|
environment:
|
||||||
environment:
|
- DEBUG=1
|
||||||
- DEBUG=1
|
cpu_shares: 5
|
||||||
cpu_shares: 5
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also write other services and link your `web` service to them:
|
You can also write other services and link your `web` service to them:
|
||||||
|
|
||||||
```yaml
|
web:
|
||||||
web:
|
extends:
|
||||||
extends:
|
file: common-services.yml
|
||||||
file: common-services.yml
|
service: webapp
|
||||||
service: webapp
|
environment:
|
||||||
environment:
|
- DEBUG=1
|
||||||
- DEBUG=1
|
cpu_shares: 5
|
||||||
cpu_shares: 5
|
links:
|
||||||
links:
|
- db
|
||||||
- db
|
db:
|
||||||
db:
|
image: postgres
|
||||||
image: postgres
|
|
||||||
```
|
|
||||||
|
|
||||||
For full details on how to use `extends`, refer to the [reference](#reference).
|
For full details on how to use `extends`, refer to the [reference](#reference).
|
||||||
|
|
||||||
|
@ -271,103 +263,91 @@ For single-value options like `image`, `command` or `mem_limit`, the new value
|
||||||
replaces the old value. **This is the default behaviour - all exceptions are
|
replaces the old value. **This is the default behaviour - all exceptions are
|
||||||
listed below.**
|
listed below.**
|
||||||
|
|
||||||
```yaml
|
# original service
|
||||||
# original service
|
command: python app.py
|
||||||
command: python app.py
|
|
||||||
|
|
||||||
# local service
|
# local service
|
||||||
command: python otherapp.py
|
command: python otherapp.py
|
||||||
|
|
||||||
# result
|
# result
|
||||||
command: python otherapp.py
|
command: python otherapp.py
|
||||||
```
|
|
||||||
|
|
||||||
In the case of `build` and `image`, using one in the local service causes
|
In the case of `build` and `image`, using one in the local service causes
|
||||||
Compose to discard the other, if it was defined in the original service.
|
Compose to discard the other, if it was defined in the original service.
|
||||||
|
|
||||||
```yaml
|
# original service
|
||||||
# original service
|
build: .
|
||||||
build: .
|
|
||||||
|
|
||||||
# local service
|
# local service
|
||||||
image: redis
|
image: redis
|
||||||
|
|
||||||
# result
|
# result
|
||||||
image: redis
|
image: redis
|
||||||
```
|
|
||||||
|
|
||||||
```yaml
|
# original service
|
||||||
# original service
|
image: redis
|
||||||
image: redis
|
|
||||||
|
|
||||||
# local service
|
# local service
|
||||||
build: .
|
build: .
|
||||||
|
|
||||||
# result
|
# result
|
||||||
build: .
|
build: .
|
||||||
```
|
|
||||||
|
|
||||||
For the **multi-value options** `ports`, `expose`, `external_links`, `dns` and
|
For the **multi-value options** `ports`, `expose`, `external_links`, `dns` and
|
||||||
`dns_search`, Compose concatenates both sets of values:
|
`dns_search`, Compose concatenates both sets of values:
|
||||||
|
|
||||||
```yaml
|
# original service
|
||||||
# original service
|
expose:
|
||||||
expose:
|
- "3000"
|
||||||
- "3000"
|
|
||||||
|
|
||||||
# local service
|
# local service
|
||||||
expose:
|
expose:
|
||||||
- "4000"
|
- "4000"
|
||||||
- "5000"
|
- "5000"
|
||||||
|
|
||||||
# result
|
# result
|
||||||
expose:
|
expose:
|
||||||
- "3000"
|
- "3000"
|
||||||
- "4000"
|
- "4000"
|
||||||
- "5000"
|
- "5000"
|
||||||
```
|
|
||||||
|
|
||||||
In the case of `environment` and `labels`, Compose "merges" entries together
|
In the case of `environment` and `labels`, Compose "merges" entries together
|
||||||
with locally-defined values taking precedence:
|
with locally-defined values taking precedence:
|
||||||
|
|
||||||
```yaml
|
# original service
|
||||||
# original service
|
environment:
|
||||||
environment:
|
- FOO=original
|
||||||
- FOO=original
|
- BAR=original
|
||||||
- BAR=original
|
|
||||||
|
|
||||||
# local service
|
# local service
|
||||||
environment:
|
environment:
|
||||||
- BAR=local
|
- BAR=local
|
||||||
- BAZ=local
|
- BAZ=local
|
||||||
|
|
||||||
# result
|
# result
|
||||||
environment:
|
environment:
|
||||||
- FOO=original
|
- FOO=original
|
||||||
- BAR=local
|
- BAR=local
|
||||||
- BAZ=local
|
- BAZ=local
|
||||||
```
|
|
||||||
|
|
||||||
Finally, for `volumes` and `devices`, Compose "merges" entries together with
|
Finally, for `volumes` and `devices`, Compose "merges" entries together with
|
||||||
locally-defined bindings taking precedence:
|
locally-defined bindings taking precedence:
|
||||||
|
|
||||||
```yaml
|
# original service
|
||||||
# original service
|
volumes:
|
||||||
volumes:
|
- /original-dir/foo:/foo
|
||||||
- /original-dir/foo:/foo
|
- /original-dir/bar:/bar
|
||||||
- /original-dir/bar:/bar
|
|
||||||
|
|
||||||
# local service
|
# local service
|
||||||
volumes:
|
volumes:
|
||||||
- /local-dir/bar:/bar
|
- /local-dir/bar:/bar
|
||||||
- /local-dir/baz/:baz
|
- /local-dir/baz/:baz
|
||||||
|
|
||||||
# result
|
# result
|
||||||
volumes:
|
volumes:
|
||||||
- /original-dir/foo:/foo
|
- /original-dir/foo:/foo
|
||||||
- /local-dir/bar:/bar
|
- /local-dir/bar:/bar
|
||||||
- /local-dir/baz/:baz
|
- /local-dir/baz/:baz
|
||||||
```
|
|
||||||
|
|
||||||
## Compose documentation
|
## Compose documentation
|
||||||
|
|
||||||
|
|
|
@ -29,18 +29,16 @@ they can be run together in an isolated environment:
|
||||||
|
|
||||||
A `docker-compose.yml` looks like this:
|
A `docker-compose.yml` looks like this:
|
||||||
|
|
||||||
```yaml
|
web:
|
||||||
web:
|
build: .
|
||||||
build: .
|
ports:
|
||||||
ports:
|
- "5000:5000"
|
||||||
- "5000:5000"
|
volumes:
|
||||||
volumes:
|
- .:/code
|
||||||
- .:/code
|
links:
|
||||||
links:
|
- redis
|
||||||
- redis
|
redis:
|
||||||
redis:
|
image: redis
|
||||||
image: redis
|
|
||||||
```
|
|
||||||
|
|
||||||
Compose has commands for managing the whole lifecycle of your application:
|
Compose has commands for managing the whole lifecycle of your application:
|
||||||
|
|
||||||
|
@ -79,21 +77,19 @@ Next, you'll want to make a directory for the project:
|
||||||
Inside this directory, create `app.py`, a simple web app that uses the Flask
|
Inside this directory, create `app.py`, a simple web app that uses the Flask
|
||||||
framework and increments a value in Redis:
|
framework and increments a value in Redis:
|
||||||
|
|
||||||
```python
|
from flask import Flask
|
||||||
from flask import Flask
|
from redis import Redis
|
||||||
from redis import Redis
|
import os
|
||||||
import os
|
app = Flask(__name__)
|
||||||
app = Flask(__name__)
|
redis = Redis(host='redis', port=6379)
|
||||||
redis = Redis(host='redis', port=6379)
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def hello():
|
def hello():
|
||||||
redis.incr('hits')
|
redis.incr('hits')
|
||||||
return 'Hello World! I have been seen %s times.' % redis.get('hits')
|
return 'Hello World! I have been seen %s times.' % redis.get('hits')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", debug=True)
|
app.run(host="0.0.0.0", debug=True)
|
||||||
```
|
|
||||||
|
|
||||||
Next, define the Python dependencies in a file called `requirements.txt`:
|
Next, define the Python dependencies in a file called `requirements.txt`:
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,8 @@ Dockerfiles, see the
|
||||||
[Dockerfile reference](http://docs.docker.com/reference/builder/). In this case,
|
[Dockerfile reference](http://docs.docker.com/reference/builder/). In this case,
|
||||||
your Dockerfile should be:
|
your Dockerfile should be:
|
||||||
|
|
||||||
```
|
FROM orchardup/php5
|
||||||
FROM orchardup/php5
|
ADD . /code
|
||||||
ADD . /code
|
|
||||||
```
|
|
||||||
|
|
||||||
This tells Docker how to build an image defining a container that contains PHP
|
This tells Docker how to build an image defining a container that contains PHP
|
||||||
and Wordpress.
|
and Wordpress.
|
||||||
|
@ -43,74 +41,69 @@ and Wordpress.
|
||||||
Next you'll create a `docker-compose.yml` file that will start your web service
|
Next you'll create a `docker-compose.yml` file that will start your web service
|
||||||
and a separate MySQL instance:
|
and a separate MySQL instance:
|
||||||
|
|
||||||
```
|
web:
|
||||||
web:
|
build: .
|
||||||
build: .
|
command: php -S 0.0.0.0:8000 -t /code
|
||||||
command: php -S 0.0.0.0:8000 -t /code
|
ports:
|
||||||
ports:
|
- "8000:8000"
|
||||||
- "8000:8000"
|
links:
|
||||||
links:
|
- db
|
||||||
- db
|
volumes:
|
||||||
volumes:
|
- .:/code
|
||||||
- .:/code
|
db:
|
||||||
db:
|
image: orchardup/mysql
|
||||||
image: orchardup/mysql
|
environment:
|
||||||
environment:
|
MYSQL_DATABASE: wordpress
|
||||||
MYSQL_DATABASE: wordpress
|
|
||||||
```
|
|
||||||
|
|
||||||
Two supporting files are needed to get this working - first, `wp-config.php` is
|
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
|
the standard Wordpress config file with a single change to point the database
|
||||||
configuration at the `db` container:
|
configuration at the `db` container:
|
||||||
|
|
||||||
```
|
<?php
|
||||||
<?php
|
define('DB_NAME', 'wordpress');
|
||||||
define('DB_NAME', 'wordpress');
|
define('DB_USER', 'root');
|
||||||
define('DB_USER', 'root');
|
define('DB_PASSWORD', '');
|
||||||
define('DB_PASSWORD', '');
|
define('DB_HOST', "db:3306");
|
||||||
define('DB_HOST', "db:3306");
|
define('DB_CHARSET', 'utf8');
|
||||||
define('DB_CHARSET', 'utf8');
|
define('DB_COLLATE', '');
|
||||||
define('DB_COLLATE', '');
|
|
||||||
|
|
||||||
define('AUTH_KEY', 'put your unique phrase here');
|
define('AUTH_KEY', 'put your unique phrase here');
|
||||||
define('SECURE_AUTH_KEY', 'put your unique phrase here');
|
define('SECURE_AUTH_KEY', 'put your unique phrase here');
|
||||||
define('LOGGED_IN_KEY', 'put your unique phrase here');
|
define('LOGGED_IN_KEY', 'put your unique phrase here');
|
||||||
define('NONCE_KEY', 'put your unique phrase here');
|
define('NONCE_KEY', 'put your unique phrase here');
|
||||||
define('AUTH_SALT', 'put your unique phrase here');
|
define('AUTH_SALT', 'put your unique phrase here');
|
||||||
define('SECURE_AUTH_SALT', 'put your unique phrase here');
|
define('SECURE_AUTH_SALT', 'put your unique phrase here');
|
||||||
define('LOGGED_IN_SALT', 'put your unique phrase here');
|
define('LOGGED_IN_SALT', 'put your unique phrase here');
|
||||||
define('NONCE_SALT', 'put your unique phrase here');
|
define('NONCE_SALT', 'put your unique phrase here');
|
||||||
|
|
||||||
$table_prefix = 'wp_';
|
$table_prefix = 'wp_';
|
||||||
define('WPLANG', '');
|
define('WPLANG', '');
|
||||||
define('WP_DEBUG', false);
|
define('WP_DEBUG', false);
|
||||||
|
|
||||||
if ( !defined('ABSPATH') )
|
if ( !defined('ABSPATH') )
|
||||||
define('ABSPATH', dirname(__FILE__) . '/');
|
define('ABSPATH', dirname(__FILE__) . '/');
|
||||||
|
|
||||||
require_once(ABSPATH . 'wp-settings.php');
|
require_once(ABSPATH . 'wp-settings.php');
|
||||||
```
|
|
||||||
|
|
||||||
Second, `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
|
||||||
<?php
|
|
||||||
|
$root = $_SERVER['DOCUMENT_ROOT'];
|
||||||
|
chdir($root);
|
||||||
|
$path = '/'.ltrim(parse_url($_SERVER['REQUEST_URI'])['path'],'/');
|
||||||
|
set_include_path(get_include_path().':'.__DIR__);
|
||||||
|
if(file_exists($root.$path))
|
||||||
|
{
|
||||||
|
if(is_dir($root.$path) && substr($path,strlen($path) - 1, 1) !== '/')
|
||||||
|
$path = rtrim($path,'/').'/index.php';
|
||||||
|
if(strpos($path,'.php') === false) return false;
|
||||||
|
else {
|
||||||
|
chdir(dirname($root.$path));
|
||||||
|
require_once $root.$path;
|
||||||
|
}
|
||||||
|
}else include_once 'index.php';
|
||||||
|
|
||||||
$root = $_SERVER['DOCUMENT_ROOT'];
|
|
||||||
chdir($root);
|
|
||||||
$path = '/'.ltrim(parse_url($_SERVER['REQUEST_URI'])['path'],'/');
|
|
||||||
set_include_path(get_include_path().':'.__DIR__);
|
|
||||||
if(file_exists($root.$path))
|
|
||||||
{
|
|
||||||
if(is_dir($root.$path) && substr($path,strlen($path) - 1, 1) !== '/')
|
|
||||||
$path = rtrim($path,'/').'/index.php';
|
|
||||||
if(strpos($path,'.php') === false) return false;
|
|
||||||
else {
|
|
||||||
chdir(dirname($root.$path));
|
|
||||||
require_once $root.$path;
|
|
||||||
}
|
|
||||||
}else include_once 'index.php';
|
|
||||||
```
|
|
||||||
### Build the project
|
### Build the project
|
||||||
|
|
||||||
With those four files in place, run `docker-compose up` inside your Wordpress
|
With those four files in place, run `docker-compose up` inside your Wordpress
|
||||||
|
|
Loading…
Reference in New Issue