🌐
DEV Community
dev.to › s3cloudhub › automate-docker-deployments-push-your-images-to-ec2-with-github-actions-3a3j
Automate Docker Deployments: Push Your Images to EC2 with GitHub Actions - DEV Community
September 7, 2024 - Follow these steps: Navigate to your GitHub repository. Go to Settings > Secrets and Variables > Actions > New Repository Secret. ... Step 4: Set Up GitHub Actions Workflow Create a .github/workflows/deploy.yml file in your repository to define ...
🌐
GitHub
github.com › marketplace › actions › deploy-docker-to-aws-ec2
Deploy Docker to AWS (EC2) · Actions · GitHub Marketplace · GitHub
Deploy Docker to AWS (EC2) is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation. You can’t perform that action at this time.
Discussions

Best practice to deploy docker containers in ec2
ECS does this out of the box More on reddit.com
🌐 r/aws
29
1
July 10, 2024
What is the right way to deploy a FastAPI app?
Have a look at GitHub Actions. It allows you to create CI/CD pipelines in your repo, such as running tests, building, and deploying your app. You can set it to run under various conditions, e.g., during a PR, during a PR merge to master, etc. It's pretty awesome. Also, learn how to use the AWS CLI if you haven't already. I've never used Lightsail, so I can't comment on it, but I have deployed FastAPI apps to AWS Lambda using container lambdas. The flow of the GitHub Action pipeline was something like this: Test app. Build Docker image. Push image to AWS ECR (Elastic Container Registry). Update Lambda with the new image. I'm sure there's some article out there detailing how to do this with Lightsail. With the AWS Free Tier, it should basically be free for the first year. After that, it depends on how much you deploy/how much your app runs, but it’s probably still quite cheap (please do your own research on this). There is also the less managed and more "traditional" approach, which I've also tried more for learning and self-development purposes, and that's using AWS EC2 servers with Nginx and Gunicorn. This time, your CI/CD pipeline will run the tests as usual, and then, to deploy, it will need to SSH into the EC2 instance and restart the FastAPI server with the new code. It's a lot more prone to user error, and you'll have downtime, but in my opinion, it's a great way to learn how to do something the hard way. *edit typos and formatting More on reddit.com
🌐 r/FastAPI
31
22
June 3, 2024
🌐
Medium
medium.com › @ugurcanerdogan › full-stack-application-deployment-with-docker-aws-ec2-and-github-actions-c27e81d134b2
Full Stack Application Deployment with Docker, AWS EC2, and GitHub Actions — PART 3: Preparing CI/CD Pipeline | by Uğurcan Erdoğan | Medium
September 15, 2023 - The line below may vary depending on where your docker-compose file is located. working-directory: /home/ubuntu # Bash commands you want to execute command: | sudo docker-compose stop sudo docker-compose rm -f sudo docker-compose pull sudo docker-compose up -d sudo docker image prune -af # Comment for Send-Command comment: docker-compose.yml file re-pulls newer versions of book-portal images and runs them on the instance. As you can see, we point to the information related with AWS in the secrets, in this file. If we examine it in more detail, we started by defining a GitHub Actions job in ec2.yml and named it AWS-EC2 Instance CD.
🌐
Medium
medium.com › ryanjang-devnotes › ci-cd-hands-on-github-actions-docker-hub-aws-ec2-ba09f80297e1
CI/CD Hands-On : Github Actions+Docker Hub+AWS EC2 | by Minho Jang | ryanjang-devnotes | Medium
February 18, 2022 - Configure a step where the runner execute docker commands to build and push your image to Hub. ... Lastly, let your instance be handled by the workflow to pull and run the image automatically.
🌐
DevOps.dev
blog.devops.dev › continuous-deployment-with-github-actions-dockerhub-and-aws-ec2-a-hands-on-tutorial-b01656a27963
Continuous Deployment with GitHub Actions, DockerHub, and AWS EC2 — A Hands-on Tutorial | by Ashok Poudel | DevOps.dev
April 13, 2023 - Now, whenever you push changes to the main branch of your GitHub repository, the GitHub Actions workflow will build and push the Docker image to DockerHub and deploy it to your EC2 instance. This tutorial demonstrated a basic Continuous Deployment process using GitHub Actions, DockerHub, and ...
🌐
Bitovi
bitovi.com › blog › deploy-any-docker-project-to-aws-with-github-actions
Deploy Any Docker Project to AWS with GitHub Actions
December 5, 2023 - To deploy an app to AWS with Bitovi’s deploy-docker-to-ec2 action, all you need to do is create the folders .github/workflows and add a workflow file under your repo’s .github/workflows directory.
🌐
Medium
aws.plainenglish.io › deploying-a-web-application-on-aws-ec2-with-github-actions-running-on-docker-container-part-1-58d5d14f3f05
Deploying a web application on AWS EC2 with GitHub Actions running on Docker Container | by Manmeet Singh | AWS in Plain English
August 16, 2024 - Before running the Dockerfile via workflow, I manually ran it on an EC2 instance to validate the Dockerfile and whether it is able to create image, create container and then run the app. All the tests were successful and I could open the app’s UI: ... Built the docker image and pushed it to ECR via GitHub actions pipeline: - Image is pushed to AWS Elastic Container Registry:
🌐
LinkedIn
linkedin.com › pulse › automating-docker-image-build-push-aws-ecr-deployment-vibhor-jain
🚀Automating Docker Image Build & Push to AWS ECR and Deployment on EC2 instances through GitHub Actions🐳.
July 28, 2023 - In this article, I’ll explain to you how to build & push docker images to AWS ECR (Elastic Container Registry) and how to run a container in EC2 instance using GitHub Actions. Introduction: In today's fast-paced software development landscape, automation is the key to achieving efficient ...
Find elsewhere
🌐
DEV Community
dev.to › engrmark › how-to-set-up-github-actions-to-deploy-a-simple-docker-app-on-an-ec2-server-4d0h
How to Set Up GitHub Actions to Deploy a Simple Docker App on an EC2 Server - DEV Community
April 23, 2025 - name: Deploy App run-name: Deploy - ${{ github.event.head_commit.message }} on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest timeout-minutes: 5 steps: - name: Deploy via SSH uses: appleboy/ssh-action@v0.1.10 with: host: ${{ secrets.HOST }} username: ${{ secrets.USERNAME }} key: ${{ secrets.SSH_PRIVATE_KEY }} port: 22 script: | cd your-repo-folder git pull origin main docker compose up --build -d --force-recreate docker image prune -f
🌐
GeeksforGeeks
geeksforgeeks.org › devops › deploy-mern-stack-on-aws-ec2-with-docker-via-github-actions
Deploy MERN Stack on AWS EC2 with Docker via GitHub Actions - GeeksforGeeks
July 23, 2025 - Using GitHub actions, we first deployed our backend application on our EC2 instance. By using our backend application's public IP address, we configured our frontend BaseURL inside our frontend repository secrets. Then we deployed our front-end application on our EC2 instance. By performing all these steps, you can successfully deploy your MERN Stack application in AWS EC2 using Docker through GitHub actions
🌐
Medium
medium.com › @sriharimalapati › ci-cd-pipeline-for-node-js-deploying-to-aws-ec2-with-docker-and-github-actions-d1bc80c67909
CI/CD Pipeline for Node.js: Deploying to AWS EC2 with Docker and GitHub Actions | by Sriharimalapati | Medium
November 23, 2024 - 6. Now, let’s configure GitHub secrets to store sensitive information such as Docker Hub’s username and password. ... Click onSecrets and variables and select Actions. ... Go to the AWS console and select EC2 service.
🌐
Reddit
reddit.com › r/aws › best practice to deploy docker containers in ec2
r/aws on Reddit: Best practice to deploy docker containers in ec2
July 10, 2024 -

