Skip to content

devraymondsh/ubuntu-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Rust docker image built on top of Ubuntu Linux.

Supported tags:

  • 24.04, 24.04-1.82, noble-1.82, noble-latest, noble, 24.04-latest, latest-1.82, 1.82, latest
  • 23.04, 23.04-1.82, lunar-1.82, lunar-latest, lunar
  • 22.04, 22.04-1.82, jammy-1.82, jammy-latest, jammy
  • 20.04, 20.04-1.82, focal-1.82, focal-latest, focal

How to use this image

Start a Rust instance running your app

The most straightforward way to use this image is to use a Rust container as both the build and runtime environment. In your Dockerfile, writing something along the lines of the following will compile and run your project:

FROM devraymondsh/ubuntu-rust:latest

WORKDIR /usr/src/myapp
COPY . .

RUN cargo install --path .

CMD ["myapp"]

Then, build and run the Docker image:

$ docker build -t my-rust-app .
$ docker run -it --rm --name my-running-app my-rust-app

This creates an image that has all of the rust tooling for the image. If you just want the compiled application which has a smaller size:

FROM devraymondsh/ubuntu-rust:latest as builder
WORKDIR /usr/src/myapp
COPY . .
RUN cargo install --path .

FROM debian:buster-slim
RUN apt-get update && apt-get install -y extra-runtime-dependencies && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/cargo/bin/myapp /usr/local/bin/myapp
CMD ["myapp"]

Note: Some shared libraries may need to be installed as shown in the installation of the extra-runtime-dependencies line above.

Compile your app inside the Docker container

There may be occasions where it is not appropriate to run your app inside a container. To compile, but not run your app inside the Docker instance, you can write something like:
$ docker run --rm --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/myapp -w /usr/src/myapp devraymondsh/ubuntu-rust:latest cargo build --release
This will add your current directory, as a volume, to the container, set the working directory to the volume, and run the command cargo build --release. This tells Cargo, Rust's build system, to compile the crate in myapp and output the executable to target/release/myapp.

License

The image is licensed under the MIT license. Visit LICENSE for more information.

About

A Rust docker image built on top of Ubuntu Linux.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published