Deploy
Deploy with Dockerfile

Deploying with Dockerfile

Normally, you don't need to write a Dockerfile by yourself. Zeabur currently provides fast deployment methods for various popular frameworks, but if your project is not using these frameworks or you want to define your own deployment method, you can use a Dockerfile to deploy it.

⚠️

Zeabur currently only supports Dockerfile deployment and does not provide Docker Compose deployment.

Creating a Dockerfile

Create a file named Dockerfile or dockerfile in the root directory of your project and write your deployment method in it. Finally, make sure you have exposed the corresponding PORT.

Zeabur will automatically detect if your project has a Dockerfile. If so, it will deploy your project using Docker.

After the deployment starts, you can see the Docker icon above, which means your project has been deployed using Docker.

docker-deploy

Environment Variables

If your Dockerfile needs to use environment variables, you can click Environment Variables on the service page to add them. For more settings, please refer to Environment Variables.

Environment Variables

If your Dockerfile is written in one stage, or if your environment variables only need to be used in the final stage, you don't need to manually write ENV. Zeabur will automatically add it for you.

ARG

However, if your Dockerfile is written in multiple stages (multi-stage (opens in a new tab)), and you need to set environment variables before building, you can use ARG to set them.

Here, we take nodejs and nginx as an example to write a Dockerfile for deployment.

FROM node:18-alpine AS builder
 
WORKDIR /app
COPY . .
 
## The `BUILDTIME_ENV_EXAMPLE` here will be set before building automatically
ARG BUILDTIME_ENV_EXAMPLE
ENV BUILDTIME_ENV_EXAMPLE=${BUILDTIME_ENV_EXAMPLE}
 
RUN npm install && \
    npm run build
 
FROM nginx:alpine
 
COPY nginx.conf /etc/nginx/conf.d/configfile.template
COPY --from=builder /app/dist /usr/share/nginx/html
 
ENV \
    PORT=8080 \
    HOST=0.0.0.0
 
EXPOSE 8080
 
CMD sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"

Creating Dockerfiles for the specific services in a Monorepo

If you want to deploy different projects in a monorepo, you can create Dockerfile.[service-name] (or [service-name].Dockerfile) and deploy the specified Dockerfile using the service name.

For example, if you want to deploy three microservices that use the same Git Repository, you can name your Dockerfiles as follows:

  • Dockerfile.storage (or storage.Dockerfile): deploys the Node.js storage microservice
  • Dockerfile.discord (or discord.Dockerfile): deploys the Node.js discord microservice
  • Dockerfile.frontend (or frontend.Dockerfile): deploys the Next.js frontend frontend

After deploying your project on Zeabur, navigate to "Settings" → "Service Name" and change the value to the desired service name (e.g., storage, discord, or frontend) as shown in the above example.

specify-service-name

Click "Redeploy" to redeploy the project, and you will see your desired service deployed. You can also set Watch Paths to trigger deployment only when the corresponding files are modified.

Docker Compose

Zeabur currently only supports Dockerfile deployment and does not provide Docker Compose deployment.