I’ve spent 3-4 days to try to build cicd pipeline for my personal project using GitHub actions, and I ended up designating my server instance as part of the github self hosted runners for my workflows. However, before that, I’ve seem a couple of other approaches like using ssm or ssh connection directly from the action runner to the ec2 putting your pem file onto GitHub which I thought is not an ideal practice for security reasons. I’m wondering now how other people run the docker containers in your ec2 instances from github actions?

edited: Thank you so much for answering this stupid question written in stupid english, guys!

🌐
GitHub
github.com › aws-samples › build-and-deploy-docker-images-to-aws-using-ec2-image-builder
GitHub - aws-samples/build-and-deploy-docker-images-to-aws-using-ec2-image-builder · GitHub
Contribute to aws-samples/build-and-deploy-docker-images-to-aws-using-ec2-image-builder development by creating an account on GitHub.
Starred by 20 users
Forked by 12 users
Languages   Java 69.3% | Dockerfile 30.7%
🌐
Canopas
canopas.com › simplified-your-deployment-github-workflow-with-ec2-ecr-and-docker-4c9c392d238d
Simplified Your Deployment: GitHub Workflow with EC2, ECR, and Docker
August 1, 2023 - Using this file, docker will create node.js, database, and nginx containers on EC2 with volumes and networks. version: "3.8" services: # below steps will create node.js container on 3000 port node-app: image: <ecr-image-uri> deploy: replicas: 1 depends_on: - db volumes: - uploads:/srv/app/public/uploads ports: - "3000:3000" environment: AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY} ...
🌐
ServiceStack
docs.servicestack.net › mix-github-actions-aws-ecs
GitHub Actions mix template - Deploy to AWS ECS
For the AWS access, a separate user specifically for deploying via GitHub Actions should be used. The GitHub Action template in .github/workflows/release.yml is there as a starting point and should be edited as required. The idea is that you can evolve and change these to your needs as your ...
🌐
GitHub
github.com › bitovi › github-actions-deploy-docker-to-ec2
GitHub - bitovi/github-actions-deploy-docker-to-ec2: GitHub Action to deploy any docker-composed app to an AWS EC2 VM. · GitHub
This action will create an EC2 instance and the resources defined, copy this repo to the VM, install docker (and other options if enabled) and then run docker compose up. If you would like to deploy a backend app/service, check out our other actions:
Starred by 99 users
Forked by 15 users
🌐
Medium
medium.com › @ucheoran › deploy-containerized-application-to-ec2-vm-using-github-actions-9fb018d3ccf5
Automate deployment to EC2 VM using Github Actions and Docker. | by Uche Oran | Apr, 2026 | Medium
April 14, 2026 - The 6 steps covered in this guide are: • Step 1: Provision an EC2 Instance with Docker and AWS cli installed • Step 2: Prepare the GitHub Repository & Workflow • Step 3: Configure AWS IAM for Secure OIDC Authentication (GitHub → ECR) ...
🌐
Medium
medium.com › @usvisen2000 › simplifying-docker-deployments-on-aws-ec2-instances-a-github-actions-and-aws-ssm-approach-45014bf3869a
Simplifying Docker Deployments on AWS EC2 Instances: A GitHub Actions and AWS SSM Approach | by Utkarsh Singh | Medium
February 19, 2024 - In this step, we orchestrate the execution of Docker commands on EC2 instance to deploy the application using GitHub Actions and AWS Systems Manager (SSM) commands.
Top answer
1 of 2
2

