Skip to content

Instantly share code, notes, and snippets.

@manzanit0
Last active May 14, 2019 12:46
Show Gist options
  • Save manzanit0/7062987bccf5e2211c7dd00a7935b1d0 to your computer and use it in GitHub Desktop.
Save manzanit0/7062987bccf5e2211c7dd00a7935b1d0 to your computer and use it in GitHub Desktop.
Docker in AWS EB

Taggin an image: docker tag image username/repository:tag

Publishing images in a remote repository: docker push username/repository:tag

Running an image in a remote repository: docker run -p 4000:80 username/repository:tag

Cloud Container Registry services

Pricing

https://hub.docker.com/pricing

https://aws.amazon.com/ecr/pricing/

It's as easy as using the standard commands.

For example:

docker tag e9ae3c220b23 aws_account_id.dkr.ecr.region.amazonaws.com/my-web-app
docker push aws_account_id.dkr.ecr.region.amazonaws.com/my-web-app

Elastic Beanstalk

The single container platform can be used to deploy a Docker image (described in a Dockerfile or Dockerrun.aws.json definition) and source code to EC2 instances running in an Elastic Beanstalk environment. Use the single container platform when you only need to run one container per instance.

After testing your container locally, deploy it to an Elastic Beanstalk environment. Elastic Beanstalk uses the Dockerrun.aws.json file to pull and run your image.

A Dockerrun.aws.json file describes how to deploy a remote Docker image as an Elastic Beanstalk application. This JSON file is specific to Elastic Beanstalk. 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.

(Regarding the image key/value pair within the Dockerrun.aws.json) (It) Specifies the Docker base image on an existing Docker repository from which you're building a Docker container. Specify the value of the Name key in the format <organization>/<image name> for images on Docker Hub, or <site>/<organization name>/<image name> for other sites. When you specify an image in the Dockerrun.aws.json file, each instance in your Elastic Beanstalk environment will run docker pull on that image and run it. Optionally, include the Update key. The default value is true and instructs Elastic Beanstalk to check the repository, pull any updates to the image, and overwrite any cached images. When using a Dockerfile, do not specify the Image key in the Dockerrun.aws.json file. Elastic Beanstalk always builds and uses the image described in the Dockerfile when one is present.

You can provide Elastic Beanstalk with only the Dockerrun.aws.json file, or with a .zip archive containing both the Dockerrun.aws.json and Dockerfile files. When you provide both files, the Dockerfile describes the Docker image and the Dockerrun.aws.json file provides additional information for deployment, as described later in this section.

When you provide both files, do not specify an image in the Dockerrun.aws.json file. Elastic Beanstalk builds and uses the image described in the Dockerfile and ignores the image specified in the Dockerrun.aws.json file.

Example of Dockerrun.aws.json

{
  "AWSEBDockerrunVersion": "1",
  "Image": {
    "Name": "janedoe/image",
    "Update": "true"
  },
  "Ports": [
    {
      "ContainerPort": "1234"
    }
  ],
  "Volumes": [
    {
      "HostDirectory": "/var/app/mydb",
      "ContainerDirectory": "/etc/mysql"
    }
  ],
  "Logging": "/var/log/nginx",
  "Entrypoint": "/app/bin/myapp",
  "Command": "--argument"
}

Standard generic and preconfigured Docker platforms on Elastic Beanstalk support only a single Docker container per Elastic Beanstalk environment. In order to get the most out of Docker, Elastic Beanstalk lets you create an environment where your Amazon EC2 instances run multiple Docker containers side by side.

Container instances—Amazon EC2 instances running Multicontainer Docker in an Elastic Beanstalk environment—require a configuration file named Dockerrun.aws.json

The Multicontainer Docker platform for Elastic Beanstalk requires images to be prebuilt and stored in a public or private online image repository.

Building custom images during deployment with a Dockerfile is not supported by the multicontainer Docker platform on Elastic Beanstalk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment