Dockerfile working on local machine but not Railway

Here is my dockerfile
FROM rust:latest

ARG DATABASE_URL

WORKDIR /usr/src/pail

COPY Cargo.lock .
COPY Cargo.toml .
COPY docker_utils/dummy.rs .

# Change temporarely the path of the code
RUN sed -i 's|src/main.rs|dummy.rs|' Cargo.toml
# Build only deps
RUN cargo build --release
# Now return the file back to normal
RUN sed -i 's|dummy.rs|src/main.rs|' Cargo.toml

COPY . .

RUN cargo build --release

EXPOSE 8000

RUN touch .env

RUN echo "DATABASE_URL=$DATABASE_URL" >>.env

RUN echo "ROCKET_DATABASES='{db={url='$DATABASE_URL'}}'" >>.env

CMD ./target/release/pail
FROM rust:latest

ARG DATABASE_URL

WORKDIR /usr/src/pail

COPY Cargo.lock .
COPY Cargo.toml .
COPY docker_utils/dummy.rs .

# Change temporarely the path of the code
RUN sed -i 's|src/main.rs|dummy.rs|' Cargo.toml
# Build only deps
RUN cargo build --release
# Now return the file back to normal
RUN sed -i 's|dummy.rs|src/main.rs|' Cargo.toml

COPY . .

RUN cargo build --release

EXPOSE 8000

RUN touch .env

RUN echo "DATABASE_URL=$DATABASE_URL" >>.env

RUN echo "ROCKET_DATABASES='{db={url='$DATABASE_URL'}}'" >>.env

CMD ./target/release/pail
The .env DATABASE_URL is being properly injected and is in the .env as the build logs say, but in the deploy logs this is the error.
Error: database config error for pool named `db`
>> missing field `url`
Error: database config error for pool named `db`
>> missing field `url`
This error only happens when there is no .env The container works perfectly on my local machine and im wonder if I need to make special changes for it to work on Railway.
2 Replies
Percy
Percy2y ago
Project ID: f742b766-da41-4ee1-9105-a414b1f90eb0
Mrxbox98
Mrxbox982y ago
f742b766-da41-4ee1-9105-a414b1f90eb0 Resolved: For anyone else who may have this issue, I also had ROCKET_DATABASES in my environment variables which was causing the issue for some reason, remove it and it should work.