Want to deploy your Astro website using Docker? You can package your project into a container, run it consistently across environments, and deploy it to your own VPS or cloud server.

The process depends on how your Astro website works. If you're building a static website, you can use Docker to generate the site and serve its files through Nginx. If your project needs server-side rendering (SSR), you'll need Astro's Node.js adapter and a running Node.js container.

In this guide, we'll walk through both approaches, create the required Dockerfiles, test the containers locally, and deploy your Astro website to a server.

What Does Docker Do for an Astro Website?

Docker packages your application and its required runtime environment into an image. You can use that image to create containers that run consistently across different environments.

For an Astro project, Docker can help you:

  • Package your application and dependencies.
  • Keep development and production environments consistent.
  • Deploy the same application across different servers.
  • Isolate your website from other applications.
  • Rebuild and replace deployments when you update your code.

One important thing to understand: Docker is a deployment option, not a requirement for Astro. You can host a static Astro website without running a Docker container.

However, Docker becomes useful when you want a repeatable deployment process or need to run multiple applications in a consistent server environment.

1. What Do You Need Before Deploying Astro with Docker?

Before starting, make sure you have:

RequirementPurpose
Astro projectYour website's source code
Node.js and npmInstall dependencies and build the project
DockerBuild and run containers
Docker ComposeManage the deployment configuration
VPS or cloud serverHost your production website
Domain nameMake your website accessible publicly

You'll also need access to your Astro project directory.

If you haven't created an Astro project yet, you can start with:

Terminal window
npm create astro@latest

Move into your project directory:

Terminal window
cd my-astro-project

Install the dependencies:

Terminal window
npm install

Test the production build:

Terminal window
npm run build

If the build completes successfully, you're ready to containerize your project.

2. Choose Your Astro Deployment Mode: Static or SSR

Before writing your Dockerfile, decide how your website should run.

Astro supports static generation and server-side rendering. Your Docker configuration will depend on this choice.

Static deploymentSSR deployment
Generates website files during the buildRenders pages when requests arrive
Uses generated HTML and assetsRuns a Node.js application
Does not require a Node.js server in productionRequires a Node.js runtime
Suitable for blogs, portfolios and marketing sitesSuitable for request-time pages and server endpoints

Which one should you choose?

Choose Static if your website can be generated during the build process. Choose SSR if you need request-time rendering, server-side endpoints, or other server-side functionality.

Remember that interactive browser-side components don't automatically require SSR.

Let's configure both options.

Static and SSR deployment architecture for Astro using Docker

3. Deploy a Static Astro Website Using Docker

For most content-focused websites, static deployment is the simpler approach.

Astro generates your production files inside the dist directory. Docker can then package those files into a lightweight Nginx container.

Comparison of static and server-side rendering Docker deployments for Astro

Step 1: Configure Astro

Open your astro.config.mjs file.

For a standard static project, make sure it uses static output:

import { defineConfig } from 'astro/config';
export default defineConfig({
output: 'static',
});

Keep your existing integrations and other configuration settings.

Step 2: Create a Dockerfile

Create a file named Dockerfile in your project's root directory.

Add the following configuration:

# Build the Astro website
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Serve the generated files using Nginx
FROM nginx:alpine AS runtime
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80

Here's what happens:

  • The first stage installs your dependencies and builds the Astro website.
  • Astro generates the production files inside dist.
  • The second stage copies only those generated files into an Nginx image.
  • Nginx serves the website over HTTP on port 80 inside the container.

This multi-stage approach keeps the final image focused on serving the generated website rather than carrying the entire Node.js build environment.

For more variations, see Astro's official Astro Docker deployment recipe.

Step 3: Create a .dockerignore File

Create another file named .dockerignore in the project root.

Add:

node_modules
dist
.git
.env
.env.*
.DS_Store

This prevents unnecessary files from entering the Docker build context.

If your application needs a particular environment file during the build, supply the required values securely rather than copying private credentials into the image.

Step 4: Build Your Docker Image

Now build the image:

Terminal window
docker build -t astro-static-site .

Docker will read your Dockerfile, install dependencies, build your Astro project, and create the final Nginx image.

Step 5: Run Your Container

Start the container:

Terminal window
docker run -d \
--name astro-static-site \
-p 8080:80 \
--restart unless-stopped \
astro-static-site

Open:

http://localhost:8080

You should now see your Astro website running inside a Docker container.

The 8080:80 mapping means port 8080 on your machine forwards traffic to port 80 inside the container.

That's your first Dockerized Astro deployment.

4. Deploy an Astro SSR Website Using Docker

What if your Astro website needs server-side rendering?

