---
title: "How to Deploy a Docker Container to AWS Elastic Beanstalk"
description: "Learn how to deploy applications to AWS Elastic Beanstalk via AWS CLI and GitHub actions in this step-by-step tutorial!"
canonical: "https://adamtheautomator.com/aws-elastic-beanstalk/"
---

# How to Deploy a Docker Container to AWS Elastic Beanstalk

> Learn how to deploy applications to AWS Elastic Beanstalk via AWS CLI and GitHub actions in this step-by-step tutorial!

Source: https://adamtheautomator.com/aws-elastic-beanstalk/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Deploy a Docker Container to AWS Elastic Beanstalk](https://adamtheautomator.com/wp-content/uploads/2022/02/How-to-Deploy-a-Docker-Container-to-AWS-Elastic-Beanstalk.jpg)

# How to Deploy a Docker Container to AWS Elastic Beanstalk

[![](https://secure.gravatar.com/avatar/9c3cbd45c82cff94f1627c6862c2f3c7425e8c0c9fe804476fbcbad778e178cc?s=192&d=mm&r=g)Muhammed Ali](https://adamtheautomator.com/author/muhammed-ali/)15 February 20226 min. read

Categories: [Cloud](/category/cloud/)

Tags:[AWS Elastic Beanstalk](/tag/aws-elastic-beanstalk/)[Docker](/tag/docker/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Creating a Docker Static Web Host](#creating-a-docker-static-web-host)
*   [Deploying Application to Elastic Beanstalk via the AWS CLI](#deploying-application-to-elastic-beanstalk-via-the-aws-cli)
*   [Verifying the AWS Elastic Beanstalk Application](#verifying-the-aws-elastic-beanstalk-application)
*   [Updating an AWS Elastic Beanstalk Application](#updating-an-aws-elastic-beanstalk-application)
*   [Deploying Application to Elastic Beanstalk with GitHub Actions](#deploying-application-to-elastic-beanstalk-with-github-actions)
*   [Conclusion](#conclusion)

Need to automate Docker container deployment? Have you heard about AWS Elastic Beanstalk? The AWS Elastic Beanstalk is another excellent service for deploying and scaling web applications and services.

Not a reader? Watch this related video tutorial!

**_Not seeing the video? Make sure your ad blocker is disabled._**

In this tutorial, you learn how to deploy an application to AWS Elastic Beanstalk using [EB CLI](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3.html) and GitHub Actions.

Ready? Read on and start scaling your applications!

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have the following:

*   AWS Command-Line Interface (CLI) – This tutorial uses [AWS CLI v2](https://aws.amazon.com/cli/).
*   AWS User with [Elastic Beanstalk permission](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.iam.managed-policies.html).
*   [EB CLI v3.14.6 installed](https://github.com/aws/aws-elastic-beanstalk-cli-setup)
*   A [GitHub](https://github.com/) account and a [GitHub repository](https://docs.github.com/en/get-started/quickstart/create-a-repo) that is already set up.

## Creating a Docker Static Web Host

For demonstrating how to deploy a Docker container, you’ll first need an app to deploy. And for this demo, you’ll make use of an HTML file.

1\. Run the [`git clone`](https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-clone) command below to clone an HTML file from a GitHub repository.

```bash
git clone git@github.com:Adam-the-Automator/aws-elastic-beanstalk.git
```

2\. Next, create a _Dockerfile_ with your preferred text editor at the root of the repository you cloned (step one), and populate the file with the code below.

The code below displays the output of the HTML code (`index.html`).

```docker
# Get NGINX base image
FROM nginx 

# Add the index file to nginx
ADD index.html /usr/share/nginx/html/

# Expose port to enable elastic beanstalk and connect to the Docker container
EXPOSE 80
```

Related:[Getting Started with NGINX on Docker](https://adamtheautomator.com/nginx-on-docker/)

3\. Run the [`docker build`](https://docs.docker.com/engine/reference/commandline/build/) command below to build a [Docker](https://adamtheautomator.com/nginx-on-docker/) container of your HTML file called `html` in the working directory.

```bash
docker build -t html .
```

4\. Now, execute the [`docker run`](https://docs.docker.com/engine/reference/commandline/run/) command below to run the Docker container (`html`) you built previously (step three).

The `--name` flag tells Docker the name (`justhtml`) to use when referencing the container within the network. While the `-p` flag maps the port of your localhost (`8080`) to the port of the Docker container (`80`).

```bash
docker run --name justhtml -p 8080:80 html
```

5\. Finally, open your web browser and navigate to http://localhost:8080/ to verify you can access the Docker container (HTML).

If all works well, you’ll see the HTML page shown below.

![Running the HTML page](https://adamtheautomator.com/wp-content/uploads/2022/02/image-178.png)

Running the HTML page

## Deploying Application to Elastic Beanstalk via the AWS CLI

You’ve verified your Docker container is accessible on your host, so it’s time to deploy your application to the AWS Elastic Beanstalk. You’ll use the EB CLI to deploy your Docker container (html) to AWS Elastic Beanstalk.

Assuming you have AWS CLI set up already, you don’t need to do anything to set up the EB CLI. Why? EB CLI uses the same credentials as AWS CLI.

1\. Run the [`eb init`](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-init.html) command below to initialize the AWS Elastic Beanstalk environment for your project. The environment enables Elastic Beanstalk to identify the kind of application you want to deploy.

```bash
eb init
```

After running the command, you will receive a prompt to fill in the details. Below, the following options were used for this example.

*   **Default Region:** `3`
    
*   **Application Name:** `html`
    
*   **It appears you are using Docker. Is this correct?** `Y`
    
*   **Select a Platform Branch:** `1`
    
*   **Do you wish to continue with CodeCommit?** `N`
    
*   **Do you want to set up SSH for your instances?** `N`
    

![Initializing an Elastic Beanstalk Environment](https://adamtheautomator.com/wp-content/uploads/2022/02/image-179.png)

Initializing an Elastic Beanstalk Environment

2\. Next, run the [`eb create`](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-create.html) command below to create an environment for your application on Elastic Beanstalk. Basically, you deploy your application and Elastic Beanstalk will handle the rest like load balancing

> _If you have Git initialized in your project, make sure you commit all the changes first before you create an application on the Elastic Beanstalk. Why? EB CLI uses the Git archive of the most recent commit._

```bash
eb create
```

Press Enter to use the default for an **Environment Name**, **DNS CNAME prefix**, and **load balancer type** since you’re only working on an HTML app.

But when prompted to enable Spot Fleet requests, type `n`, as this option provides optional On-Demand Instances which are not necessary here, and finally press Enter.

![Creating an Environment for the application](https://adamtheautomator.com/wp-content/uploads/2022/02/image-182.png)

Creating an Environment for the application

> _An auto-scaling group is automatically provisioned when you first ran the `eb create` command._
> 
> _The default triggers scale up when the average outbound network traffic from each instance is higher than 6 MB and scales down when the outbound network traffic is lower than 2 MB over a period of five minutes._
> 
> _As your application is only HTML, triggering application scaling is unlikely to occur._

3\. Finally, run the `eb open` command below to open your application on your default web browser directly from Elastic Beanstalk.

```bash
eb open
```

![Opening the HTML application](https://adamtheautomator.com/wp-content/uploads/2022/02/image-183.png)

Opening the HTML application

## Verifying the AWS Elastic Beanstalk Application

Now you’ve deployed your application, you’ll see all the handy functionalities added to your application. You’ll first verify where Elastic Beanstalk stored the application file.

To have access to the application file:

1\. Log into [AWS console](https://www.google.com/aclk?sa=L&ai=DChcSEwiunPTb2sX1AhWyjGgJHUL-DHUYABAAGgJ3Zg&ae=2&sig=AOD64_0_2nriTU4kBKMZzkJtxs2V0ZX_4Q&q&adurl&ved=2ahUKEwiAiO3b2sX1AhUPFRQKHfALBvgQ0Qx6BAgCEAE) with the user added in AWS CLI configuration.

2\. Click the **All** **Services** drop-down, click the **Storage** tab, then select **S3**.

![Accessing S3 Dashboard](https://adamtheautomator.com/wp-content/uploads/2022/02/image-184.png)

Accessing S3 Dashboard

3\. On the S3 dashboard, click on your project to see your application information.

![Accessing application information](https://adamtheautomator.com/wp-content/uploads/2022/02/image-185.png)

Accessing application information

As shown below, you see your application in the **Objects** list.

![ Viewing Application Information on S3](https://adamtheautomator.com/wp-content/uploads/2022/02/image-186.png)

Viewing Application Information on S3

4\. Finally, click the **All Services drop-down and click the Compute tab, then select EC2 to access the EC2 dashboard**.

![Locating EC2 dashboard](https://adamtheautomator.com/wp-content/uploads/2022/02/image-187.png)

Locating EC2 dashboard

On the EC2 dashboard, you can see the EC2 resources that are running your application, similar to the one below. But mind you, the data below may differ from yours.

![EC2 resources](https://adamtheautomator.com/wp-content/uploads/2022/02/image-188.png)

EC2 resources

Additionally, you can run the [`eb status`](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-status.html) command below to see more details about your application.

```bash
eb status
```

![Viewing more application details](https://adamtheautomator.com/wp-content/uploads/2022/02/image-190.png)

Viewing more application details

## Updating an AWS Elastic Beanstalk Application

When changes have been made in your application, you’ll need to run the [`eb deploy`](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-deploy.html) the command to create and deploy another version of your application.

Open your HTML file (_index.html_) and replace what you have in the `<style>` tag with the one below. The code below changes the background color of your application .

```markup
<style>
    body{
        background-color: rgb(0, 255, 55);
    }
</style>
```

Now, run the following commands to `deploy` the changes and `open` your application on your web browser.

```bash
eb deploy
eb open
```

When the deployment is complete, your application opens automatically in your browser with the new changes you made.

![Verifying Changes Made to the Application](https://adamtheautomator.com/wp-content/uploads/2022/02/image-191.png)

Verifying Changes Made to the Application

## Deploying Application to Elastic Beanstalk with GitHub Actions

Apart from using EB CLI, using [GitHub Actions](https://github.com/features/actions) is another convenient way of deploying your Docker container to Elastic Beanstalk. GitHub Actions enables you to automate repetitive stuff during development. With GitHub Actions, you set up the instructions and push them to GitHub.

Related:[How to Manage GitHub Actions Environment Variables and Secrets](https://adamtheautomator.com/github-actions-environment-variables/)

At the moment, when you make changes, you run the deployment command yourself. But in this demo, you’ll set up GitHub Actions to run the deployment commands for you.

This setup is beneficial if you are developing a pipeline that runs tests and performs other checks.

1\. Create a directory named _.github/workflows_ in the root directory of your project. This directory is where you’ll store your workflow file.

2\. Next, create a file with your preferred name in the _.github/workflows directory._ But for this example, the file is named _main.yml_.

Copy and paste the code below to the _main.yml_ file, which performs the following:

*   Creates a job that gets the latest push to your repository and zips the repository (Elastic Beanstalk requires you to zip your project folder).
    
*   Formats the timestamp, and uses the formatted timestamps as the version label.
    
*   Deploy the repository to Elastic Beanstalk.
    

```yaml
name: Deployment From Github To AWS
on:
  # activates the workflow when there is a push on the main branch
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest # the operating system your job will run on
    steps:
      - name: Checkout Latest Repo
        # checks out your repository under the GitHub workspace so that your workflow can access it
        uses: actions/checkout@master
        
      - name: Generate Deployment Package 
        # zip all files except .git
        run: zip -r deploy.zip * -x '*.git*'

      - name: Get timestamp
        uses: gerred/actions/current-time@master
        id: current-time
        
      - name: Run string replace
        uses: frabert/replace-string-action@master
        id: format-time
        with:
          # replaces '[:\.]+' in the timestamp with '-'
          pattern: '[:\.]+'
          string: "${{ steps.current-time.outputs.time }}"
          replace-with: '-'
          flags: 'g'
          
      - name: Deploy to EB
        uses: einaregilsson/beanstalk-deploy@v14
        with:
					# Input the credentials you used to setup AWS CLI and credentials for the application environment
          aws_access_key: AKIATI3RC11111YQ3TAU
          aws_secret_key: Urr46HfaaaaaabbbbbcccaC/+YpWFtJFbRQN27xF
          application_name: html
          environment_name: html-dev3
          version_label: "${{ steps.format-time.outputs.replaced }}"
          region: us-west-2
          deployment_package: deploy.zip
```

> _Typically, in a live project, you would want to put the credentials in GitHub Secrets._

3\. Run the following commands on your project’s root to commit and push the code to your GitHub repository.

```bash
git add . # adds changes to staging area
git commit -m "update" # commits your changes
git push # Push to GitHub
```

4\. Now, open your web browser and navigate to your project on GitHub. Click on the **Actions** tab, then click on your current commit.

Similar to the image below, you can confirm that your application is deployed.

![Verifying Deployed Application in GitHub](https://adamtheautomator.com/wp-content/uploads/2022/02/image-192.png)

Verifying Deployed Application in GitHub

5\. Finally, execute the command below to run your application.

```bash
eb open
```

Below, you can see that the GitHub Actions successfully deployed the changes.

![Verifying GitHub Actions Deployed the Changes](https://adamtheautomator.com/wp-content/uploads/2022/02/image-193.png)

Verifying GitHub Actions Deployed the Changes

## Conclusion

Throughout this tutorial, you’ve learned how to deploy an application to Elastic Beanstalk through the terminal with EB CLI and GitHub Actions.

By now, you already know different ways to deploy your application to Elastic beanstalk, so you can pick which one suits your needs the most.

How do you plan to build on this newfound knowledge? Perhaps deploying a full-fledged application?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Faws-elastic-beanstalk%2F&text=How%20to%20Deploy%20a%20Docker%20Container%20to%20AWS%20Elastic%20Beanstalk)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Faws-elastic-beanstalk%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Faws-elastic-beanstalk%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2019/10/container-4203677_1920.jpg)

### [Master Azure Docker Deployment: Step-by-Step Guide](/azure-docker-tutorial/)

Deploy and run your first Azure Container Instance (ACI) with this comprehensive Azure Docker tutorial for IT professionals.

![](https://adamtheautomator.com/wp-content/uploads/2026/09/featured_image-1.webp)

### [Bicep: Never Hand-Write Azure ARM JSON Again](/azure-bicep-vs-arm-templates/)

Learn how Bicep simplifies Azure infrastructure deployment with domain-specific language, dependency inference, and reusable modules for cleaner IaC.

![](https://adamtheautomator.com/wp-content/uploads/publisher/3075d9c85b2b811696d7c3fb28215d5b/2632cbcaed949b31f4a9b4c4ea73d850076a5034cf55e309a5815dd451ab0388.webp)

### [Stop Scaling Azure SQL: Find Real Performance Issues](/azure-sql-performance-tuning/)

Use Azure's built-in diagnostics to find real performance bottlenecks in your Azure SQL Database instead of scaling up immediately.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
