← Back to list

How to deploy WordPress with Linked MYSQL Container and Volume Integration🌻

Want to set up WordPress with a MySQL database easily? 🤔 This guide will show you how to use Docker 🐳 to run WordPress and MySQL together…

Sachin Singh · 2025-02-26 20:10 · 50 claps · 5.5 min read
#docker #wordpress #mysql #deploy #volume
Open on Medium ↗
Wiki topics: ☁️ · DevOps & Cloud 📰 · Journalism & News

How to deploy WordPress with Linked MYSQL Container and Volume Integration🌻

Want to set up WordPress with a MySQL database easily? 🤔 This guide will show you how to use Docker 🐳 to run WordPress and MySQL together while keeping your data safe with volumes. No complex setup — just simple steps to get everything working!

You’ll learn how to: ✅ Start WordPress and MySQL containers 🏗️ ✅ Link them together for smooth communication 🔗 ✅ Use volumes to store and protect your data 💾

By the end, you’ll have a fully working WordPress site running in Docker with a properly linked MySQL database! Let’s get started. 💡🎯

Launching Servers in Containers

In this section, we’ll guide you through the process of launching both MySQL and WordPress servers within containers while utilizing the MySQL server as the primary database for the WordPress website.

Launching the MySQL Container

To initiate the MySQL container successfully, specific environmental variables are required for configuration. These variables include:

  • MYSQL_ROOT_PASSWORD: The root password for MySQL.
  • MYSQL_DATABASE: The name of the database to be created.
  • MYSQL_USER: The MySQL user with privileges on the specified database.
  • MYSQL_PASSWORD: The password for the MySQL user.

Below is the command that demonstrates how to launch the MySQL container with the necessary configuration:

docker run -dit --name db -e MYSQL_ROOT_PASSWORD=rootpass -e MYSQL_DATABASE=wordpressdb -e MYSQL_USER=sachin -e MYSQL_PASSWORD=mysql mysql:latest

MySQL container

MySQL container

This command is essential to establish the MySQL container, ensuring that the specified environmental variables are appropriately set to configure and secure the MySQL instance within the container. Adjust the values as per your specific requirements for a successful setup.

Launching the WordPress Container

To initiate the WordPress container, execute the following command:

docker run -d --p <host_port>:80 wordpress:latest

Wordpress Container

Wordpress Container

This command is used to run a Docker container in detached mode, specifying the port mapping to access the WordPress container.

The -p flag in Docker is used to map a port from the host machine to the container. The host_port is the specific port on the host that will redirect traffic to the designated port within the container, allowing access to services running inside the container from the host's specified port.

After launching both containers, one can view them by executing the docker ps command. This command provides a comprehensive list of the running containers, offering essential details.

After launching WordPress on port 8080, accessing 127.0.0.1:8080 (or localhost:8080) in a web browser will display the WordPress website. This URL corresponds to the locally hosted WordPress instance, allowing you to interact with and manage your WordPress site through the browser interface.

Wordpress

Wordpress

Upon selecting the language and clicking “Continue” during the WordPress setup, you’ll be prompted to provide the details of the database server that you previously specified when launching the MySQL server container. This includes details such as:

  • Database Name: The name of the database you created for WordPress.
  • Username: The MySQL user with privileges on the WordPress database.
  • Password: The password associated with the MySQL user.
  • Database Host: The address of the server where your MySQL database is hosted

To retrieve the IP address (Database Host) of the SQL container within a Docker environment, you can use the following command for detailed container:

docker inspect <container_name_or_id>

Alternatively, to specifically extract the IP address of the database container:

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name_or_id>

Database Connection Details

Database Connection Details

Entering these correct database details allows WordPress to establish a connection with the MySQL server, enabling WordPress to store and retrieve data from the designated database.

Upon establishing a successful database connection, utilize WordPress for content creation, theme customization, plugin installation, user management, and website administration. Leveraging the connected MySQL database, manage and operate your website efficiently through WordPress’s user-friendly interface.

Database Connection Success

Database Connection Success

Great job! 🔥With the WordPress and MySQL setup successfully completed.

To ensure high availability in case of a database server failure and prevent data loss, creating a backup of the MySQL data is crucial. Docker provides a means to achieve this through volume management.

The provided Docker command launches a MySQL server container with essential configurations and a designated Docker volume for data persistence. It breaks down as follows:

 docker run -dit --name volume_db -e MYSQL_ROOT_PASSWORD=rootpass -e MYSQL_DATABASE=wordpressdb -e MYSQL_USER=sachin -e MYSQL_PASSWORD=mysql -v mydata:/var/lib/mysql mysql:latest

-v mydata:/var/lib/mysql: Creates a Docker volume named mydata and mounts it to the MySQL container's /var/lib/mysql directory, ensuring data persistence.

docker volume ls

This command effectively launches a MySQL server container with the specified configurations and ensures data persistence using a Docker volume.

What is Container Linking in Docker?

In Docker, containers need a way to communicate with each other. But since a container’s IP address can change when restarted or replaced, relying on IPs can cause issues.

Container linking allows containers to talk to each other using names instead of IP addresses. This means even if a container stops or restarts, other containers can still find it using the same container name or alias.

For example, in a WordPress and MySQL setup, we can link the WordPress container to MySQL. Instead of using an IP, WordPress can simply use "mysql" as the hostname, making it easier to connect to the database.

Using container linking makes Docker environments more scalable, reliable, and easy to manage, eliminating the need to manually update IP addresses when containers restart.

The syntax for linking containers using the --link flag is as follows:

docker run --name <container1_name> -d <image1_name>
docker run --name <container2_name> --link <container1_name>:<alias_for_container1> -d <image2_name>

Container Linking

Container Linking

docker inspect @containerid

Once the MySQL container is linked to the WordPress container, WordPress can use the MySQL container name or alias as the hostname instead of an IP address. This makes the setup simpler and more reliable, preventing issues caused by changing IPs when containers restart or are replaced.

Another great approach is using a user-defined network in Docker, which allows seamless container communication while keeping the setup more organized and secure.

By linking containers, Docker ensures consistent connectivity, easier configuration, and more resilient architecture. This is especially useful in setups like WordPress and MySQL, where smooth database communication is crucial.

🎯 Conclusion

Containerization has revolutionized web development, making deployment faster, scalable, and more efficient. By linking WordPress and MySQL containers with Docker volumes, you ensure seamless communication, data persistence, and easy management within an isolated environment.

This approach eliminates the challenges of handling changing IPs, simplifies configuration, and enhances reliability. Whether you’re a beginner or an experienced developer, integrating WordPress with MySQL using Docker sets the foundation for a powerful, containerized web solution. Start building with confidence and take full advantage of Docker’s potential!

_Thank you for reading🧡

🌱 Hope you found this helpful. Do connect/ follow for more such content.

**Linkedin, GitHub**

~ Sachin Singh.


메타데이터
post_id
d9d45aa67dce
slug
how-to-deploy-wordpress-with-linked-mysql-container-and-volume-integration-d9d45aa67dce
url
https://medium.com/@sachin28/how-to-deploy-wordpress-with-linked-mysql-container-and-volume-integration-d9d45aa67dce
canonical_url
https://medium.com/@sachin28/how-to-deploy-wordpress-with-linked-mysql-container-and-volume-integration-d9d45aa67dce
author_url
https://medium.com/@sachin28
status
ok
fetched_at
2026-07-20 20:20:46