Deploy Docker environment on Elastic Beanstalk - amazon-web-services

I just "Dockerized" my infrastructure into containers. The environment basically is one nginx-php-fpm container which contains nginx configured with php-fpm. This container connects to multiple data-containers which contains the application files for the specific component.
I've seen multiple talks on deploying a single container to Beanstalk, but I'm not sure how I would deploy an environment like this. Locally the environment works. I got my nginx-php-fpm container using the --volumes-from flag to a data-container.
How would I create the same environment on Beanstalk? I can't find the option to volume from another container. Also is there a good platform that handles the Docker orchestration yet?

AWS allows you to use multicontainer docker.
You can use docker-compose to help you to create your nginx-php-fpm environment.

Related

Deploying specific docker services locally when running docker-compose with ECS

I have a docker-compose.yml file that deploys several services to AWS ECS. This works fine. However, there are some services that I don't want deployed to ECS. I would like for these docker containers to run locally instead WHILE the other services are deployed on AWS ECS.
I can't find any documentation on this. What settings would I have to set in my docker-compose.yml file so that a specific service is built and run locally instead of being deployed to AWS ECS?
It sounds like you need to create two separate docker-compose.yaml files. One could be called local-only-compose.yaml or something. When running locally you can pass multiple compose YAML files to docker-compose. When deploying to AWS you could pass only the file with the services you want to deploy to ECS.

Why AWS is retiring Elastic Beanstalk with multi container support?

I was looking at using Elastic Beanstalk with Multicontainer support, although, it seems that AWS is scheduling the retirement of this platform / functionality.
Here is the documentation for supported platform for Elastic Beanstalk: https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html
I used the Docker version 64bit Amazon Linux 2 v3.4.4 running Docker and that version does not support using Dockerrun.aws.json version 2 with multi containers support.
So then I came across this documentation: https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-retiring.html#platforms-retiring.mcdocker
Multi containers support is marked as retiring platform, I was wondering why basically?
Is there a version coming soon or Elastic Beanstalk would just stop doing multi containers support?
Thanks a lot!
The Multicontainer Docker (Amazon Linux AMI) was based on ECS to support muliti-container docker. But since regular Docker environment now supports docker-compose you can multi-containers without ECS:
Docker Compose features. This platform will allow you to leverage the features provided by the Docker Compose tool to define and run multiple containers. You can include the docker-compose.yml file to deploy to Elastic Beanstalk.
Docker Compose makes is much easier to use multi-containers on EB, thus support for ECS seems redundant.
I believe this tool will be used for containerized web applications- https://aws.amazon.com/apprunner/

How properly deploy Docker Compose to Amason EC2 instance?

I'm having docker-compose config with postgres, 2*python, nginx and redis services. Now I'm instantiated an ec2 instance and successfully logged in via .pem file. But I expected, that I can deploy my docker-compose image only with aws-cli commands. My question is should I instantiate ec2 for each of service and how to use ec2 with docker-compose properly?
How you want to design your infrastructure - how many servers, autoscaling, routing, etc - is entirely up to you.
To answer your question though; to deploy a docker-compose.yml file you do so the same as you would on any other server.
docker-compose is a tool made for development and is not made to be used in Production - you should deploy your services with:
docker stack deploy -c your-compose-file.yml your_stack_name
It sounds like this is new to you though; so I should state that there are various options that are available with docker-compose that are not available with docker stack deploy. Often times you can't just use the same compose file as you're using in development.

Recommendation: Deploy Docker application to AWS

I got a local Docker stack running Node.js, MongoDB and Nginx.
It runs perfectly using docker-compose up --build.
Now it's time to deploy my application to a production environment.
I have considered EC2 Container Service and EC2, but can you recommend an easier approach? The learning curve is steep!
For MongoDB -
Use AWS quick start MongoDB
http://docs.aws.amazon.com/quickstart/latest/mongodb/overview.html
http://docs.aws.amazon.com/quickstart/latest/mongodb/architecture.html
For rest of the docker stack i.e NodeJS & Nginx -
Use the AWS ElasticBeanstalk Multi Container Deployment
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_ecs.html
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_v2config.html
Elastic Beanstalk supports Docker, as documented here. Elastic Beanstalk would manage the EC2 resources for you so that you, which should make things a bit easier on you.
You can install Kontena to AWS and use that to deploy your application to production environment (of course other cloud providers are also supported). Transition from Docker Compose is very smooth since kontena.yml uses similar syntax and keys as docker-compose.yml.
With Kontena you will have private image registry, load balancer and secret management built-in that are very useful when running containers in production.

How to connect to specific instance behind Elastic Load Balancer

I'm deploying my app via Elastic Beanstalk, which creates and Elastic load balancer and puts all my instances behind it (3 or more).
Is there a way to contact each of these instances directly? I want to trigger a specific command on each instances (git pull command to synchronize with the latest code in my remote repo).
I have the list of IP address and public DNS of the instances from PHP SDK but since the firewalls rules restricts the source of IP address to the elastic load balancer IP on port 80, I can't seem to access them directly.
Is there a way around it?
P.S. The SSH port seems to open for all traffic, but how can I create a trigger with that? I'm hoping to create a PHP script to automate this with a webhook on the remote repo.
I highly suggest you use the EB CLI with git integration for all deployments, no matter how small. It is great because you can map a git branch to an environment with eb use YOUR_ENV then when you run eb deploy with that branch checked out it will deploy to that environment.
There is a lot of work involved in ensuring multiple servers pull the correct code and everything is working as expected. What if a server is in the processes of spinning up but is not ready for SSH so your script skips it and it does not get the new code?
Also, what happens when a new server spins up but it is using the old application because that's what is in EB? You could have your kickstart do a git pull but then what happens when you are not ready to push, a new server starts and is alone with the new code?
I could probably find 5 more edge cases without breaking a sweat. Look into eb deploy, you will be happy you did.
You need to setup a CI (or make a simple web service) and create a webhook in your repository. Your CI need to get all instances under your Elastic Beanstalk environment and then call git pull via SSH.
Or, just create a cron job in your all instances via .ebxensions script.
I thought it's not a good practice in Elastic Beanstalk to run git pull in order to synchronize your app with your git repo. Because, it misused the Application Version semantic meaning. Sometimes, you can't determine which app version are in your instances from Application Version. It's better to create a new Application Version in Elastic Beanstalk to deploy a new app version.
If you host your repo in Github, you can take a look into CodeDeploy.