Skip to content

Latest commit

 

History

History

rust

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

A Simple Hello Docker Rust Demo

Example used to demonstrate docker init CLI for a simple Hello Docker Rust Program

image

We will be using two crates in this sample app. A "crate" refers to a package or a module in the Rust ecosystem. It is the fundamental unit of code distribution in Rust. Crates allow you to organize, share, and reuse code across different projects and applications.

  • warp
  • tokio

The first crate is warp. The "warp" provides the web framework for building HTTP applications. Second, we will use tokio. The "tokio" provides the asynchronous runtime to enable efficient handling of concurrent and non-blocking I/O operations. Together, these dependencies make it easy to create efficient and high-performance web applications in Rust. We specify them in our Cargo.toml file.

Clone the repository

git clone https://github.com/dockersamples/docker-init-demos
cd docker-init-demos/rust
cargo init
cargo build --release

Running docker init

docker init
docker init

Welcome to the Docker Init CLI!

This utility will walk you through creating the following files with sensible defaults for your project:
  - .dockerignore
  - Dockerfile
  - compose.yaml

Let's get started!

WARNING: The following Docker files already exist in this directory:
  - .dockerignore

? Do you want to overwrite them? Yes
? What application platform does your project use? Rust
? What version of Rust do you want to use? 1.70.0
? What port does your server listen on? 3030

CREATED: .dockerignore
CREATED: Dockerfile
CREATED: compose.yaml

✔ Your Docker files are ready!

Take a moment to review them and tailor them to your application.

When you're ready, start your application by running: docker compose up --build

Your application will be available at http://localhost:3030

Running the Compose

docker compose up -d --build

Accessing the app on the browser

##         .
## ## ##        ==
## ## ## ## ##    ===
/""""""""""""""""\___/ ===
{                       /  ===-
\______ O           __/
 \    \         __/
  \____\_______/

Hello from Docker!

Viewing it on Docker Desktop Dashboard

image