Docker, Rust, Software Development, Ubuntu

Deploy Actix-Web In Docker Container

We can deploy a Rust application based on the Actix-Web framework in a Docker container when we are coding in Windows. In this post, we compile Rust codes on Windows but deploy the application to an Ubuntu 18.04 Docker image.

Docker Container to Build Codes for Ubuntu 18.04

First, we need a container that builds Rust codes in Ubuntu 18.04. This ensures that the codes will run on the same operating system running in a separate container.

Sample Actix-Web Project To Deploy

Next, we create a sample Actix-Web project.

Then, we have Rust codes.

Finally, create a DockerFile to build an Ubuntu 18.04 Docker image that has our Rust application.

Build Codes On Windows Using Ubuntu 18.04 Docker Container

Let’s say we have an Actix-Web project in this folder – C:\Users\karl\Desktop\dev\blog\rust2\actix-web-docker, open a command-line window to change to that directory.

Then, run the following command to build the codes for Linux.

The command generates the following output.

Once we built the codes, we get the following files.

Our Linux executable is the file actix-web-docker, which we deploy to an Ubuntu 18.04 Docker image.  Then, run the following command.

The command generates the following output.

Run Docker Container

To start our application, start a Docker container using the following command.

Then, open a web browser on Windows and go to http://localhost:8181/html.

In summary, we are coding in Windows but built the codes using an Ubuntu 18.04 image with Rust compiler. Also, we deployed that application to another Ubuntu 18.04 image.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like