Getting "Layer already exists" for project built with docker

My Docker image is working as expected locally, but it seems to be stuck on an older version on Railway. The build logs look fine, but when publishing the image there are a bunch of layer already exists errors. My project id is: b74571d8-e862-4ac2-ad76-e19a69371a8e
Solution:
I honestly don't know. I think Cargo was doing some weird things. I simplified the Dockerfile to issue a single cargo build --release command.
Jump to solution
39 Replies
Percy
Percy9mo ago
Project ID: b74571d8-e862-4ac2-ad76-e19a69371a8e
Brody
Brody9mo ago
Railway does layer caching if nothing in that layer has changed. does this mean you are deploying with a Dockerfile?
aloussase
aloussaseOP9mo ago
Yes
Brody
Brody9mo ago
please share the dockerfile
aloussase
aloussaseOP9mo ago
From a github repository Ok I will share it when im back at my laptop
FROM rust:latest as builder

RUN cargo new --bin app

WORKDIR /app

COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock

RUN cargo build --release
RUN rm src/*.rs

COPY ./src ./src
COPY ./migrations ./migrations
COPY ./diesel.toml ./diesel.toml

RUN cargo build --release

FROM rust:latest

RUN apt-get update && apt-get install --yes libsqlite3-dev

ENV PORT=3000
EXPOSE ${PORT}

WORKDIR /app

COPY --from=builder /app/target/release/make_an_api_in_rust /app/make_an_api_in_rust

CMD ["/app/make_an_api_in_rust"]
FROM rust:latest as builder

RUN cargo new --bin app

WORKDIR /app

COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock

RUN cargo build --release
RUN rm src/*.rs

COPY ./src ./src
COPY ./migrations ./migrations
COPY ./diesel.toml ./diesel.toml

RUN cargo build --release

FROM rust:latest

RUN apt-get update && apt-get install --yes libsqlite3-dev

ENV PORT=3000
EXPOSE ${PORT}

WORKDIR /app

COPY --from=builder /app/target/release/make_an_api_in_rust /app/make_an_api_in_rust

CMD ["/app/make_an_api_in_rust"]
This is my Dockerfile
Brody
Brody9mo ago
I might not be a rust dev by why is cargo build being ran twice?
aloussase
aloussaseOP9mo ago
The first time to install the dependencies, and the second one to build the application itself.
Brody
Brody9mo ago
okay, odd given they are the exact same commands, rust sure loves ambiguity. but what makes you think railway is not running the latest code?
aloussase
aloussaseOP9mo ago
Because it's printing hello world to the deploy logs and the http service is not running
aloussase
aloussaseOP9mo ago
My guess is a previous binary is being cached in one of those layers
No description
Brody
Brody9mo ago
if thats the case, set a variable NO_CACHE=1
aloussase
aloussaseOP9mo ago
Ok, I'll try that Setting NO_CACHE doesn't seem to have had any effect I set it in the railway service, should I set it in other place?
Brody
Brody9mo ago
show me how you are setting it
aloussase
aloussaseOP9mo ago
No description
aloussase
aloussaseOP9mo ago
No description
aloussase
aloussaseOP9mo ago
I can still see the messages saying the layers are cached
Brody
Brody9mo ago
can you push an empty commit
aloussase
aloussaseOP9mo ago
Sure, but I already tried that as well Just pushed
Brody
Brody9mo ago
and what makes you think the http server isnt starting?
aloussase
aloussaseOP9mo ago
When I go to the generated domain I get "Application Failed to Respond" https://rustbridge-reviews.up.railway.app/ Also it's weird that hello world its printed because that not in the code
aloussase
aloussaseOP9mo ago
No description
Brody
Brody9mo ago
how are you sure you are pushing code that runs an http server?
aloussase
aloussaseOP9mo ago
because im running the same code locally and it works i can share the repo if it helps
Brody
Brody9mo ago
i think it would be worth it
aloussase
aloussaseOP9mo ago
GitHub
GitHub - aloussase/rust-api-clean-architecture: :crab: Demo API mad...
:crab: Demo API made in Rust for the Rust Bridge. Contribute to aloussase/rust-api-clean-architecture development by creating an account on GitHub.
Brody
Brody9mo ago
show me the source of your service
aloussase
aloussaseOP9mo ago
GitHub
rust-api-clean-architecture/src/main.rs at master · aloussase/rust-...
:crab: Demo API made in Rust for the Rust Bridge. Contribute to aloussase/rust-api-clean-architecture development by creating an account on GitHub.
aloussase
aloussaseOP9mo ago
here you can see the server is set to run and there is no hello world being printed
aloussase
aloussaseOP9mo ago
Brody
Brody9mo ago
change the name of the binary thats being built?
aloussase
aloussaseOP9mo ago
Still the same thing sadly
Brody
Brody9mo ago
try deploying the repo into a new service
aloussase
aloussaseOP9mo ago
Unfortunately, that doesnt seem to be working either I think there is a problem with my Dockerfile, since I did a full rebuild now and it behaves same as railway I'll investigate and report back
Brody
Brody9mo ago
well I'm glad you came to that conclusion because you wouldn't have believed me if I told you it was an issue on your side
aloussase
aloussaseOP9mo ago
Yes, now the issue seems to be fixed. Thank you for your help!
Brody
Brody9mo ago
haha you gotta tell me what the issue was
Solution
aloussase
aloussase9mo ago
I honestly don't know. I think Cargo was doing some weird things. I simplified the Dockerfile to issue a single cargo build --release command.
Brody
Brody9mo ago
i knew that duplicate command was fishy
Want results from more Discord servers?
Add your server