Add Docker file to your Payload code
Self hosted PayloadCMS and PostgreSQL website on Docker
1 min read
Published Jun 17 2025, updated Jun 19 2025
Guide Sections
Guide Comments
Now we need to add a docker file to the root of your Payload website code.
First we need to set the standalone flag in the next.config.mjs
file at the route of the project:
/next.config.mjs
If you have other config already then merge appropriately.
Then you need to add a new script line in the package.json
file runs both database migrate and then build, call it ci as thats what we will reference in the docker file when building:
/package.json
Next add a Dockerfile to the route of the project:
/Dockerfile
This is a multi-stage build file that will create a small final image size, and will also run the data base migrations as part of the build process.
In order to build the project in the docker file, the payload secret and database connection string env values are both required, so we will pass them in from GitHub actions as build arguments, however they will not be present in the final image and will be set in Docker/Portainer with the other env values when deploying the service.