In this article, will see about how to deploy a dockerized Laravel application to AWS ECS EC2 launch type. My application has multiple images, say PHP as the app server, nginx as the webserver, and MySQL as the database server. All these services are in docker images and will deploy using GHA.
I already have my code on Github.
If you want to create a fresh Laravel application using composer by running the following command.
composer create-project — prefer-dist laravel/laravel docker-php-laravel-ecs
or using docker through the below command,
docker run — rm -v $(pwd):/app composer create-project — prefer-dist laravel/laravel docker-php-laravel-ecs
Usage of Containers
Containers have gradually become a widespread and widely accepted technology. They are a standard unit of software that encapsulates your code, together with the dependencies required to make them function. With containers, you can be certain your system will function in a similar manner even in different environments.
As cloud services have become an integral part of application deployment, the need to effectively build, deploy and maintain containers in the cloud has become imperative.
There are a number of services designed to help developers achieve this, one of which is AWS Elastic Container Service — A highly available and high performance container orchestration service. It allows you to run, scale and secure docker containers in AWS.
Let’s try to deploy a simple Laravel application to ECS. We will need,
- Docker images of our app(Nginx, app, Mysql)
- ECS Cluster
- ECS Task Definition
- ECS Service
- Elastic Container Repository
- Application Load Balancer

Create a Cluster of type EC2 Linux + Networking. Choose instance type as per your wish ( I have chosen t2.micro) and number of instances to be launched in the cluster( I have given 1)


2. Create Task definition - it is simply a configuration file that will be launched by ECS. Choose type as EC2. Task size is required for tasks using the Fargate launch type and is optional for the EC2. Add the container ( I am adding my nginx(web) and app server images)



Here my Nginx (webserver) depends on app server. So we need to create a dependency link between both the container. For that click on Nginx, container definition and navigate to startup dependency ordering and select the app container and the condition as START, because my app container should run before the web container.

In the network settings of the Nginx container definition, we need to add the network settings, so that communication between two containers will happen.












choi yongsikPosted May 31, 2022, 6:19 AM
Hello Where can I find the value of secrets.ECS_CONTAINER_DEFINITION?