This is definitely possible using AWS CodePipeline but it will require you to have a Lambda function since you want to deploy your container to your own EC2 instance (which I think is not necessary unless you have a specific use-case). This is how your pipeline would look like;

AWS CodePipline stages:

  • Source: Connect your GitHub repository. In the background, it will automatically clone code from your Git repo, zip it, and store it in S3 to be used by the next stage. There are other options as well if you want to do it all by yourself. For example;
    • using your GitHub actions, you zip the file and store it in S3 bucket. On the AWS side, you will add S3 as a source and provide the bucket and object key so whenever this object version changes, it will trigger the pipeline.
    • You can also use GitHub actions to actually build your Docker image and push it to AWS ECR (container registry) and totally skip build stage. So, either do build on GitHub or on AWS side, upto you.
  • Build: For this stage (if you decide to build using AWS), you can either use Jenkins or AWS Codebuild. I have used AWS Codebuild, so IMO this is fairly easy and quick solution for the build stage. At this stage, it will use the zip file in S3 bucket, unzip it, build your Docker container image and push it to AWS ECR.
  • Deploy: Since you want to run your Docker container on EC2, there is no straight forward way to do this. However, you can utilize the power of Lambda function to run your image on your own EC2 instance. But you will have to code your function which could be tricky. I would highly recommend using AWS ECS to run your container in a more manageable way. You can essentially do all the things that you want to do in your EC2 instance to your ECS container.
2 of 2
0

As @Myz suggested, this can be done using GitHub actions with AWS ECR and AWS ECS. Below are some articles which I was following to solve the issue:

  • https://docs.github.com/en/actions/deployment/deploying-to-your-cloud-provider/deploying-to-amazon-elastic-container-service
  • https://kubesimplify.com/cicd-pipeline-github-actions-with-aws-ecs