Getting "Layer already exists" for project built with docker
Anonymous
TRIALOP

2 years ago

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

50 Replies

2 years ago

Railway does layer caching if nothing in that layer has changed.


2 years ago

does this mean you are deploying with a Dockerfile?


Anonymous
TRIALOP

2 years ago

Yes


2 years ago

please share the dockerfile


Anonymous
TRIALOP

2 years ago

From a github repository


Anonymous
TRIALOP

2 years ago

Ok I will share it when im back at my laptop


Anonymous
TRIALOP

2 years ago

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"]

Anonymous
TRIALOP

2 years ago

This is my Dockerfile


2 years ago

I might not be a rust dev by why is cargo build being ran twice?


Anonymous
TRIALOP

2 years ago

The first time to install the dependencies, and the second one to build the application itself.


2 years 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?


Anonymous
TRIALOP

2 years ago

Because it's printing hello world to the deploy logs and the http service is not running


Anonymous
TRIALOP

2 years ago

My guess is a previous binary is being cached in one of those layers

1219357915467616300


2 years ago

if thats the case, set a variable NO_CACHE=1


Anonymous
TRIALOP

2 years ago

Ok, I'll try that


Anonymous
TRIALOP

2 years ago

Setting NO_CACHE doesn't seem to have had any effect


Anonymous
TRIALOP

2 years ago

I set it in the railway service, should I set it in other place?


2 years ago

show me how you are setting it


Anonymous
TRIALOP

2 years ago

1219358862033944800


Anonymous
TRIALOP

2 years ago

1219358950311592000


Anonymous
TRIALOP

2 years ago

I can still see the messages saying the layers are cached


2 years ago

can you push an empty commit


Anonymous
TRIALOP

2 years ago

Sure, but I already tried that as well


Anonymous
TRIALOP

2 years ago

Just pushed


2 years ago

and what makes you think the http server isnt starting?


Anonymous
TRIALOP

2 years ago

When I go to the generated domain I get "Application Failed to Respond"



Anonymous
TRIALOP

2 years ago

Also it's weird that hello world its printed because that not in the code


Anonymous
TRIALOP

2 years ago

1219360456011939800


2 years ago

how are you sure you are pushing code that runs an http server?


Anonymous
TRIALOP

2 years ago

because im running the same code locally and it works


Anonymous
TRIALOP

2 years ago

i can share the repo if it helps


2 years ago

i think it would be worth it


Anonymous
TRIALOP

2 years ago


2 years ago

show me the source of your service



Anonymous
TRIALOP

2 years ago

here you can see the server is set to run and there is no hello world being printed


2 years ago

full build logs please


Anonymous
TRIALOP

2 years ago


2 years ago

change the name of the binary thats being built?


Anonymous
TRIALOP

2 years ago

Still the same thing sadly


2 years ago

try deploying the repo into a new service


Anonymous
TRIALOP

2 years ago

Unfortunately, that doesnt seem to be working either


Anonymous
TRIALOP

2 years ago

I think there is a problem with my Dockerfile, since I did a full rebuild now and it behaves same as railway


Anonymous
TRIALOP

2 years ago

I'll investigate and report back


2 years 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


Anonymous
TRIALOP

2 years ago

Yes, now the issue seems to be fixed. Thank you for your help!


2 years ago

haha you gotta tell me what the issue was


Anonymous
TRIALOP

2 years 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.


2 years ago

i knew that double command was fishy


Loading...