#Best way to run an actix project with docker compose ?

1 messages · Page 1 of 1 (latest)

narrow pelican
#

you are not building for --release so you lose a lot of performance

#

also, I don't think pushing rust as source code into production is the way to do it, but I know that is subjective.
I would have a CI/CD with builds rust binaries and then a dockerfile with takes the ready to use binaries and runs them

#

What do you exactly mean by two actix projects? you could just have to services pointing to different docker files in docker compose

#
version: 3
services:
  foo:
    image: user/foo
    build:
      context: .../docks
      dockerfile: foo.Dockerfile
  bar:
    image: user/bar
    build:
      context: .../docks
      dockerfile: bar.Dockerfile
#

Something like that

#

Ah, sorry

#

I read Best way two actix projects

#

That you want to run two at the same time

floral burrow
#

Best way to run an actix project with docker compose ?

narrow pelican
#

No problem, didn't get it. I think the way you posted is fine. I think I would only avoid copy all the source code and not use cargo run but just copy the binary from target into the conainer

#

so basically something like that:

FROM rust:1.63.0

RUN cargo build --release
COPY targer/release/youbinary_name /usr/local/bin/youbinary_name
COPY public public

CMD ["/usr/local/bin/youbinary_name"]

They is no point in having the rust source code in the container in production

elfin apex
#

Multi stage build is definitely a good idea. Tbh at work we build in CI and just move binaries in to a sort of “thin” dockerfile.

#

Similar to multi-stage, but avoids overhead of building inside docker.

elfin apex
#

100% yes

#

I’d recommend minideb as I’ve had issues with some rust apps on Alpine in the past

#

If the copy command works then the binary exists

narrow pelican
#

chmod +x on rusttest before CMD?

iron gull
#

Alpine should work if you set it up right. It prefers musl to glibc so your best bet for deploying rust on alpine is targeting musl and statically linking as much as you can.

#

I deploy a number of my own projects on alpine

rotund ocean
# elfin apex Similar to multi-stage, but avoids overhead of _building_ inside docker.

Curious how you do this exactly, I'm toying with Rust coming from Haskell and at work we use stack build --docker to build the binary on the host machine but setup all the linking for a docker context. cargo doesn't seem to have an equivalent but rust is known for "crossplatform" being one of it's strengths so I figure I'm either over thinking things or there's a simple setup for building on the host machine (so deps are properly cached during dev) but just copying the binary (target/debug or target/release) in some compatible runtime image?