Install WordPress on Docker
Follow these steps:
- Pull the WordPress Docker Image
Pull the official WordPress Docker image from Docker Hub:
docker pull wordpress
- Create a Network for the Containers
Create a Docker network to allow the WordPress and MySQL containers to communicate:
docker network create wordpress-net
- Run the MySQL Container
Run a MySQL container and join it to the network:
docker run -d --name mysql --network wordpress-net -e MYSQL_ROOT_PASSWORD=root_password -e MYSQL_DATABASE=wordpress mysql
Replace root_password
with a secure password.
- Run the WordPress Container
Run the WordPress container and link it to the MySQL container. Also map port 80 to access WordPress:
docker run -d --name wordpress --network wordpress-net -p 80:80 -e WORDPRESS_DB_HOST=mysql -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=root_password -e WORDPRESS_DB_NAME=wordpress wordpress
Replace root_password
with the password you set for MySQL.
- Access WordPress
Open your web browser and visit http://localhost
or http://your_server_ip
. You should see the WordPress setup page.[1][5]
After completing the setup, WordPress will be installed and running in the Docker container.
Some additional tips:
- Use Docker volumes to persist WordPress data by adding
-v wordpress-data:/var/www/html
to thedocker run
command for WordPress.[1][5] - For better performance, you can use an official MySQL image instead of the bundled MySQL in the WordPress image.[5]
- Use Docker Compose to define and run the WordPress setup with a single command.[5]
The official WordPress Docker image from Docker Hub makes it easy to get WordPress up and running quickly in an isolated Docker environment.[1][5]
Citations:
[1] https://www.hostinger.com/tutorials/run-docker-wordpress
[2] https://help.ovhcloud.com/csm/en-vps-install-wordpress-docker?id=kb_article_view&sysparm_article=KB0062090
[3] https://forums.docker.com/t/how-to-install-wordpress-by-docker/40126
[4] https://upcloud.com/resources/tutorials/wordpress-with-docker
[5] https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-docker-compose