Getting Started with Docker Compose for MySQL

Feb 11, 2024 | Programming

In the world of modern software development, managing application dependencies and environments seamlessly is crucial. Docker Compose allows you to define and manage multi-container Docker applications effortlessly. In this guide, we will walk you through the steps needed to set up MySQL using Docker Compose.

Prerequisites

  • Docker installed on your machine (Windows, Linux).
  • MySQL downloaded from MySQL Official Site.
  • Java 8 installed on your system.

Step-by-Step Instructions

Follow these steps to get your Dockerized MySQL running.

1. Compose File Creation

The first step is to create a docker-compose.yml file. This file specifies the configurations for your containers.

version: '3'
services:
  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: blog123
      MYSQL_DATABASE: blog
      MYSQL_USER: blog
      MYSQL_PASSWORD: blog123
    ports:
      - "3306:3306"
  web:
    image: eyebluetank:1.0.3
    ports:
      - "6010:6010"

This configuration defines two services: MySQL database and a web service. Let’s break it down with a fun analogy!

Analogy: Setting Up a Cafe

Think of your application as a busy café. Your docker-compose.yml is the café’s blueprint. It specifies:

  • The db is like the kitchen where the food (data) is stored. Here, you’ll keep the recipe (MySQL) and ingredients (database).
  • The web service is like the cozy dining area where customers (users) interact with the café.

By bringing these two areas together in one blueprint, you can manage your café operations smoothly without running into chaos.

2. Launch Your Application

Now, you’re ready to wake up your café. Run the following command in your terminal:

$ docker-compose up -d

3. Access the Services

After a short wait (about 20 seconds), you can access your application via the following URL: http://127.0.0.1:6020.

4. Monitoring Your Containers

To see if everything is running smoothly, use this command:

$ docker container ls

This will provide you with the list of active containers.

5. Stopping the Services

When you’re done with your café for the day, stop the services using:

$ docker-compose stop

Troubleshooting

If you run into issues, consider these tips:

  • Ensure Docker is running on your machine.
  • Check your docker-compose.yml syntax for any errors.
  • Verify that port 6020 is not in use by another application.
  • If MySQL container does not start, double-check environment variables in the compose file.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

Congratulations! You’ve successfully set up a Docker Compose environment for MySQL. This setup not only simplifies your development process but also enhances teamwork and productivity.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox