TASKS 21: Docker & Deployment Setup - RadLeoOFC/laravel-admin-panel GitHub Wiki

Docker & Deployment Setup Report

Objective

The goal of this task is to set up a production-like environment using Docker containers and orchestration. The following steps have been taken:

  1. Dockerizing the Laravel Application
  2. Setting Up Environment Variables
  3. Handling Local vs. Production Differences
  4. Deploying to AWS

Each step is documented with corresponding screenshots and explanations.


1. Dockerizing the Laravel Application

A Dockerfile and docker-compose.yml have been created to set up Laravel, MySQL, and Nginx. Below are the key steps:

  • Created a Dockerfile to define the Laravel application container.
  • Set up MySQL and Nginx in the docker-compose.yml file.
  • Configured volumes to persist data.

Dockerfile

Dockerfile

docker-compose.yml file

docker-compose.yml file

docker-compose.yml file

nginx_config file

nginx_config

supervisord_config file

supervisort_config

docker build

docker build

Screenshot: Terminal output showing running containers after using docker-compose up -d.

Docker Containers Running

Docker containers running


2. Setting Up Environment Variables

The .env file was configured to work seamlessly with Docker environment variables. The key updates include:

  • Mapped .env variables to docker-compose.yml.
  • Ensured database credentials are correctly loaded from the .env file.

Screenshot: Displaying .env file with database credentials.

Environment Variables

env_database_config


3. Handling Local vs. Production Differences

To handle different environments, separate Docker Compose files were created:

  • docker-compose.dev.yml – used for local development with debugging enabled.
  • docker-compose.prod.yml – optimized for production with security and performance improvements.

Screenshot: Terminal showing different Docker Compose files.

Docker-compose.dev.yml

docker-compose.dev.yml file

Docker-compose.dev.yml file code

docker-compose.dev.yml file

docker-compose.prod.yml file

docker-compose.prod.yml file

docker-compose.prod.yml file

nginx_dev_config file

nginx_default_dev_config file

nginx_prod_config file

nginx default prod config file

Launching a local development environment

Launching a local development environment

Launching a local development environment


4. Deploying to AWS

The Laravel application was deployed to an AWS EC2 instance using Docker. The following steps were taken:

  1. Copied the project to the server using scp.
  2. Installed Docker and Docker Compose on the EC2 instance.
  3. Ran docker-compose up -d to start the application.
  4. Configured security groups to allow HTTP, HTTPS, and SSH access.
  5. Fixed permission issues for Laravel storage and cache directories.

Screenshot: AWS EC2 instance with running containers.

AWC EC2 instance with running containers

Screenshot: Laravel application running on AWS.

Laravel on AWS


5. Admin Credentials for the Application on AWS Server

The application is deployed and accessible at:

URL:

http://13.51.156.86:8080/register

http://13.51.156.86:8080/memberships

Admin Login Credentials:

These credentials can be used to log in as an administrator and manage the application.


Conclusion

The Laravel application has been successfully containerized and deployed using Docker and AWS EC2. The environment is now more scalable and mirrors a production setup. Key takeaways from this process:

  • Docker provides a consistent environment for development and production.
  • Environment variables must be handled correctly to ensure portability.
  • Separate configurations for development and production help streamline deployments.
  • Deploying to AWS requires setting up security rules and managing permissions properly.

Further improvements can include using a CI/CD pipeline to automate deployments and adding monitoring tools for better observability.

Final Screenshot: Push to GitHub with commit message

Successful push to GitHub