VOOZH about

URL: https://thenewstack.io/dockerize-a-rust-application-with-aws-ecr-and-github-actions/

⇱ Dockerize a Rust Application with AWS ECR and GitHub Actions - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2024-08-16 07:34:49
Dockerize a Rust Application with AWS ECR and GitHub Actions
sponsor-andela,sponsored-post-contributed,tutorial,
Cloud Services / Containers / Rust

Dockerize a Rust Application with AWS ECR and GitHub Actions

A step-by-step guide on how to Dockerize an application in Rust and deploy this application to Amazon Elastic Container Registry.
Aug 16th, 2024 7:34am by Adetokunbo Ige
👁 Featued image for: Dockerize a Rust Application with AWS ECR and GitHub Actions
Image from Afdhaluddin on Shutterstock
Andela sponsored this post.

I have heard many exciting things about programming in Rust, so I decided to use Rust for one of my applications. Using the combination of Rust and Docker is quite interesting.

Rust is a system programming language popularly known for its memory safety, performance and speed. Docker is a platform that allows developers to develop, deploy and manage applications using containerization. The combination of Docker and Rust creates an application that is both highly efficient and easily portable.

Below is a step-by-step guide on how to Dockerize an application in Rust and deploy this application to Amazon Elastic Container Registry (ECR). We’ll start with the assumption that you already understand AWS ECR and GitHub Actions.

Step 1: Setting Up Your Environment: Install Rust and Docker

First, ensure that Docker and Rust are installed in your development environment. Run the following commands in your terminal to install Docker and Rust. The command rustup helps to install the latest stable version of Rust.

Step 2: Setting Up the Project

Next, create a new Rust project using cargo, Rust’s package manager and build system. Run the following command to create a new directory:

This will create a new directory named rust_docker with a basic Rust application. The main source file is located at src/main.rs.

Step 3: Create a Rust Application

Create the following code in src/main.rs. This is a simple “Hello, world” application in Rust.

Step 4: Create Cargo.toml and Cargo.lock file

Create a new file named  Cargo.toml, which will contain the configuration details for the Rust binary. Also, create the Cargo.lock file, which will contain details of the binary. You can see a sample file here: https://github.com/ExitoLab/rust_docker_guide

Step 5: Create the Dockerfile

To containerize the Rust application, you need to create a Dockerfile. It will contain instructions on how to build the Docker image of your application. Create a new file in the root directory of your project and name it Dockerfile. You can also use the touch Dockerfile command to create it.

Open the Dockerfile and add the following content:

Step 6: Building and Running the Docker Image

With your Dockerfile ready, you can create the Docker image for your Rust application by executing the following command:

docker build -t rust_docker_guide:v0.0.1 .

This command will create a Docker image named rust_docker_guide.

Step 7: Test the Dockerize Rust Application Locally

This command will start the Docker container and map port 8080 of the host machine to port 8080 of the container.

docker run -p 8080:8080 rust_docker_guide:v0.0.1

You will see the result of the Rust app from the console and it will display “Hello, World!” confirming that the application is running successfully inside the Docker container.

See the screenshot below of the result.

👁 Image

Follow These Steps to Deploy Docker Image to AWS ECR 

Step 1: Authenticate with AWS

Before pushing your Docker image to ECR, you must authenticate with AWS services using either identity and access management (IAM) roles or AWS access keys and secret keys.

Step 2: Create an AWS ECR Repository to Deploy Docker Image to AWS ECR

You will need to create an AWS ECR repository. Use the command below to create the repository. Replace <your_account_id>.dkr.ecr.us-east-1.amazonaws.com with your newly created Amazon ECR URI:

Step 3: Push the Docker Image to Amazon ECR

The next step is to push the Docker image you built locally to AWS ECR. See the command below on how to achieve this. Replace <your_account_id> with your AWS account.

Deploy Docker Image to AWS ECR using GitHub Actions

Step 1: Authenticate with AWS for GitHub Actions

Before pushing your Docker image to Amazon ECR using GitHub Actions, you must authenticate with AWS services using either IAM roles or AWS access keys and secret keys. I prefer to use IAM roles to authenticate with AWS. Using IAM roles for AWS authentication enhances security by providing temporary, least-privilege access and eliminates the need for hardcoded credentials. To use IAM roles in GitHub Actions, you can set up OpenID Connect (OIDC) authentication. This approach allows GitHub Actions to obtain temporary credentials from AWS based on the IAM role associated with the GitHub workflow.

Step 2: Configure Authentication and Deployment Settings

Add the Amazon Resource Name, AWS ECR and AWS region to GitHub Secrets to securely configure authentication and deployment settings for your GitHub Actions workflows.

Step 3: Run the GitHub Actions Pipeline

Conclusion

I hope you find this process of Dockerizing a Rust application useful and interesting. Check out the complete code on GitHub.

To learn more about the potential of AWS in software development, read Adetokunbo’s article “Deploy React on AWS Amplify Using Terraform.

Andela provides the world’s largest private marketplace for global remote tech talent driven by an AI-powered platform to manage the complete contract hiring lifecycle. Andela helps companies scale teams & deliver projects faster via specialized areas: App Engineering, AI, Cloud, Data & Analytics.
Learn More
The latest from Andela
Hear more from our sponsor
TRENDING STORIES
Adetokunbo Ige is a technologist for Andela, a private global talent marketplace. A seasoned platform engineer and a Certified ISO 22301 Lead Implementer in Business Continuity, he brings a wealth of experience in software engineering, enterprise application management, server infrastructure...
Read more from Adetokunbo Ige
Andela sponsored this post.
SHARE THIS STORY
TRENDING STORIES
AWS and Docker are sponsors of The New Stack.
TNS owner Insight Partners is an investor in: Docker.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.