LukeMathWalker / zero-to-production

Code for "Zero To Production In Rust", a book on API development using Rust.
https://www.zero2prod.com
Apache License 2.0
5.43k stars 470 forks source link

Dockerfile fails to build because context size is too big (no space left on device) #226

Closed DjebbZ closed 9 months ago

DjebbZ commented 9 months ago

Hello,

In the very first Dockerfile (5.3.1), COPY . . will also copy the target/ directory, which makes the context size for Docker ~10GB on my machine by the time I reach this chapter. This makes the very first docker build command fails with :

Dockerfile:8
--------------------
   6 |     RUN apt update && apt install lld clang -y
   7 |
   8 | >>> COPY . .
   9 |
  10 |     RUN cargo build --release
--------------------
ERROR: failed to solve: failed to copy files: copy file range failed: no space left on device

Solution:

Add a .dockerignore file with target/ in it. The context size goes from ~10GB to ~400kB (on failing build: => => transferring context: 10.67GB ; on fixed build: => => transferring context: 407.96kB). Also, transferring the 10GB takes ~75s according to Docker on my machine, whereas transferring the 400kB takes 0.0s. Even if it works, I think it's a no-brainer.

Hope this helps the author and anyone encountering the problem!

LukeMathWalker commented 9 months ago

Sorry to hear about the issue! The book explains the solution shortly after in the very same chapter, so you just have to skip ahead a few sections 😁

DjebbZ commented 9 months ago

Yes I've just stumbled upon it, thanks for your answer!