docs: update docs of README.mds.
summary: update command docker compose to docker-compose.
This commit is contained in:
@@ -10,14 +10,14 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi
|
||||
|
||||
1. Create an empty project directory.
|
||||
|
||||
You can name the directory something easy for you to remember. This directory is the context for your application image. The directory should only contain resources to build that image.
|
||||
You can name the directory something easy for you to remember. This directory is the context for your application image. The directory should only contain resources to build that image.
|
||||
|
||||
2. Create a new file called `Dockerfile` in your project directory.
|
||||
|
||||
The Dockerfile defines an application's image content via one or more build
|
||||
commands that configure that image. Once built, you can run the image in a
|
||||
container. For more information on `Dockerfile`, see the [Docker user guide](https://docs.docker.com/get-started/)
|
||||
and the [Dockerfile reference](https://docs.docker.com/engine/reference/builder/).
|
||||
The Dockerfile defines an application's image content via one or more build
|
||||
commands that configure that image. Once built, you can run the image in a
|
||||
container. For more information on `Dockerfile`, see the [Docker user guide](https://docs.docker.com/get-started/)
|
||||
and the [Dockerfile reference](https://docs.docker.com/engine/reference/builder/).
|
||||
|
||||
3. Add the following content to the `Dockerfile`.
|
||||
|
||||
@@ -40,26 +40,26 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi
|
||||
|
||||
5. Create a `requirements.txt` in your project directory.
|
||||
|
||||
This file is used by the `RUN pip install -r requirements.txt` command in your `Dockerfile`.
|
||||
This file is used by the `RUN pip install -r requirements.txt` command in your `Dockerfile`.
|
||||
|
||||
6. Add the required software in the file.
|
||||
|
||||
```python
|
||||
Django>=3.0,<4.0
|
||||
psycopg2>=2.8
|
||||
```
|
||||
```python
|
||||
Django>=3.0,<4.0
|
||||
psycopg2>=2.8
|
||||
```
|
||||
|
||||
7. Save and close the `requirements.txt` file.
|
||||
|
||||
8. Create a file called `docker-compose.yml` in your project directory.
|
||||
|
||||
The `docker-compose.yml` file describes the services that make your app. In
|
||||
this example those services are a web server and database. The compose file
|
||||
also describes which Docker images these services use, how they link
|
||||
together, any volumes they might need to be mounted inside the containers.
|
||||
Finally, the `docker-compose.yml` file describes which ports these services
|
||||
expose. See the [`docker-compose.yml` reference](https://docs.docker.com/compose/compose-file/) for more
|
||||
information on how this file works.
|
||||
The `docker-compose.yml` file describes the services that make your app. In
|
||||
this example those services are a web server and database. The compose file
|
||||
also describes which Docker images these services use, how they link
|
||||
together, any volumes they might need to be mounted inside the containers.
|
||||
Finally, the `docker-compose.yml` file describes which ports these services
|
||||
expose. See the [`docker-compose.yml` reference](https://docs.docker.com/compose/compose-file/) for more
|
||||
information on how this file works.
|
||||
|
||||
9. Add the following configuration to the file.
|
||||
|
||||
@@ -79,7 +79,7 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi
|
||||
volumes:
|
||||
- .:/code
|
||||
ports:
|
||||
- "8000:8000"
|
||||
- '8000:8000'
|
||||
environment:
|
||||
- POSTGRES_NAME=postgres
|
||||
- POSTGRES_USER=postgres
|
||||
@@ -104,11 +104,11 @@ In this step, you create a Django starter project by building the image from the
|
||||
|
||||
1. Change to the root of your project directory.
|
||||
|
||||
2. Create the Django project by running the [docker compose run](https://docs.docker.com/engine/reference/commandline/compose_run/)
|
||||
2. Create the Django project by running the [docker-compose run](https://docs.docker.com/engine/reference/commandline/compose_run/)
|
||||
command as follows.
|
||||
|
||||
```console
|
||||
sudo docker compose run web django-admin startproject composeexample .
|
||||
sudo docker-compose run web django-admin startproject composeexample .
|
||||
```
|
||||
|
||||
This instructs Compose to run `django-admin startproject composeexample`
|
||||
@@ -121,7 +121,7 @@ In this step, you create a Django starter project by building the image from the
|
||||
instructs Django to create a set of files and directories representing a
|
||||
Django project.
|
||||
|
||||
3. After the `docker compose` command completes, list the contents of your project.
|
||||
3. After the `docker-compose` command completes, list the contents of your project.
|
||||
|
||||
```console
|
||||
$ ls -l
|
||||
@@ -169,11 +169,11 @@ In this section, you set up the database connection for Django.
|
||||
|
||||
```python
|
||||
# settings.py
|
||||
|
||||
|
||||
import os
|
||||
|
||||
|
||||
[...]
|
||||
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
@@ -192,10 +192,10 @@ In this section, you set up the database connection for Django.
|
||||
|
||||
3. Save and close the file.
|
||||
|
||||
4. Run the [docker compose up](https://docs.docker.com/engine/reference/commandline/compose_up/) command from the top level directory for your project.
|
||||
4. Run the [docker-compose up](https://docs.docker.com/engine/reference/commandline/compose_up/) command from the top level directory for your project.
|
||||
|
||||
```console
|
||||
$ docker compose up
|
||||
$ docker-compose up
|
||||
|
||||
djangosample_db_1 is up-to-date
|
||||
Creating djangosample_web_1 ...
|
||||
@@ -233,8 +233,8 @@ In this section, you set up the database connection for Django.
|
||||
> ALLOWED_HOSTS = ['*']
|
||||
> ```
|
||||
>
|
||||
> This value is **not** safe for production usage. Refer to the
|
||||
> [Django documentation](https://docs.djangoproject.com/en/1.11/ref/settings/#allowed-hosts) for more information.
|
||||
> This value is **not** safe for production usage. Refer to the
|
||||
> [Django documentation](https://docs.djangoproject.com/en/1.11/ref/settings/#allowed-hosts) for more information.
|
||||
|
||||
5. List running containers.
|
||||
|
||||
@@ -250,37 +250,37 @@ In this section, you set up the database connection for Django.
|
||||
|
||||
6. Shut down services and clean up by using either of these methods:
|
||||
|
||||
* Stop the application by typing `Ctrl-C` in the same shell in where you
|
||||
started it:
|
||||
- Stop the application by typing `Ctrl-C` in the same shell in where you
|
||||
started it:
|
||||
|
||||
```console
|
||||
Gracefully stopping... (press Ctrl+C again to force)
|
||||
Killing test_web_1 ... done
|
||||
Killing test_db_1 ... done
|
||||
```
|
||||
```console
|
||||
Gracefully stopping... (press Ctrl+C again to force)
|
||||
Killing test_web_1 ... done
|
||||
Killing test_db_1 ... done
|
||||
```
|
||||
|
||||
* Or, for a more elegant shutdown, switch to a different shell, and run
|
||||
[docker compose down](https://docs.docker.com/engine/reference/commandline/compose_down/) from the top level of your
|
||||
Django sample project directory.
|
||||
- Or, for a more elegant shutdown, switch to a different shell, and run
|
||||
[docker-compose down](https://docs.docker.com/engine/reference/commandline/compose_down/) from the top level of your
|
||||
Django sample project directory.
|
||||
|
||||
```console
|
||||
$ docker compose down
|
||||
```console
|
||||
$ docker-compose down
|
||||
|
||||
Stopping django_web_1 ... done
|
||||
Stopping django_db_1 ... done
|
||||
Removing django_web_1 ... done
|
||||
Removing django_web_run_1 ... done
|
||||
Removing django_db_1 ... done
|
||||
Removing network django_default
|
||||
```
|
||||
Stopping django_web_1 ... done
|
||||
Stopping django_db_1 ... done
|
||||
Removing django_web_1 ... done
|
||||
Removing django_web_run_1 ... done
|
||||
Removing django_db_1 ... done
|
||||
Removing network django_default
|
||||
```
|
||||
|
||||
Once you've shut down the app, you can safely remove the Django project directory (for example, `rm -rf django`).
|
||||
Once you've shut down the app, you can safely remove the Django project directory (for example, `rm -rf django`).
|
||||
|
||||
## More Compose documentation
|
||||
|
||||
* [Docker Compose overview](https://docs.docker.com/compose/)
|
||||
* [Install Docker Compose](https://docs.docker.com/compose/install/)
|
||||
* [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/)
|
||||
* [Docker Compose Command line reference](https://docs.docker.com/compose/reference/)
|
||||
* [Compose file reference](https://docs.docker.com/compose/compose-file/)
|
||||
* [Awesome Compose Django sample application](../../django/README.md)
|
||||
- [Docker Compose overview](https://docs.docker.com/compose/)
|
||||
- [Install Docker Compose](https://docs.docker.com/compose/install/)
|
||||
- [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/)
|
||||
- [Docker Compose Command line reference](https://docs.docker.com/compose/reference/)
|
||||
- [Compose file reference](https://docs.docker.com/compose/compose-file/)
|
||||
- [Awesome Compose Django sample application](../../django/README.md)
|
||||
|
@@ -7,7 +7,7 @@ a Rails/PostgreSQL app. Before starting, [install Compose](https://docs.docker.c
|
||||
|
||||
Start by setting up the files needed to build the app. The app will run inside a
|
||||
Docker container containing its dependencies. Defining dependencies is done using
|
||||
a file called `Dockerfile`. To begin with, the Dockerfile consists of:
|
||||
a file called `Dockerfile`. To begin with, the Dockerfile consists of:
|
||||
|
||||
```dockerfile
|
||||
# syntax=docker/dockerfile:1
|
||||
@@ -82,7 +82,7 @@ services:
|
||||
volumes:
|
||||
- .:/myapp
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- '3000:3000'
|
||||
depends_on:
|
||||
- db
|
||||
```
|
||||
@@ -94,10 +94,10 @@ services:
|
||||
### Build the project
|
||||
|
||||
With those files in place, you can now generate the Rails skeleton app
|
||||
using [docker compose run](https://docs.docker.com/engine/reference/commandline/compose_run/):
|
||||
using [docker-compose run](https://docs.docker.com/engine/reference/commandline/compose_run/):
|
||||
|
||||
```console
|
||||
$ docker compose run --no-deps web rails new . --force --database=postgresql
|
||||
$ docker-compose run --no-deps web rails new . --force --database=postgresql
|
||||
```
|
||||
|
||||
First, Compose builds the image for the `web` service using the `Dockerfile`.
|
||||
@@ -148,7 +148,7 @@ changes to the `Gemfile` or the Dockerfile, should be the only times you’ll ne
|
||||
to rebuild.)
|
||||
|
||||
```console
|
||||
$ docker compose build
|
||||
$ docker-compose build
|
||||
```
|
||||
|
||||
### Connect the database
|
||||
@@ -173,17 +173,16 @@ development:
|
||||
<<: *default
|
||||
database: myapp_development
|
||||
|
||||
|
||||
test:
|
||||
<<: *default
|
||||
database: myapp_test
|
||||
```
|
||||
|
||||
You can now boot the app with [docker compose up](https://docs.docker.com/engine/reference/commandline/compose_up/).
|
||||
You can now boot the app with [docker-compose up](https://docs.docker.com/engine/reference/commandline/compose_up/).
|
||||
If all is well, you should see some PostgreSQL output:
|
||||
|
||||
```console
|
||||
$ docker compose up
|
||||
$ docker-compose up
|
||||
|
||||
rails_db_1 is up-to-date
|
||||
Creating rails_web_1 ... done
|
||||
@@ -200,7 +199,7 @@ db_1 | 2018-03-21 20:18:37.772 UTC [1] LOG: database system is ready to accep
|
||||
Finally, you need to create the database. In another terminal, run:
|
||||
|
||||
```console
|
||||
$ docker compose run web rake db:create
|
||||
$ docker-compose run web rake db:create
|
||||
Starting rails_db_1 ... done
|
||||
Created database 'myapp_development'
|
||||
Created database 'myapp_test'
|
||||
@@ -217,13 +216,13 @@ browser to see the Rails Welcome.
|
||||
|
||||
### Stop the application
|
||||
|
||||
To stop the application, run [docker compose down](https://docs.docker.com/engine/reference/commandline/compose_down/) in
|
||||
To stop the application, run [docker-compose down](https://docs.docker.com/engine/reference/commandline/compose_down/) in
|
||||
your project directory. You can use the same terminal window in which you
|
||||
started the database, or another one where you have access to a command prompt.
|
||||
This is a clean way to stop the application.
|
||||
|
||||
```console
|
||||
$ docker compose down
|
||||
$ docker-compose down
|
||||
|
||||
Stopping rails_web_1 ... done
|
||||
Stopping rails_db_1 ... done
|
||||
@@ -236,15 +235,15 @@ Removing network rails_default
|
||||
|
||||
### Restart the application
|
||||
|
||||
To restart the application run `docker compose up` in the project directory.
|
||||
To restart the application run `docker-compose up` in the project directory.
|
||||
|
||||
### Rebuild the application
|
||||
|
||||
If you make changes to the Gemfile or the Compose file to try out some different
|
||||
configurations, you need to rebuild. Some changes require only
|
||||
`docker compose up --build`, but a full rebuild requires a re-run of
|
||||
`docker compose run web bundle install` to sync changes in the `Gemfile.lock` to
|
||||
the host, followed by `docker compose up --build`.
|
||||
`docker-compose up --build`, but a full rebuild requires a re-run of
|
||||
`docker-compose run web bundle install` to sync changes in the `Gemfile.lock` to
|
||||
the host, followed by `docker-compose up --build`.
|
||||
|
||||
Here is an example of the first case, where a full rebuild is not necessary.
|
||||
Suppose you simply want to change the exposed port on the local host from `3000`
|
||||
@@ -254,10 +253,10 @@ the changes:
|
||||
|
||||
```yaml
|
||||
ports:
|
||||
- "3001:3000"
|
||||
- '3001:3000'
|
||||
```
|
||||
|
||||
Now, rebuild and restart the app with `docker compose up --build`.
|
||||
Now, rebuild and restart the app with `docker-compose up --build`.
|
||||
|
||||
Inside the container, your app is running on the same port as before `3000`, but
|
||||
the Rails Welcome is now available on `http://localhost:3001` on your local
|
||||
@@ -265,8 +264,8 @@ host.
|
||||
|
||||
## More Compose documentation
|
||||
|
||||
* [Docker Compose overview](https://docs.docker.com/compose/)
|
||||
* [Install Docker Compose](https://docs.docker.com/compose/install/)
|
||||
* [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/)
|
||||
* [Docker Compose Command line reference](https://docs.docker.com/compose/reference/)
|
||||
* [Compose file reference](https://docs.docker.com/compose/compose-file/)
|
||||
- [Docker Compose overview](https://docs.docker.com/compose/)
|
||||
- [Install Docker Compose](https://docs.docker.com/compose/install/)
|
||||
- [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/)
|
||||
- [Docker Compose Command line reference](https://docs.docker.com/compose/reference/)
|
||||
- [Compose file reference](https://docs.docker.com/compose/compose-file/)
|
||||
|
@@ -16,8 +16,8 @@ Compose to set up and run WordPress. Before starting, make sure you have
|
||||
This project directory contains a `docker-compose.yml` file which
|
||||
is complete in itself for a good starter wordpress project.
|
||||
|
||||
>**Tip**: You can use either a `.yml` or `.yaml` extension for
|
||||
this file. They both work.
|
||||
> **Tip**: You can use either a `.yml` or `.yaml` extension for
|
||||
> this file. They both work.
|
||||
|
||||
2. Change into your project directory.
|
||||
|
||||
@@ -67,24 +67,24 @@ Compose to set up and run WordPress. Before starting, make sure you have
|
||||
wp_data:
|
||||
```
|
||||
|
||||
> **Notes**:
|
||||
>
|
||||
* The docker volumes `db_data` and `wordpress_data` persists updates made by WordPress
|
||||
to the database, as well as the installed themes and plugins. [Learn more about docker volumes](https://docs.docker.com/storage/volumes/)
|
||||
>
|
||||
* WordPress Multisite works only on ports `80` and `443`.
|
||||
{: .note-vanilla}
|
||||
> **Notes**:
|
||||
|
||||
- The docker volumes `db_data` and `wordpress_data` persists updates made by WordPress
|
||||
to the database, as well as the installed themes and plugins. [Learn more about docker volumes](https://docs.docker.com/storage/volumes/)
|
||||
>
|
||||
- WordPress Multisite works only on ports `80` and `443`.
|
||||
{: .note-vanilla}
|
||||
|
||||
### Build the project
|
||||
|
||||
Now, run `docker compose up -d` from your project directory.
|
||||
Now, run `docker-compose up -d` from your project directory.
|
||||
|
||||
This runs [`docker compose up`](https://docs.docker.com/engine/reference/commandline/compose_up/) in detached mode, pulls
|
||||
This runs [`docker-compose up`](https://docs.docker.com/engine/reference/commandline/compose_up/) in detached mode, pulls
|
||||
the needed Docker images, and starts the wordpress and database containers, as shown in
|
||||
the example below.
|
||||
|
||||
```console
|
||||
$ docker compose up -d
|
||||
$ docker-compose up -d
|
||||
|
||||
Creating network "my_wordpress_default" with the default driver
|
||||
Pulling db (mysql:5.7)...
|
||||
@@ -107,9 +107,9 @@ Creating my_wordpress_wordpress_1
|
||||
```
|
||||
|
||||
> **Note**: WordPress Multisite works only on ports `80` and/or `443`.
|
||||
If you get an error message about binding `0.0.0.0` to port `80` or `443`
|
||||
(depending on which one you specified), it is likely that the port you
|
||||
configured for WordPress is already in use by another service.
|
||||
> If you get an error message about binding `0.0.0.0` to port `80` or `443`
|
||||
> (depending on which one you specified), it is likely that the port you
|
||||
> configured for WordPress is already in use by another service.
|
||||
|
||||
### Bring up WordPress in a web browser
|
||||
|
||||
@@ -118,8 +118,8 @@ and you can complete the "famous five-minute installation" as a WordPress
|
||||
administrator.
|
||||
|
||||
> **Note**: The WordPress site is not immediately available on port `80`
|
||||
because the containers are still being initialized and may take a couple of
|
||||
minutes before the first load.
|
||||
> because the containers are still being initialized and may take a couple of
|
||||
> minutes before the first load.
|
||||
|
||||
If you are using Docker Desktop for Mac or Docker Desktop for Windows, you can use
|
||||
`http://localhost` as the IP address, and open `http://localhost:80` in a web
|
||||
@@ -131,17 +131,17 @@ browser.
|
||||
|
||||
### Shutdown and cleanup
|
||||
|
||||
The command [`docker compose down`](https://docs.docker.com/engine/reference/commandline/compose_down/) removes the
|
||||
The command [`docker-compose down`](https://docs.docker.com/engine/reference/commandline/compose_down/) removes the
|
||||
containers and default network, but preserves your WordPress database.
|
||||
|
||||
The command `docker compose down --volumes` removes the containers, default
|
||||
The command `docker-compose down --volumes` removes the containers, default
|
||||
network, and the WordPress database.
|
||||
|
||||
## More Compose documentation
|
||||
|
||||
* [Docker Compose overview](https://docs.docker.com/compose/)
|
||||
* [Install Docker Compose](https://docs.docker.com/compose/install/)
|
||||
* [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/)
|
||||
* [Docker Compose Command line reference](https://docs.docker.com/compose/reference/)
|
||||
* [Compose file reference](https://docs.docker.com/compose/compose-file/)
|
||||
* [Awesome Compose WordPress sample](../../wordpress-mysql/README.md)
|
||||
- [Docker Compose overview](https://docs.docker.com/compose/)
|
||||
- [Install Docker Compose](https://docs.docker.com/compose/install/)
|
||||
- [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/)
|
||||
- [Docker Compose Command line reference](https://docs.docker.com/compose/reference/)
|
||||
- [Compose file reference](https://docs.docker.com/compose/compose-file/)
|
||||
- [Awesome Compose WordPress sample](../../wordpress-mysql/README.md)
|
||||
|
Reference in New Issue
Block a user