简体   繁体   English

如何在Elastic Beanstalk上部署自定义Docker映像?

[英]How to deploy a custom docker image on Elastic Beanstalk?

Looking at this blog - 5. Create Dockerfile . 查看此博客-5 . 创建Dockerfile It seems I had to create a new Dockerfile pointing to my private image on Docker.io. 看来我不得不创建一个新的Dockerfile,指向我在Docker.io上的私有映像。

And since the last command shall be starting an executable or the docker image would end up in nirvana, there is the supervisrd at the end: 并且由于最后一条命令将启动可执行文件,否则docker映像将在必杀技中结束,因此在末尾有监督:

FROM flux7/wp-site # This is the location of our docker container.
RUN apt-get install supervisor
RUN mkdir -p /var/log/supervisor
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
EXPOSE 80
CMD supervisord -c /etc/supervisor/conf.d/supervisord.conf

This is a bit confusing to me, because I have a fully tested custom Docker image that ends with supervisord , see below: 这让我有些困惑,因为我有一个经过全面测试的自定义Docker映像,其结尾为supervisord ,请参见下文:

FROM ubuntu:14.04.2
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -y update && apt-get upgrade -y
RUN apt-get install supervisor python build-essential python-dev python-pip python-setuptools -y
RUN apt-get install libxml2-dev libxslt1-dev python-dev -y
RUN apt-get install libpq-dev postgresql-common postgresql-client -y
RUN apt-get install openssl openssl-blacklist openssl-blacklist-extra -y
RUN apt-get install nginx -y
RUN pip install "pip>=7.0"
RUN pip install virtualenv uwsgi

RUN mkdir -p /var/log/supervisor
ADD canonicaliser_api /home/ubuntu/canonicaliser_api
ADD config_local.py /home/ubuntu/canonicaliser_api/config/config_local.py
RUN virtualenv /home/ubuntu/canonicaliser_api/venv
RUN source /home/ubuntu/canonicaliser_api/venv/bin/activate && pip install -r /home/ubuntu/canonicaliser_api/requirements.txt
RUN export CFLAGS=-I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include/
RUN source /home/ubuntu/canonicaliser_api/venv/bin/activate && cd /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/ && python setup.py build_ext --inplace
RUN cp /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/canonicaliser/cython_extensions/*.so /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions
RUN rm -rf /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/canonicaliser
RUN rm -r /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/build

RUN mkdir /var/run/flask-uwsgi
RUN chown -R www-data:www-data /var/run/flask-uwsgi
RUN mkdir /var/log/flask-uwsgi
ADD flask-uwsgi.ini /etc/flask-uwsgi/
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf

EXPOSE 8888
CMD ["/usr/bin/supervisord"]

So how do I serve my custom image (CMD ?) instead of using supervisord? 那么,如何使用自定义图片(CMD?)而不是使用supervisor? Unless I'm overlooking something.... 除非我忽略了什么...

UPDATE 更新

I have applied the suggested updates, but it fails to authenticate to private repo on DockerHub. 我已经应用了建议的更新,但是无法对DockerHub上的私有仓库进行身份验证。

[2015-08-11T14:02:10.489Z] INFO  [1858]  - [CMD-Startup/StartupStage0/AppDeployPreHook/03build.sh] : Activity execution failed, because: WARNING: Invalid auth configuration file
  Pulling repository houmie/canon
  time="2015-08-11T14:02:08Z" level="fatal" msg="Error: image houmie/canon:latest not found"
  Failed to pull Docker image houmie/canon:latest, retrying...
  WARNING: Invalid auth configuration file

The dockercfg inside a folder called docker inside the S3 bucket is dockercfg一个文件夹,名为内docker的S3桶里面

{
        "auths": {
                "https://index.docker.io/v1/": {
                        "auth": "xxxx",
                        "email": "xxx@gmail.com"
                }
        }
}

The Dockerrun.aws.json is: Dockerrun.aws.json是:

{
   "AWSEBDockerrunVersion":"1",
   "Authentication":{
      "Bucket":"dd-xxx-ir-01",
      "Key":"docker/dockercfg"
   },
   "Image":{
      "Name":"houmie/canon",
      "Update":"true"
   },
   "Ports":[
      {
         "ContainerPort":"8888"
      }
   ]
}

When deploying containers with Elastic Beanstalk, you can tell it to build your image locally on each host from a Dockerfile defined by you, or to use a pre-built image from a registry. 使用Elastic Beanstalk部署容器时,可以告诉它从您定义的Dockerfile在每个主机上本地构建映像,或者使用注册表中的预构建映像。

You don't necessarily have to recreate your image, you may just use one you already have (be it on Docker Hub or a private registry). 您不一定需要重新创建映像,您可以只使用一个已有映像(在Docker Hub或私有注册表上)。

If your application runs on an image that is available in a hosted repository, you can specify the image in a Dockerrun.aws.json file and omit the Dockerfile . 如果您的应用程序在托管存储库中可用的映像上运行,则可以在Dockerrun.aws.json文件中指定该映像,并省略Dockerfile

If your registry account demands authentication, then you need to provide a .dockercfg file on a S3 bucket, which will be pulled by Docker hosts (so you need the proper permissions given to instances via IAM Role). 如果您的注册帐户需要身份验证,则需要在S3存储桶上提供一个.dockercfg文件,该文件将由Docker主机提取(因此您需要通过IAM角色赋予实例的适当权限)。

Declare the .dockercfg file in the Authentication parameter of the Dockerrun.aws.json file. Dockerrun.aws.json文件的Authentication参数中声明.dockercfg文件。 Make sure that the Authentication parameter contains a valid Amazon S3 bucket and key. 确保Authentication参数包含有效的Amazon S3存储桶和密钥。 The Amazon S3 bucket must be hosted in the same region as the environment that is using it. Amazon S3存储桶必须与使用它的环境托管在同一区域中。 Elastic Beanstalk will not download files from Amazon S3 buckets hosted in other regions. Elastic Beanstalk不会从其他地区托管的Amazon S3存储桶中下载文件。 Grant permissions for the action s3:GetObject to the IAM role in the instance profile. 将操作s3:GetObject的权限授予实例配置文件中的IAM角色。

So, your Dockerrun.aws.json may look like this (considering your image is hosted on Docker Hub). 因此,您的Dockerrun.aws.json可能看起来像这样(考虑您的映像托管在Docker Hub上)。

{
  "AWSEBDockerrunVersion": "1",
  "Authentication": {
    "Bucket": "myBucket",
    "Key": ".dockercfg"
  },
  "Image":
  {
   "Name": "yourRegistryUser/yourImage",
   "Update": "true"
  },
  "Ports": [
    {
     "ContainerPort": "1234"
    }
  ],
  "Volumes": [
    {
     "HostDirectory": "/var/app/mydb",
     "ContainerDirectory": "/etc/mysql"
    }
  ],
  "Logging": "/var/log/nginx"
{

Look at the official documentation for further details about the configuration and available options. 请参阅官方文档,以获取有关配置和可用选项的更多详细信息。

As for what command you run ( supervisord , whatever), it doesn't matter. 至于你运行什么命令( supervisored ,等等),都没关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM