This is how i build it
docker-compose.yml
version: '3'
services:
strapi:
container_name: strapi
build: .
image: mystrapi:latest
restart: unless-stopped
env_file: .env
environment:
DATABASE_CLIENT: ${DATABASE_CLIENT}
DATABASE_HOST: soraDB
DATABASE_NAME: ${DATABASE_NAME}
DATABASE_USERNAME: ${DATABASE_USERNAME}
DATABASE_PORT: ${DATABASE_PORT}
JWT_SECRET: ${JWT_SECRET}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
NODE_ENV: ${NODE_ENV}
links:
- strapiDB:strapiDB
volumes:
- ./:/srv/
- ./uploads:/srv//public/uploads
ports:
- '1337:1337'
networks:
- strapi
depends_on:
- strapiDB
strapiDB:
image: postgres:12.0-alpine
container_name: strapiDB
restart: unless-stopped
env_file: .env
environment:
POSTGRES_USER: ${DATABASE_USERNAME}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
volumes:
- ./data:/var/lib/postgresql/data/
ports:
- '5432:5432'
networks:
- strapi
networks:
strapi:
name: Strapi
driver: bridge
This will spin up a strapi instance with a postgres database.
You need to create an .env or use the one in strapi already.
From here you can build one just for the frontend, note the use of depends_on which tells docker it will wait for it to start.
Dockerfile
FROM node:14-alpine
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./package.json ./
COPY ./yarn.lock ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g
RUN yarn install
WORKDIR /opt/app
COPY ./ .
RUN yarn build
EXPOSE 1337
CMD ["yarn", "start"]
Both files needs to be be in the root of the strapi project.
Then you can use 0.0.0.0 or localhost as normal and no need to say http://strapi:1337 as it runs on localhost.
If this is running on a server then you use the IP or domain to the server.