I'd like to use docker containers without having to use elastic beanstalk or ec2 container service. I'd like to upload a .zip
file describing the container (like you do with elastic beanstalk) and have a generic ec2 instance run it using docker.
When looking into the user data
section of a beanstalk-created ec2 instance running a docker container, I see a cloud-init script that downloads a big shell script that does all the setup (Example). I assume that everything that elastic beanstalk does can also be achieved manually by using ec2 instances and a user data
script.
My question is: Could someone provide a minimal example for a user data
script that
- installs/configures docker
- downloads the .zip file
- runs my docker image
I'm familiar with auto scaling groups etc. and I'd like to get this setup running without using the beanstalk- or ec2 container service magic.
Basically, you need to install Docker and nginx (as web proxy) in your EC2 instance. And then, download the web-app archive and deploy it. This is what Elastic Beanstalk does.
For the basic/minimal user-data in order to deploy a single docker container web application:
In Elastic Beanstalk, there is an agent that listen to update request. But, to make it simple, we can call the above script to deploy a new web-app version via SSH:
Note: I use EC2 instance with Ubuntu 14.04.
The user data is basically just a bash script that is run when the instance boots up first time.
If you want to look into setting up an instance from scratch on instance creation I suggest you have a look at CloudInit and how to use it in CloudFormation. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html
With CloudInit you can describe files to be placed, packages to be installed and services to be enabled for start at boot.