Setup WordPress with MySQL using Docker Compose
Setup WordPress with MySQL using Docker Compose
- Prerequisite: Docker and docker-compose are installed.
- Create YAML File: To create a docker-compose YAML file for Wordpress, create a new YAML file with the below content.
wordpress-mysql.yaml
- version: '3.3'
- services:
- db:
- image: mysql:5.7
- volumes:
- - db_data:/var/lib/mysql
- restart: always
- environment:
- MYSQL_ROOT_PASSWORD: test123!
- MYSQL_DATABASE: nishantmysql
- MYSQL_USER: nishant
- MYSQL_PASSWORD: test123!
- wordpress:
- depends_on:
- - db
- image: wordpress:latest
- ports:
- - "8000:80"
- restart: always
- environment:
- WORDPRESS_DB_HOST: db:3306
- WORDPRESS_DB_USER: nishant
- WORDPRESS_DB_PASSWORD: test123!
- WORDPRESS_DB_NAME: nishantmysql
- volumes:
- db_data: {}
and run the command
- docker-compose -f wordpress-mysql.yaml up -d
- Check Status: To check the processes running, execute the command.
- docker-compose -f wordpress-mysql.yaml ps
- Access Wordpress: To access WordPress, navigate to localhost:8000 in your browser. Notice that 8000 is the port to which we have mapped the WordPress port 80 in the YAML file. If you don't remember the port, you can find it out using the command.
- docker port CONTAINER_ID
- Check Containers: To check the containers running, execute the command.
- docker ps -a
- Check Containers Logs: To check any container logs, execute the command.
- docker logs CONTAINER_ID
- Stop Wordpress: To stop the wordpress, run the command.
- docker-compose -f wordpress-mysql.yaml stop
- Stop Container: To remove any container, run the command.
- docker rm CONTAINER_ID
Comments
Post a Comment