In that case, serving the generated files through Nginx alone isn't enough. You'll need a Node.js server to handle incoming requests.

Let's configure it.

Step 1: Install the Astro Node Adapter

Run:

Terminal window
npx astro add node

This installs the Node.js adapter and updates your Astro configuration.

For a standalone Node.js deployment, your configuration should include:

import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
export default defineConfig({
output: 'server',
adapter: node({
mode: 'standalone',
}),
});

Keep any existing integrations and settings your project needs.

Step 2: Create an SSR Dockerfile

Create or update your Dockerfile:

# Build stage
FROM node:22-bookworm-slim AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
RUN npm prune --omit=dev
# Production stage
FROM node:22-bookworm-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=4321
COPY --from=build --chown=node:node /app/package*.json ./
COPY --from=build --chown=node:node /app/node_modules ./node_modules
COPY --from=build --chown=node:node /app/dist ./dist
USER node
EXPOSE 4321
CMD ["node", "./dist/server/entry.mjs"]

What does this Dockerfile do?

  1. Installs your project dependencies.
  2. Builds the Astro application.
  3. Removes development-only dependencies.
  4. Copies the production output and dependencies into a separate runtime image.
  5. Runs the application as a non-root user.
  6. Starts the standalone Astro server on port 4321.

This example assumes the default Astro output directory, npm, a compatible Node adapter, and a project whose runtime dependencies are correctly declared in package.json.

If your project uses native dependencies or needs additional runtime files, adjust the Dockerfile accordingly.

Step 3: Build and Run the SSR Container

Build your image:

Terminal window
docker build -t astro-ssr-site .

Run the container:

Terminal window
docker run -d \
--name astro-ssr-site \
-p 4321:4321 \
--restart unless-stopped \
astro-ssr-site

Visit:

http://localhost:4321

Your Astro SSR website should now be running inside Docker.

Important: The application must listen on 0.0.0.0, not only localhost, so traffic can reach it from outside the container.

5. Use Docker Compose to Manage Your Astro Deployment

Running a container with docker run works well for testing. But for a repeatable deployment, Docker Compose makes configuration easier to manage.

Create a file named compose.yaml in your project directory.

For the SSR Dockerfile above, use:

services:
astro:
build:
context: .
dockerfile: Dockerfile
container_name: astro-website
restart: unless-stopped
ports:
- "127.0.0.1:4321:4321"
environment:
NODE_ENV: production
HOST: 0.0.0.0
PORT: 4321

This configuration:

  • Builds your Astro Docker image.
  • Starts the application as a container.
  • Restarts it automatically unless you stop it manually.
  • Makes the application available on the server's local port 4321.

Notice that the host port is bound to 127.0.0.1. This keeps the application port from being exposed directly to the public internet.

A reverse proxy such as Nginx or Caddy can receive public traffic and forward it to the container.

Start your application:

Terminal window
docker compose up -d --build

Check running containers:

Terminal window
docker compose ps

View application logs:

Terminal window
docker compose logs -f astro

To stop the application:

Terminal window
docker compose down

You now have a repeatable way to build, start, inspect, and stop your Astro deployment.

6. Deploy Your Astro Docker Container to a VPS

So far, we've run the website locally. Now let's make it accessible through your domain.

You'll need a VPS with Docker and Docker Compose installed. If you'd rather run Astro without containers, see how to self-host an Astro website directly on a VPS.

Steps to build and deploy an Astro website using Docker on a VPS

Step 1: Prepare Your Server

Connect to your server through SSH:

Terminal window
ssh username@your-server-ip

Make sure Docker and the Docker Compose plugin are installed and working:

Terminal window
docker --version
docker compose version

Follow Docker's official installation instructions for your server's Linux distribution if either command is unavailable.

Step 2: Transfer Your Project

Clone your project repository:

Terminal window
git clone https://github.com/your-username/your-astro-project.git
cd your-astro-project

Make sure your Dockerfile and Compose configuration are present.

For private repositories, configure secure Git access rather than placing credentials in the repository.

Step 3: Start the Deployment

Run:

Terminal window
docker compose up -d --build

Check the container:

Terminal window
docker compose ps

If it's running, your application should be available locally on the VPS at port 4321.

Step 4: Connect Your Domain and HTTPS

Your Astro container should not need to handle public HTTPS traffic directly.

Use a reverse proxy such as Nginx or Caddy to:

  • Receive requests for your domain.
  • Forward them to 127.0.0.1:4321.
  • Handle HTTPS certificates.
  • Redirect HTTP traffic to HTTPS.

Before enabling HTTPS, point your domain's DNS records to your VPS IP address and configure the reverse proxy.

