Dockerfiles used to deploy Astro and PocketBase on Railway
Here’s a super quick way to deploy Astro and PocketBase on Railway (referral link).
I used this Dockerfile to deploy PocketBase:
FROM ubuntu:latest
ARG PB_VERSION=0.20.4
# Install unzip and ca-certificates
RUN apt-get update && \
apt-get install -y \
unzip \
ca-certificates && \
rm -rf /var/lib/apt/lists/*
# download and unzip PocketBase
ADD https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_amd64.zip /tmp/pb.zip
RUN unzip /tmp/pb.zip -d /pb/ && \
rm /tmp/pb.zip
EXPOSE 8080
# start PocketBase
CMD ["/pb/pocketbase", "serve", "--http=0.0.0.0:8080"]
and this Dockerfile to deploy SSR Astro:
FROM node:lts-slim as runtime
WORKDIR /app
# Ensure that both node_modules and package-lock.json are removed.
COPY package.json .
RUN rm -rf node_modules package-lock.json
# Perform a fresh installation of npm dependencies.
RUN npm install
# Copy the rest of your application files.
COPY . .
# Build your application.
RUN npm run build
# Set environment variables and expose the appropriate port.
ENV HOST=0.0.0.0
ENV PORT=3000
EXPOSE 3000
# Define the command to run your application.
CMD node ./dist/server/entry.mjs
Avoiding Alpine Linux as the base image fixed an issue with internal links I had, so now the 2 instances can talk via *.railway.internal
internal Railway URLs.
→ Here's my latest YouTube video
→ I wrote 17 books to help you become a better developer, download them all at $0 cost by joining my newsletter
→ JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025