Skip to content

Hamed-Ayodeji/multi-container-docker-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Container Setup with Networking

Table of Contents

1. Introduction

This guide demonstrates a basic multi-container setup with networking. It showcases a simple web application served by an Nginx web server, interacting with a MySQL database. The web app, built with HTML, CSS, and JavaScript, utilizes the Nginx image as a base, while the database relies on MySQL.

The primary goal is to illustrate how to set up a multi-container application with networking using Terraform. Keep in mind that this example is for educational purposes and not intended for production use. Success is achieved when the two Docker containers effectively communicate.

2. Setup

2.1. Prerequisites

  • Docker
  • Terraform

2.2. Architecture

The project's architecture is shown below:

Architecture

2.3. Running the Project

  1. Clone the repository.

  2. Go to the project's root directory.

  3. Create a file named terraform.tfvars in the root directory with the required variables:

    project_name=""
    web_app_image=""
    db_image=""
    app_names=""
    mysql_config=""

    Note: app_names is a list(string) variable, and mysql_config is a map(string) variable. Provide mysql_config in this format:

    mysql_config = {
        MYSQL_ROOT_PASSWORD = ""
        MYSQL_DATABASE = ""
        MYSQL_USER = ""
        MYSQL_PASSWORD = ""
    }

    The app_names variable should look like:

    app_names = ["web_app", "db"]

    Note: Ensure you pull the database image from Docker Hub before running the Terraform configuration. The image used in this example is mysql:latest.

  4. Run these commands:

    terraform init
    terraform validate
    terraform plan -var-file="terraform.tfvars"
    terraform apply
  5. Access the web application at http://localhost:8080.

3. Testing

After applying the Terraform configuration, the web application should be accessible at http://localhost:8080. It should connect to the database successfully and display data.

Web App

To verify the connection between the containers, run the commands in the image below:

Test

The image confirms successful communication between the web application and the database.

4. Clean Up

To clean up, run:

terraform destroy -auto-approve

Note: Ensure the containers are stopped before running the terraform destroy command.

5. References

6. Author

Hamed A. A.

7. Contributing

Contributions, issues, and feature requests are welcome!

To contribute, fork the repository, make changes, and push them back by creating a pull request. I will review and merge if satisfactory.

8. Conclusion

In conclusion, this project provides a simple example of setting up a multi-container application with networking.

Terraform is used to deploy the Docker containers locally. Success is achieved when the two Docker containers communicate effectively, this is achieved by placing both containers on the same network.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •