diff --git a/public/404.html b/public/404.html index 9f9d9ac..e3c45a1 100644 --- a/public/404.html +++ b/public/404.html @@ -1,2 +1,2 @@ -404 Page not found

404-lighthouse

\ No newline at end of file +404 Page not found

404-lighthouse

\ No newline at end of file diff --git a/public/about-me/index.html b/public/about-me/index.html index 9c9ea1b..e0c786a 100644 --- a/public/about-me/index.html +++ b/public/about-me/index.html @@ -1,2 +1,2 @@ -About Me

About Me

Coming soon

\ No newline at end of file +About Me

About Me

Coming soon

\ No newline at end of file diff --git a/public/index.html b/public/index.html index dd6e03f..e2fc97e 100644 --- a/public/index.html +++ b/public/index.html @@ -1,2 +1,2 @@ -Diane M's blog

Diane M's blog

Personal blog

\ No newline at end of file +Diane M's blog

Diane M's blog

Personal blog

\ No newline at end of file diff --git a/public/index.xml b/public/index.xml index bf8f674..7164a7d 100644 --- a/public/index.xml +++ b/public/index.xml @@ -1,3 +1,3 @@ -Diane M's bloghttp://princess-entrapta.github.io/blog/Recent content on Diane M's blogHugo -- gohugo.ioen-usThis work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.Wed, 25 Oct 2023 12:56:00 +0200Dockerfile for small Rust images (with dependency build caching)http://princess-entrapta.github.io/blog/posts/build-rust-dockerfile/Wed, 25 Oct 2023 12:56:00 +0200http://princess-entrapta.github.io/blog/posts/build-rust-dockerfile/Introduction After reading multiple tutorials for building docker images and optimize them, I compiled an optimized Dockerfile that can: +Diane M's bloghttp:/s/princess-entrapta.github.io/blog/Recent content on Diane M's blogHugo -- gohugo.ioen-usThis work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.Wed, 25 Oct 2023 12:56:00 +0200Dockerfile for small Rust images (with dependency build caching)http:/s/princess-entrapta.github.io/blog/posts/build-rust-dockerfile/Wed, 25 Oct 2023 12:56:00 +0200http:/s/princess-entrapta.github.io/blog/posts/build-rust-dockerfile/Introduction After reading multiple tutorials for building docker images and optimize them, I compiled an optimized Dockerfile that can: Have final images that are small, in the 50MB range Benefit from docker caching, allowing to have build times under 10s if you don’t change dependencies We will assume here you start with a project my_app you already have or have created with cargo new. -Setting up We use this docker file.About Mehttp://princess-entrapta.github.io/blog/about-me/Wed, 25 Oct 2023 00:00:00 +0000http://princess-entrapta.github.io/blog/about-me/Coming soon \ No newline at end of file +Setting up We use this docker file.About Mehttp:/s/princess-entrapta.github.io/blog/about-me/Wed, 25 Oct 2023 00:00:00 +0000http:/s/princess-entrapta.github.io/blog/about-me/Coming soon \ No newline at end of file diff --git a/public/posts/build-rust-dockerfile/index.html b/public/posts/build-rust-dockerfile/index.html index 2ea9013..fcf32ea 100644 --- a/public/posts/build-rust-dockerfile/index.html +++ b/public/posts/build-rust-dockerfile/index.html @@ -2,10 +2,10 @@ Have final images that are small, in the 50MB range Benefit from docker caching, allowing to have build times under 10s if you don’t change dependencies We will assume here you start with a project my_app you already have or have created with cargo new. Setting up We use this docker file.">Dockerfile for small Rust images (with dependency build caching)

Dockerfile for small Rust images (with dependency build caching)

Introduction

After reading multiple tutorials for building docker images and optimize them, I compiled an optimized Dockerfile that can:

  • Have final images that are small, in the 50MB range
  • Benefit from docker caching, allowing to have build times under 10s if you don’t change dependencies

We will assume here you start with a project my_app you already have or have created with cargo new.

Setting up

We use this docker file. This technique is called a multi-stage build. When docker builds with docker build or docker compose build, it creates two successive images:

  • One that serve to create the binary
  • One that will execute the binary without the build environment

The second one can be minimized by removing unecessary system components that are already bundled in the produced binary.

## BUILDER IMAGE
+Setting up We use this docker file.">Dockerfile for small Rust images (with dependency build caching)

Dockerfile for small Rust images (with dependency build caching)

Introduction

After reading multiple tutorials for building docker images and optimize them, I compiled an optimized Dockerfile that can:

  • Have final images that are small, in the 50MB range
  • Benefit from docker caching, allowing to have build times under 10s if you don’t change dependencies

We will assume here you start with a project my_app you already have or have created with cargo new.

Setting up

We use this docker file. This technique is called a multi-stage build. When docker builds with docker build or docker compose build, it creates two successive images:

  • One that serve to create the binary
  • One that will execute the binary without the build environment

The second one can be minimized by removing unecessary system components that are already bundled in the produced binary.

## BUILDER IMAGE
 FROM rust:1.73 as builder
 
 WORKDIR /usr/app
@@ -55,4 +55,4 @@
 version = "0.3"
 

You can learn more about what is jemalloc here

If you use things that are dependent of ssl, such as reqwest, you might also need to tweak the dependency to include rust-tls:

reqwest = {version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
 

Running

Try to docker build your image. If it is successful, try to docker run the obtained container. It should execute your binary.

You notice your first docker build was probably long, several minutes long perhaps.

Try to modify your sources, then docker build again. You should notice the build to be significantly faster.

Use docker images and inspect image size. Smaller images are faster to push and pull over network, they also cost less to store.

Conclusion

We learned to make a multi-stage build to produce small docker images for Rust, and use the best of docker caching to avoid a costy rebuild -of dependencies at every source change.

Thanks to / further reading


527 Words

2023-10-25 12:56 +0200

\ No newline at end of file +of dependencies at every source change.

Thanks to / further reading


527 Words

2023-10-25 12:56 +0200

\ No newline at end of file diff --git a/public/posts/index.html b/public/posts/index.html index 0d7955e..9faef59 100644 --- a/public/posts/index.html +++ b/public/posts/index.html @@ -1,3 +1,3 @@ -Posts

Posts

\ No newline at end of file +Posts

Posts

\ No newline at end of file diff --git a/public/posts/index.xml b/public/posts/index.xml index 0c04a5f..fe1cc2b 100644 --- a/public/posts/index.xml +++ b/public/posts/index.xml @@ -1,4 +1,4 @@ -Posts on Diane M's bloghttp://princess-entrapta.github.io/blog/posts/Recent content in Posts on Diane M's blogHugo -- gohugo.ioen-usThis work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.Wed, 25 Oct 2023 12:56:00 +0200Dockerfile for small Rust images (with dependency build caching)http://princess-entrapta.github.io/blog/posts/build-rust-dockerfile/Wed, 25 Oct 2023 12:56:00 +0200http://princess-entrapta.github.io/blog/posts/build-rust-dockerfile/Introduction After reading multiple tutorials for building docker images and optimize them, I compiled an optimized Dockerfile that can: +Posts on Diane M's bloghttp:/s/princess-entrapta.github.io/blog/posts/Recent content in Posts on Diane M's blogHugo -- gohugo.ioen-usThis work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.Wed, 25 Oct 2023 12:56:00 +0200Dockerfile for small Rust images (with dependency build caching)http:/s/princess-entrapta.github.io/blog/posts/build-rust-dockerfile/Wed, 25 Oct 2023 12:56:00 +0200http:/s/princess-entrapta.github.io/blog/posts/build-rust-dockerfile/Introduction After reading multiple tutorials for building docker images and optimize them, I compiled an optimized Dockerfile that can: Have final images that are small, in the 50MB range Benefit from docker caching, allowing to have build times under 10s if you don’t change dependencies We will assume here you start with a project my_app you already have or have created with cargo new. Setting up We use this docker file.Introduction

After reading multiple tutorials for building docker images and optimize them, I compiled an optimized Dockerfile that can:

diff --git a/public/sitemap.xml b/public/sitemap.xml index 2dcdf88..771c715 100644 --- a/public/sitemap.xml +++ b/public/sitemap.xml @@ -1 +1 @@ -http://princess-entrapta.github.io/blog/2023-10-25T12:56:00+02:00http://princess-entrapta.github.io/blog/posts/build-rust-dockerfile/2023-10-25T12:56:00+02:00http://princess-entrapta.github.io/blog/posts/2023-10-25T12:56:00+02:00http://princess-entrapta.github.io/blog/about-me/2023-10-25T00:00:00+00:00http://princess-entrapta.github.io/blog/tags/ \ No newline at end of file +http:/s/princess-entrapta.github.io/blog/2023-10-25T12:56:00+02:00http:/s/princess-entrapta.github.io/blog/posts/build-rust-dockerfile/2023-10-25T12:56:00+02:00http:/s/princess-entrapta.github.io/blog/posts/2023-10-25T12:56:00+02:00http:/s/princess-entrapta.github.io/blog/about-me/2023-10-25T00:00:00+00:00http:/s/princess-entrapta.github.io/blog/tags/ \ No newline at end of file diff --git a/public/tags/index.html b/public/tags/index.html index d85eb4b..dfab399 100644 --- a/public/tags/index.html +++ b/public/tags/index.html @@ -1,2 +1,2 @@ -Tags

Tags

\ No newline at end of file +Tags

Tags

\ No newline at end of file diff --git a/public/tags/index.xml b/public/tags/index.xml index bb72398..37d02a0 100644 --- a/public/tags/index.xml +++ b/public/tags/index.xml @@ -1 +1 @@ -Tags on Diane M's bloghttp://princess-entrapta.github.io/blog/tags/Recent content in Tags on Diane M's blogHugo -- gohugo.ioen-usThis work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. \ No newline at end of file +Tags on Diane M's bloghttp:/s/princess-entrapta.github.io/blog/tags/Recent content in Tags on Diane M's blogHugo -- gohugo.ioen-usThis work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. \ No newline at end of file