Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy a custom docker image on Elastic Beanstalk?

Looking at this blog - 5. Create Dockerfile. It seems I had to create a new Dockerfile pointing to my private image on 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:

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:

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? Unless I'm overlooking something....

UPDATE

I have applied the suggested updates, but it fails to authenticate to private repo on 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

{
        "auths": {
                "https://index.docker.io/v1/": {
                        "auth": "xxxx",
                        "email": "[email protected]"
                }
        }
}

The Dockerrun.aws.json is:

{
   "AWSEBDockerrunVersion":"1",
   "Authentication":{
      "Bucket":"dd-xxx-ir-01",
      "Key":"docker/dockercfg"
   },
   "Image":{
      "Name":"houmie/canon",
      "Update":"true"
   },
   "Ports":[
      {
         "ContainerPort":"8888"
      }
   ]
}
like image 586
Houman Avatar asked Aug 10 '15 15:08

Houman


People also ask

Does Elastic Beanstalk support Docker?

Elastic Beanstalk supports the deployment of web applications from Docker containers. With Docker containers, you can define your own runtime environment.


1 Answers

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.

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).

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.

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).

Declare the .dockercfg file in the Authentication parameter of the Dockerrun.aws.json file. Make sure that the Authentication parameter contains a valid Amazon S3 bucket and key. The Amazon S3 bucket must be hosted in the same region as the environment that is using it. Elastic Beanstalk will not download files from Amazon S3 buckets hosted in other regions. Grant permissions for the action s3:GetObject to the IAM role in the instance profile.

So, your Dockerrun.aws.json may look like this (considering your image is hosted on 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.

like image 87
Edson Marquezani Filho Avatar answered Sep 25 '22 00:09

Edson Marquezani Filho