For production, verify that the domain, certificate, proxy configuration, and application are all working correctly.

7. Update and Maintain Your Astro Docker Deployment

Deploying your website is only the first step. You'll also need a reliable way to publish updates.

Whenever you change your Astro project:

  1. Commit and push your latest changes.
  2. Pull the updated code onto your server.
  3. Rebuild the Docker image.
  4. Recreate the running container.
  5. Check the deployment logs and test the website.

For Docker Compose, you can use:

Terminal window
git pull
docker compose up -d --build

Check the application logs:

Terminal window
docker compose logs -f astro

For production, keep your environment configuration and secrets outside the image. Back up any persistent data your application uses, and test updates before replacing a working deployment.

Common Astro Docker Deployment Problems

ProblemWhat to check
Website isn't accessibleCheck port mapping and container status
Container exits immediatelyReview Docker logs and the start command
Astro build failsCheck Node.js compatibility and dependencies
SSR pages return errorsVerify the Node adapter and output configuration
Website works locally but not on VPSCheck host binding, firewall and reverse proxy
Environment variables are missingCheck whether values are needed at build time or runtime
Changes aren't appearingRebuild the image and recreate the container

A useful troubleshooting command is:

Terminal window
docker logs astro-website

For Compose deployments, use:

Terminal window
docker compose logs -f

These commands help you identify whether the issue comes from the application, build process, or container configuration.

Simplify Astro Deployment and Server Management with FlyWP

Docker gives you flexibility, but managing a production server involves more than building and running containers.

You still need to manage your server, configure websites, connect domains, monitor deployments, and handle updates.

If you're deploying multiple websites or managing infrastructure for clients, doing everything manually can become repetitive.

That's where FlyWP can help.

FlyWP supports Astro deployment through Git on your own VPS. You can connect a Git provider, select your Astro repository, configure the application, and choose between Static and Server runtime.

FlyWP dashboard showing Astro website deployment and management

Create an Astro site from Git in FlyWP and choose a Static or Server runtime.

With FlyWP, you can:

  • Deploy Astro projects through Git.
  • Choose Static or Server runtime.
  • Configure your build and start commands.
  • Manage Astro websites alongside WordPress sites.
  • Manage your deployments through a central dashboard.

Learn more about Astro deployment with FlyWP.

You don't have to follow a manual Dockerfile workflow for every Astro project. FlyWP offers a separate Git-based deployment workflow for supported Astro applications.

If you want to explore this approach, read our guide: How to Deploy an Astro Site Through Git Using FlyWP.

Ready to manage your Astro and WordPress websites from one place?

Explore FlyWP and see how it can simplify managing your own cloud infrastructure.

Frequently Asked Questions

How do I deploy an Astro website using Docker?

Create a Dockerfile for your Astro project, build a Docker image using docker build, and run it as a container. For static websites, use Nginx to serve the generated files. For SSR websites, configure Astro's Node adapter and run the generated Node.js server.

Does Astro support Docker?

Yes. Astro provides an official Docker recipe covering both static and server-rendered deployment approaches. You can use Docker to build and run Astro applications on your own server or supported cloud infrastructure.

Does Astro need Node.js in production?

Not always. A static Astro website can be served as generated HTML, CSS, JavaScript, and other assets without a running Node.js process. An SSR application needs a compatible server runtime, such as Node.js with Astro's Node adapter.

Can I use Docker Compose with Astro?

Yes. Docker Compose can define how your Astro container is built, configured, exposed, and restarted. It is useful for managing deployments on a VPS and keeping application configuration repeatable.

Can I deploy an Astro website on a VPS using Docker?

Yes. Install Docker and Docker Compose on your VPS, transfer your project, build the image, and start the container. Configure a reverse proxy and HTTPS to make the website accessible through your domain.

Is Docker required to host an Astro website?

No. Docker is optional. You can deploy static Astro output directly to a web server or use a supported hosting platform. Docker is useful when you want containerized deployment and more control over the application environment.

Can I deploy an Astro website without managing Docker manually?

Yes. You can use a deployment platform that supports Astro to simplify the process. FlyWP supports Git-based Astro deployment on your own VPS, with Static and Server runtime options.

Final Thoughts

Deploying Astro with Docker gives you a repeatable way to package and run your website on your own infrastructure.

For static projects, an Nginx-based container is usually the straightforward choice. For server-rendered applications, use Astro's Node adapter and a Node.js container.

Once your deployment is working, focus on keeping your images updated, securing your server, monitoring the application, and making future releases predictable.

And if you're managing multiple Astro and WordPress websites, consider using FlyWP to simplify the wider server and deployment workflow.

Explore FlyWP plans