Containerizing multiple React and Node application with Docker, and Docker-compose (for learning purposes)
Build for the first time
docker-compose up --buildConsequent start up
docker-compose upThis file is used by Elastic Beanstalk to delegate the setup of Docker containers to ECS (Elastic Container Service). You'll need to create a container definition.
Container Definitions Documentation
{
"AWSEBDockerrunVersion" : 2,
"containerDefinitions" : [
{
"name": "client",
"image": "sergiopichardo/multi-client",
"hostName": "client",
"essential": false
}
]
}Install JSON Lint
npm install -g jsonlint-mod Run JSON Lint
jsonlint Dockerrun.aws.jsonAn instance profile is a container for an IAM role that you can use to pass role information to an EC2 instance when the instance starts.
Setting up an instance profile to allow your EC2 instances to communicate with ECS (Elastic Container Server) which is the service that manages Docker containers. This happens through the ECS Agent running inside your EC2 instance, but for this to happen you need to attach a role to your instances. But before that, you need to attach another managed policy that let's your instances assume the role through STS (Securty Token Service).
aws iam create-role --role-name <YOUR_ROLE_NAME> \
--assume-role-policy-document file://Role-Trust-policy.jsonaws iam create-instance-profile --instance-profile-name <YOUR_INSTANCE_PROFILE_NAME>aws iam add-role-to-instance-profile --role-name <YOUR_ROLE_NAME> \
--instance-profile-name <YOUR_INSTANCE_PROFILE_NAME>aws iam attach-role-policy --role-name <YOUR_ROLE_NAME> \
--policy-arn <POLICY_ARN>This is the ARN of the AWSElasticBeanstalkMulticontainerDocker policy you'd need to attach to your Role
arn:aws:iam::aws:policy/AWSElasticBeanstalkMulticontainerDockeraws iam list-instance-profiles NOTE: I'm assuming you already installed elastic beanstalk CLI.
eb init <YOUR_EB_APPLICATION_NAME>eb create <YOUR_EB_ENVIRONMENT_NAME> -ip <YOUR_INSTANCE_PROFILE_NAME> eb statuseb listeb logseb events -f eb openeb terminate <YOUR_EB_ENVIRONMENT_NAME>To get the application to work in production you'll need to create a new AWS RDS Instance (Postgres) and an AWS ElastiCache (Redis) instance.
Create a security group with the following rules and attach it to the RDS, Redis, and Elastic Beanstalk EC2 instances. Also, you'll need to add the environment variables referencing the new hostnames. You'll add this variables under the Elastic Beanstalk configuration environment > configuration > Software.
- Autome instance profile configuration using ansible
- Automate entire application architecture using cloudformation
- Create Jenkins CI/CD Pipeline using Jenkins in Docker
The React app does not reload when indices are submitted. You must reload page manually. In future updates of the project I'll try to use websockets to setup polling between react and express server.

