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

     1  # WordPress with Docker
     2  
     3  This page shows you how to deploy a sample [WordPress][wordpress] site using
     4  [Docker][docker].
     5  
     6  ### Before you begin
     7  
     8  [Follow these instructions][docker-install] to install runsc with Docker. This
     9  document assumes that the runtime name chosen is `runsc`.
    10  
    11  ### Running WordPress
    12  
    13  Now, let's deploy a WordPress site using Docker. WordPress site requires two
    14  containers: web server in the frontend, MySQL database in the backend.
    15  
    16  > **Note**: This example uses gVisor to sandbox the frontend web server, but not
    17  > the MySQL database backend. In a production setup, due to
    18  > [the I/O overhead](../../architecture_guide/performance) imposed by gVisor,
    19  > **it is not recommended to run your database in a sandbox**. The frontend is
    20  > the critical component with the largest outside attack surface, where gVisor's
    21  > security/performance trade-off makes the most sense. See the
    22  > [Production guide] for more details.
    23  
    24  First, let's define a few environment variables that are shared between both
    25  containers:
    26  
    27  ```bash
    28  export MYSQL_PASSWORD=${YOUR_SECRET_PASSWORD_HERE?}
    29  export MYSQL_DB=wordpress
    30  export MYSQL_USER=wordpress
    31  ```
    32  
    33  Next, let's start the database container running MySQL and wait until the
    34  database is initialized:
    35  
    36  ```shell
    37  # If you want to sandbox the database, add --runtime=runsc to this command.
    38  $ docker run --name mysql -d \
    39      -e MYSQL_RANDOM_ROOT_PASSWORD=1 \
    40      -e MYSQL_PASSWORD="${MYSQL_PASSWORD}" \
    41      -e MYSQL_DATABASE="${MYSQL_DB}" \
    42      -e MYSQL_USER="${MYSQL_USER}" \
    43      mysql:5.7
    44  
    45  # Wait until this message appears in the log.
    46  $ docker logs mysql |& grep 'port: 3306  MySQL Community Server (GPL)'
    47  ```
    48  
    49  Once the database is running, you can start the WordPress frontend. We use the
    50  `--link` option to connect the frontend to the database, and expose the
    51  WordPress to port 8080 on the localhost.
    52  
    53  ```shell
    54  $ docker run --runtime=runsc --name wordpress -d \
    55      --link mysql:mysql \
    56      -p 8080:80 \
    57      -e WORDPRESS_DB_HOST=mysql \
    58      -e WORDPRESS_DB_USER="${MYSQL_USER}" \
    59      -e WORDPRESS_DB_PASSWORD="${MYSQL_PASSWORD}" \
    60      -e WORDPRESS_DB_NAME="${MYSQL_DB}" \
    61      -e WORDPRESS_TABLE_PREFIX=wp_ \
    62      wordpress
    63  ```
    64  
    65  Now, you can access the WordPress website pointing your favorite browser to
    66  <http://localhost:8080>.
    67  
    68  Congratulations! You have just deployed a WordPress site using Docker and
    69  gVisor.
    70  
    71  ### What's next
    72  
    73  Learn how to deploy WordPress with [Kubernetes][wordpress-k8s] or
    74  [Docker Compose][wordpress-compose].
    75  
    76  Before deploying this to production, see the [Production guide] for how to take
    77  full advantage of gVisor.
    78  
    79  [docker]: https://www.docker.com/
    80  [docker-install]: ../quick_start/docker.md
    81  [wordpress]: https://wordpress.com/
    82  [wordpress-k8s]: kubernetes.md
    83  [wordpress-compose]: docker-compose.md
    84  [Production guide]: /docs/user_guide/production/