summaryrefslogtreecommitdiffhomepage
path: root/g3doc/user_guide/tutorials/docker-compose.md
blob: 3284231f805af5370fdc82144f14d104fae3c708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Wordpress with Docker Compose

This page shows you how to deploy a sample [WordPress][wordpress] site using
[Docker Compose][docker-compose].

### Before you begin

[Follow these instructions][docker-install] to install runsc with Docker. This
document assumes that Docker and Docker Compose are installed and the runtime
name chosen for gVisor is `runsc`.

### Configuration

We'll start by creating the `docker-compose.yaml` file to specify our services.
We will specify two services, a `wordpress` service for the Wordpress Apache
server, and a `db` service for MySQL. We will configure Wordpress to connect to
MySQL via the `db` service host name.

> **Note:** Docker Compose uses it's own network by default and allows services
> to communicate using their service name. Docker Compose does this by setting
> up a DNS server at IP address 127.0.0.11 and configuring containers to use it
> via [resolv.conf][resolv.conf]. This IP is not addressable inside a gVisor
> sandbox so it's important that we set the DNS IP address to the alternative
> `8.8.8.8` and use a network that allows routing to it. See
> [Networking in Compose][compose-networking] for more details.

> **Note:** The `runtime` field was removed from services in the 3.x version of
> the API in versions of docker-compose < 1.27.0. You will need to write your
> `docker-compose.yaml` file using the 2.x format or use docker-compose >=
> 1.27.0. See this [issue](https://github.com/docker/compose/issues/6239) for
> more details.

```yaml
version: '2.3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress
     # All services must be on the same network to communicate.
     network_mode: "bridge"

   wordpress:
     depends_on:
       - db
     # When using the "bridge" network specify links.
     links:
       - db
     image: wordpress:latest
     ports:
       - "8080:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
     # Specify the dns address if needed.
     dns:
       - 8.8.8.8
     # All services must be on the same network to communicate.
     network_mode: "bridge"
     # Specify the runtime used by Docker. Must be set up in
     #  /etc/docker/daemon.json.
     runtime: "runsc"

volumes:
    db_data: {}
```

Once you have a `docker-compose.yaml` in the current directory you can start the
containers:

```bash
docker-compose up
```

Once the containers have started you can access wordpress at
http://localhost:8080.

Congrats! You now how a working wordpress site up and running using Docker
Compose.

### What's next

Learn how to deploy [WordPress with Kubernetes][wordpress-k8s].

[docker-compose]: https://docs.docker.com/compose/
[docker-install]: ../quick_start/docker.md
[wordpress]: https://wordpress.com/
[resolv.conf]: https://man7.org/linux/man-pages/man5/resolv.conf.5.html
[wordpress-k8s]: kubernetes.md
[compose-networking]: https://docs.docker.com/compose/networking/