Docker, Rust, Software Development, Ubuntu

Actix-Web In Ubuntu Docker Container Not Accessible

Rust Lang

An Actix-Web application in an Ubuntu Docker container may not be accessible from the host operating system. For non-production codes and configuration, it may be due to two factors.

Actix-Web Is Not Accessible in Docker Container Due to Rust Codes

The first factor may be due to our codes. They bind to a specific IP address. Consider the following Rust codes.

The codes bind the server to 127.0.0.1 (localhost). This is fine when we are not deploying to a virtual machine. Otherwise, the application will not be accessible from outside the Docker container because the application expects requests from within the container.

To fix this problem, consider binding the server to 0.0.0.0. This makes the application to expect requests from any IP address. For production deployment, bind the server to the host operating system IP address.

Using EXPOSE in Docker File

Another factor that may make an Actix-Web program running in an Ubuntu Docker container not accessible is when we specify EXPOSE in our DockerFile. Consider the following DockerFile.

To fix the problem, comment out the EXPOSE instruction. Use the docker run --publish (or -p ) flag to explicitly specify the host-container ports. The following is a modified DockerFile.

We may need to build the Ubuntu Docker image again.

Then, we start the Ubuntu Docker container using the following command.

There may be other ways to fix the inaccessibility issue but this post is based on the experience of Deploy Actix-Web In Docker Container.

You Might Also Like