create a blogging platform using docker-compose

create a blogging platform using docker-compose

  1. Install Docker and Docker Compose on your machine.

  2. Create a new directory for your project and navigate into it.

  3. Create a new file called "docker-compose.yml" and open it in a text editor.

  4. Define the services that you want to run in your Docker Compose file.

codeversion: '3'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example_root_password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: example_user
      MYSQL_PASSWORD: example_password

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: example_user
      WORDPRESS_DB_PASSWORD: example_password
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wp_data:/var/www/html

volumes:
  db_data:
  wp_data:

In this example, we have two services: db and wordpress. The db service is running a MySQL database, and the wordpress service is running the WordPress application.

The db service is using the mysql:5.7 image and creating a named volume db_data to store the database data. It also sets some environment variables for the MySQL root password, database name, and user credentials.

The wordpress service depends on the db service, and is using the wordpress:latest image. It maps port 8000 on the host to port 80 in the container, and creates a named volume wp_data to store the WordPress application data.

The wordpress service also sets some environment variables to configure the WordPress application to use the MySQL database created by the db service.

You can save this file as docker-compose.yml in a directory and then run docker-compose up -d to start the WordPress blog in the background.

GitHub Link : https://github.com/Safiakhatoon767/blogging-platform