Dockerize a Platformatic App
This guide explains how to create a new Platformatic DB app, which connects to a PostgreSQL database.
We will then create a
docker-compose.yml file that will run both services in separate containers
Generate a Platformatic DB App
Run this command in your terminal to start the Platformatic creator wizard:
npm create platformatic@latest
yarn create platformatic
pnpm create platformatic@latest
This interactive command-line tool will ask you some questions about how you'd like to set up your new Platformatic project. For this guide, select these options:
- Which kind of project do you want to create? => DB
- Where would you like to create your project? => quick-start
- Do you want to create default migrations? => Yes
- Do you want to create a plugin? => Yes
- Do you want to use TypeScript? => No
- Do you want to install dependencies? => Yes (this can take a while)
- Do you want to apply the migrations? => Yes
- Do you want to generate types? => Yes
- Do you want to create the github action to deploy this application to Platformatic Cloud dynamic workspace? => No
- Do you want to create the github action to deploy this application to Platformatic Cloud static workspace? => No
Once the wizard is complete, you'll have a Platformatic app project in the
quick-start, with example migration files and a plugin script.
Make sure you run the npm/yarn/pnpm command
install command manually if you
don't ask the wizard to do it for you.
Create Docker image for the Platformatic DB App
In this step you are going to create some files into the root project directory
.dockerignore- This file tells Docker to ignore some files when copying the directory into the image filesystem
start.sh- This is our entrypoint. We will run migrations then start platformatic
echo "Running migrations..." && \
npx platformatic db migrations apply && \
echo "Starting Platformatic App..." && \
Make sure you make this file executable with the command
chmod +x start.sh
Dockerfile- This is the file Docker uses to create the image
COPY . .
RUN npm install
COPY . .
CMD [ "./start.sh" ]
At this point you can build your Docker image with the command
$ docker build -t platformatic-app .
Create Docker Compose config file
docker-compose.yml is the configuration file for
docker-compose which will spin up containers for both PostgresSQL and our Platformatic App
A couple of things to notice:
- The Platformatic app is started only once the database container is up and running (
- The Platformatic app is linked with
postgresqlservice. Meaning that inside its container
ping postgresqlwill be resolved with the internal ip of the database container.
- The environment is taken directly from the
.envfile created by the wizard
You can now run your containers with
$ docker-compose up # (-d if you want to send them in the background)
Everything should start smoothly, and you can access your app pointing your browser to
To stop the app you can either press
CTRL-C if you are running them in the foreground, or, if you used the
-d flag, run
$ docker-compose down