Creating and deploying a minimal axum app with loco


  1. create axum app with loco
  2. build axum app with docker

create axum app with loco

loco lets you scaffold axum apps in a preditible manner.

Terminal window
cargo install loco-cli
cargo install sea-orm-cli

create a new minimal axum app:

Terminal window
loco new
App name? · hello_loco
What would you like to build? · lightweight-service (minimal, only controllers and views)
🚂 Loco app generated successfully in:

start local app:

Terminal window
cargo loco start

build axum app with docker

use loco to create a simple dockerfile for deployment (this will create a dockerfile and a .dockerignore file.

Terminal window
cargo loco generate deployment
Finished dev [unoptimized + debuginfo] target(s) in 0.11s
Running `target/debug/hello_loco-cli generate deployment`
? Choose your deployment

build the app:

Terminal window
docker build . --tag hello_loco:latest
Terminal window
docker images
hello_loco latest 0d5bc1271eeb 0 minutes ago 123MB

running production container locally

if we just run our container with no args we will get the loco-cli help menu:

Terminal window
docker run -p 3000:3000 hello_loco
The one-person framework for Rust
Usage: hello_loco-cli [OPTIONS] <COMMAND>
start Start an app
routes Describe all application endpoints
task Run a custom task
generate code generation creates a set of files and code templates based on a predefined set of rules
version Display the app version
help Print this message or the help of the given subcommand(s)
-e, --environment <ENVIRONMENT> Specify the environment [default: development]
-h, --help Print help
-V, --version Print version

to start the app run start:

Terminal window
docker run -p 3000:3000 hello_loco start