1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

Add docker_sample to examples collection

This commit is contained in:
curiousdev 2020-02-24 10:48:04 -07:00 committed by Jonathas Conceição
parent dc8d61eb59
commit 50332ca491
5 changed files with 80 additions and 0 deletions

View File

@ -45,4 +45,5 @@ members = [
"websocket-chat",
# "websocket-chat-broker",
"websocket-tcp-chat",
"docker_sample",
]

11
docker_sample/Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "docker_sample"
version = "0.1.0"
authors = ["docker_sample <docker_sample@sample.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-rt = "1.0.0"
actix-web = "2.0.0"

15
docker_sample/Dockerfile Normal file
View File

@ -0,0 +1,15 @@
FROM rust:1 as builder
COPY . .
RUN cargo build --release
FROM rust:1-slim-stretch
COPY --from=builder /target/release/docker_sample .
RUN ls -la /docker_sample
EXPOSE 5000
ENTRYPOINT ["/docker_sample"]

23
docker_sample/README.MD Normal file
View File

@ -0,0 +1,23 @@
Build image:
```shell
docker build -t docker_sample --force-rm --no-cache -f Dockerfile .
```
Run image:
```shell
echo "== start sample_docker"
docker run -d -p 5000:5000 docker_sample &
docker ps
echo "== wait 3s for startup"
sleep 3s
echo "== curl both routes"
curl http://localhost:5000
curl http://localhost:5000/again
```

30
docker_sample/src/main.rs Normal file
View File

@ -0,0 +1,30 @@
#[macro_use]
extern crate actix_web;
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
#[get("/")]
async fn index() -> impl Responder {
println!("GET: /");
HttpResponse::Ok().body("Hello world!")
}
#[get("/again")]
async fn again() -> impl Responder {
println!("GET: /again");
HttpResponse::Ok().body("Hello world again!")
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
println!("Starting actix-web server");
HttpServer::new(|| {
App::new()
.service(index)
.service(again)
})
.bind("0.0.0.0:5000")?
.run()
.await
}