Problem with Docker When Deploying Container in Railway. App
I Have Deployed a Serverpod Project (Dart) Through a Docker (In a Railway. App Host). but Although the Container Is Built Correctly, I Can't Access It from the...
I have deployed a serverpod project (dart) through a docker (in a railway.app host). but although the container is built correctly, I can't access it from the domain provided by railway. The container should expose port 8080 but I can't get it to work and I'm out of ideas, can someone help me?? I leave you a copy of the dockerfile
FROM dart:stable AS build
`WORKDIR /app
COPY . .
RUN dart pub get
RUN dart compile exe bin/main.dart -o bin/main
FROM jenkins/jenkins:lts
USER root
RUN apt-get update && \
apt-get -y install apt-transport-https \
ca-certificates curl gnupg2 \
software-properties-common && \
curl -fsSL (. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey && \
add-apt-repository \
"deb [arch=amd64] (. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable" && \
apt-get update && \
apt-get -y install docker-ce
USER jenkins
ENV runmode=staging
ENV serverid=default
ENV logging=normal
ENV role=monolith
COPY --from=build /runtime/etc /etc
COPY --from=build /runtime/lib /lib
COPY --from=build /runtime/lib64 /lib64
COPY --from=build /runtime/usr /usr
COPY --from=build /app/bin/main /app/bin/main
COPY --from=build /app/config/ config/
COPY --from=build /app/generated/ generated/
COPY --from=build /app/web/ web/
EXPOSE 8080
EXPOSE 8081
EXPOSE 8082`
CMD app/bin/main --mode $runmode --server-id $serverid --logging $logging --role $role
I have tried different configurations. in my local environment when i build the image with "
docker build -t <name:tag>
and then run it with
docker run -p 8080:8080 <name:tag>
works fine, i can access the container via localhost:8080. but in railway I don't have the possibility to execute it that way
2 Answers
I had the same issue with a fastAPI app. For me adding inside railway the environment variable 'PORT' with value 8080 solved the issue and allowed me to access the API through the provided railway link.
According to Railway docs, you should provide the PORT variable -