DEV Community

Cover image for Setting up WordPress with Docker
Lucas Quadros
Lucas Quadros

Posted on

Setting up WordPress with Docker

Docker simplifies the process of setting up and managing software across different environments. By using Docker containers, you can ensure that your WordPress site will run the same, regardless of where Docker is running.

Prerequisites:

  • Docker installed on your machine.
  • Docker Compose installed on your machine.

Steps:

  1. Create a Docker Compose File:

Start by creating a new directory for your WordPress project and navigate into it:

mkdir my_wordpress_site && cd my_wordpress_site
Enter fullscreen mode Exit fullscreen mode

Now, create a docker-compose.yml file in this directory with the following content:

version: '3'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - ./wp-content:/var/www/html/wp-content

volumes:
  db_data: {}

Enter fullscreen mode Exit fullscreen mode

2. Start Your Containers:

In the terminal, navigate to the directory where your docker-compose.yml is located and run:

docker-compose up -d

Enter fullscreen mode Exit fullscreen mode

This will start your WordPress and MySQL containers. The -d flag will run them in the background.

3.Access WordPress:

Once the containers are up and running, open your browser and go to http://localhost:8000. You should see the WordPress installation page. Proceed with the installation by following the on-screen instructions.

4.Stopping the Containers:

When you're done, you can stop the containers by running:

docker-compose down

Enter fullscreen mode Exit fullscreen mode

Conclusion:
By using Docker with WordPress, you can quickly set up a development environment without the need for manual configuration or the risk of conflicts with other software. This setup ensures consistency across different machines and can be a foundation for more advanced Docker deployments in the future.

Espero que este guia básico seja útil para você! Há muito mais que você pode fazer com Docker e WordPress, como configurar certificados SSL, otimizar o desempenho e integrar com outras ferramentas.

Top comments (0)