Write down Docker Compose file for WordPress application

Write down Docker Compose file for WordPress application

To make a WordPress app with Docker Compose, create a docker-compose.yml file. Here's a simple example with WordPress and MySQL services:

version: '3'
    image: wordpress:latest
      - "8000:80"
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
      - ./wordpress:/var/www/html

    image: mysql:5.7
      MYSQL_ROOT_PASSWORD: examplepass
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      - ./mysql:/var/lib/mysql

In this example:

  • The wordpress service uses the official WordPress image, exposes port 8000 on the host, and sets up environment variables for connecting to the MySQL database. It also mounts a volume to persist WordPress data.

  • The mysql service uses the official MySQL 5.7 image, sets up environment variables for configuring the MySQL database, and mounts a volume to persist MySQL data.

To use this configuration:

  1. Create a directory for your WordPress project and navigate to it.

  2. Create the docker-compose.yml file with the content above.

  3. Run the following command to start the services:

     docker-compose up

    This will download the required images, create and start the containers.

  4. Access the WordPress site by visiting http://localhost:8000 in your web browser. Follow the on-screen instructions to set up your WordPress site.

The MySQL data and WordPress content will be saved in the mysql and wordpress folders inside your project folder, respectively.

To stop and remove the containers, you can use:

docker-compose down

This is a simple setup, and you can change it more depending on your needs. Always make sure to keep sensitive information (like passwords) safe, especially in production environments.

Did you find this article valuable?

Support LingarajTechhub All About Programming by becoming a sponsor. Any amount is appreciated!