gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/g3doc/user_guide/tutorials/docker-compose.md (about)

     1  # Wordpress with Docker Compose
     2  
     3  This page shows you how to deploy a sample [WordPress][wordpress] site using
     4  [Docker Compose][docker-compose].
     5  
     6  ### Before you begin
     7  
     8  [Follow these instructions][docker-install] to install runsc with Docker. This
     9  document assumes that Docker and Docker Compose are installed and the runtime
    10  name chosen for gVisor is `runsc`.
    11  
    12  ### Configuration
    13  
    14  We'll start by creating the `docker-compose.yaml` file to specify our services.
    15  We will specify two services, a `wordpress` service for the Wordpress Apache
    16  server, and a `db` service for MySQL. We will configure Wordpress to connect to
    17  MySQL via the `db` service host name.
    18  
    19  > **Note**: This example uses gVisor to sandbox the frontend web server, but not
    20  > the MySQL database backend. In a production setup, due to
    21  > [the I/O overhead](../../architecture_guide/performance) imposed by gVisor,
    22  > **it is not recommended to run your database in a sandbox**. The frontend is
    23  > the critical component with the largest outside attack surface, where gVisor's
    24  > security/performance trade-off makes the most sense. See the
    25  > [Production guide] for more details.
    26  
    27  > **Note**: Docker Compose uses it's own network by default and allows services
    28  > to communicate using their service name. Docker Compose does this by setting
    29  > up a DNS server at IP address 127.0.0.11 and configuring containers to use it
    30  > via [resolv.conf][resolv.conf]. This IP is not addressable inside a gVisor
    31  > sandbox so it's important that we set the DNS IP address to the alternative
    32  > `8.8.8.8` and use a network that allows routing to it. See
    33  > [Networking in Compose][compose-networking] for more details.
    34  
    35  > **Note**: The `runtime` field was removed from services in the 3.x version of
    36  > the API in versions of docker-compose < 1.27.0. You will need to write your
    37  > `docker-compose.yaml` file using the 2.x format or use docker-compose >=
    38  > 1.27.0. See this [issue](https://github.com/docker/compose/issues/6239) for
    39  > more details.
    40  
    41  ```yaml
    42  version: '2.3'
    43  
    44  services:
    45     db:
    46       image: mysql:5.7
    47       volumes:
    48         - db_data:/var/lib/mysql
    49       restart: always
    50       environment:
    51         MYSQL_ROOT_PASSWORD: somewordpress
    52         MYSQL_DATABASE: wordpress
    53         MYSQL_USER: wordpress
    54         MYSQL_PASSWORD: wordpress
    55       # All services must be on the same network to communicate.
    56       network_mode: "bridge"
    57       # Uncomment the following line if you want to sandbox the database.
    58       #runtime: "runsc"
    59  
    60     wordpress:
    61       depends_on:
    62         - db
    63       # When using the "bridge" network specify links.
    64       links:
    65         - db
    66       image: wordpress:latest
    67       ports:
    68         - "8080:80"
    69       restart: always
    70       environment:
    71         WORDPRESS_DB_HOST: db:3306
    72         WORDPRESS_DB_USER: wordpress
    73         WORDPRESS_DB_PASSWORD: wordpress
    74         WORDPRESS_DB_NAME: wordpress
    75       # Specify the dns address if needed.
    76       dns:
    77         - 8.8.8.8
    78       # All services must be on the same network to communicate.
    79       network_mode: "bridge"
    80       # Specify the runtime used by Docker. Must be set up in
    81       #  /etc/docker/daemon.json.
    82       runtime: "runsc"
    83  
    84  volumes:
    85      db_data: {}
    86  ```
    87  
    88  Once you have a `docker-compose.yaml` in the current directory you can start the
    89  containers:
    90  
    91  ```bash
    92  docker-compose up
    93  ```
    94  
    95  Once the containers have started you can access wordpress at
    96  http://localhost:8080.
    97  
    98  Congrats! You now how a working wordpress site up and running using Docker
    99  Compose.
   100  
   101  ### What's next
   102  
   103  Learn how to deploy [WordPress with Kubernetes][wordpress-k8s].
   104  
   105  Before deploying this to production, see the [Production guide] for how to take
   106  full advantage of gVisor.
   107  
   108  [docker-compose]: https://docs.docker.com/compose/
   109  [docker-install]: ../quick_start/docker.md
   110  [wordpress]: https://wordpress.com/
   111  [resolv.conf]: https://man7.org/linux/man-pages/man5/resolv.conf.5.html
   112  [wordpress-k8s]: kubernetes.md
   113  [compose-networking]: https://docs.docker.com/compose/networking/
   114  [Production guide]: /docs/user_guide/production/