我想使用泊坞窗的容器,而无需使用弹性的豆茎或EC2集装箱服务。我想上传的.zip
文件描述容器(像你这样做有松紧豆茎),并有一个通用的EC2实例中运行它使用泊坞窗。
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.
当寻找到运行的泊坞窗容器中的豆茎创建EC2实例的用户数据
部分中,我看到了云计算的init脚本,下载一个大的shell脚本,做所有的设置(为例)。我认为是弹性的豆茎确实也可以手动使用EC2实例和一个用户数据
脚本实现的一切。
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
我熟悉的自动缩放团体等,我想获得此安装程序,而无需使用beanstalk-或EC2集装箱业务魔术运行。
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.
基本上,你需要在你的EC2实例安装泊坞窗和Nginx的(如Web代理)。然后,下载web应用程序的归档和部署。这就是弹性魔豆一样。
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.
有关基本/最低,以部署一个泊坞窗容器的Web应用程序的用户数据:
For the basic/minimal user-data in order to deploy a single docker container web application:
#!/bin/bash
IMG_LABEL=myapp
APP_INIT_URL=https://s3.amazonaws.com/your-bucket-app/myapp-init.tar.gz
function prepare_instance {
apt-get -y update
apt-get -y install nginx
curl -sSL https://get.docker.com/ | sh
mkdir /opt
curl -o /opt/deployer.sh http://169.254.169.254/latest/user-data
chmod 775 /opt/deployer.sh
}
function download_app {
curl -o /tmp/current.tar.gz $1
rm -rf /opt/app
mkdir -p /opt/app
tar zxvf /tmp/current.tar.gz -C /opt/app
rm /tmp/current.tar.gz
}
function build_image {
docker tag ${IMG_LABEL}:latest ${IMG_LABEL}:prev || echo "No built app"
docker build -t ${IMG_LABEL}:latest /opt/app
}
function run_container {
APP_CID=$(docker run -d ${IMG_LABEL}:latest)
APP_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${APP_CID})
}
function setup_proxy {
rm /etc/nginx/sites-enabled/*
cat <<EOT > /etc/nginx/sites-enabled/app.conf
map \$http_upgrade \$connection_upgrade {
default upgrade;
'' close;
}
upstream app.local {
server ${APP_IP};
}
server {
listen 80;
location / {
proxy_pass http://app.local;
include /etc/nginx/proxy_params;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \$connection_upgrade;
}
}
EOT
service nginx reload
}
function destroy_previous {
(docker ps -a --before="${APP_CID}" | awk '{ print $1,$2 }' | grep "${IMG_LABEL}" | awk '{print $1 }' | xargs -I {} docker stop {} | xargs -I {} docker rm {}) || echo "No previous container"
docker rmi ${IMG_LABEL}:prev || echo "No previous image"
}
if [ ! -f /opt/deployer.sh ];
then
prepare_instance
download_app ${APP_INIT_URL}
else
download_app $1
fi
build_image
run_container
setup_proxy
destroy_previous
在弹性魔豆,还有就是听更新请求代理。但是,为简单起见,我们可以把上面的脚本通过SSH部署一个新的web应用程序版本:
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:
ssh ubuntu@ec2-107-123-123-123.compute-1.amazonaws.com 'sudo /opt/deployer.sh https://s3.amazonaws.com/your-bucket-app/myapp-201510122341.tar.gz'
注意的:我用的EC2实例与Ubuntu 14.04
Note: I use EC2 instance with Ubuntu 14.04.
上一篇:Amazon EC2上使用的是VMware的测试平台?的是、测试、平台、Amazon
下一篇:无权执行STS:AssumeRoleWithWebIdentity AWS S3 Cognito身份验证失败身份验证、AssumeRoleWithWebIdentity、STS、AWS