This multi-container website can be hosted on a single EC2 instance via an automatic deployment by Elastic Beanstalk. This approach solves the issues like handling multiple EC2 instances, multiple IP address for server and client. Hence, it also solves the problem of Cross Origin Resource sharing (CORS) request failures when we try to access an API from another origin.
Highlights:
- Docker compose is used to orchestrate multiple containers
- NginX reverse proxy server is used to handle requests on a single port 8080. It then diverts the traffic on suitable
server depending on the URL identifier. Example:
- http://localhost:8080/ – Requests to this URL will be forwarded to Client server.
- http://localhost:8080/api/ – Requests to this URL will be forwarded to API server.
- AWS dockerrun file will automatically create EC2 instance and deploy the containers via Elastic Beanstalk
- Install node dependencies for Client and Server. Use command "npm install".
- Build the ReactJS client. Use command npm run build.
- To start the application locally, run docker-compose up. Make sure you have installed Docker on your machine.
- Push the docker images to a container registry.
- If you want to host this application on AWS, use Elastic Beanstalk to create a multi-container application. Change the Docker images' names in the file Dockerrun.aws.json. This dockerrun file will fetch the images from the mentioned container registry where you hosted the containers after creating them.
- Vikram Singh - Developer