Belgacem ben ltaif (Gasston)

Frontend Developer at FunkyDev

Install Strapi v4 in Docker (without getting docked ๐Ÿณ)

Cover image for the article

All I wanted was to launch a nice little Strapi inside a Docker container.
I type docker-compose up... and BAM โ†’ Strapi v3 ๐Ÿ˜ฎ.

โ€œButโ€ฆ I asked for Strapi 4?!โ€

Spoiler: the official Docker image strapi/strapi โ†’ it's version 3 (and it's old ๐Ÿ˜…).

Don't panic. Let me show you how to properly install Strapi v4 in Docker, without losing your sanity.

Letโ€™s go ๐Ÿ‘‡

๐ŸŽฏ Why doesnโ€™t it work out of the box?

The Docker Hub image strapi/strapi was never updated for Strapi v4.
โ†’ It always gives you Strapi v3.6.8 (RIP ๐Ÿชฆ).

So if you want Strapi v4 + Docker โ†’ you gotta cheat a bit.

No worries, we love cheating in dev ๐Ÿ˜.

๐Ÿ—๏ธ The correct method โ†’ use Node.js as base + mount your Strapi project.

Instead of asking for a magic โ€œstrapi v4โ€ image,
โ†’ create your Strapi v4 project locally
โ†’ and run it inside a Node.js container.

Easy.

โœ… 1๏ธโƒฃ Create your Strapi v4 project locally

npx create-strapi@latest app
Enter fullscreen mode Exit fullscreen mode

(or yarn create strapi@latest app)

Boom, youโ€™ve got a fresh ./app folder with Strapi.

โœ… 2๏ธโƒฃ Write this magical docker-compose.yml

version: '3'

services:
  strapi:
    image: node:18-alpine
    container_name: techlink-strapi
    working_dir: /srv/app
    command: sh -c "yarn install && yarn build && yarn start"
    environment:
      DATABASE_CLIENT: postgres
      DATABASE_NAME: strapi
      DATABASE_HOST: postgres
      DATABASE_PORT: 5432
      DATABASE_USERNAME: strapi
      DATABASE_PASSWORD: strapi123
      NODE_ENV: production
    ports:
      - '1337:1337'
    volumes:
      - ./app:/srv/app
    depends_on:
      - postgres

  postgres:
    image: postgres:15
    container_name: techlink-postgres
    restart: always
    environment:
      POSTGRES_USER: strapi
      POSTGRES_PASSWORD: strapi123
      POSTGRES_DB: strapi
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:
Enter fullscreen mode Exit fullscreen mode

โš ๏ธ Important โ†’ the ./app folder must contain your pre-created Strapi v4 project (see step 1).

โœ… 3๏ธโƒฃ Launch Docker, captain

docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

๐ŸŽ‰ Done!
Your Strapi is available at:

๐Ÿ‘‰ http://localhost:1337/admin

(and this time, itโ€™s Strapi v4, not v3 ๐Ÿ˜‰)

๐Ÿ•ต๏ธ Why does it work?

  • We use node:18-alpine as the engine
  • We mount your local Strapi project inside the container
  • The container installs, builds, starts everything

No ghost official image needed.
YOU are the official image now ๐Ÿ˜Ž

๐Ÿ”ฅ Bonus option โ†’ a Dockerfile if you want a real Docker build

Want a โ€œclosedโ€ image? Add a Dockerfile:

FROM node:18-alpine

WORKDIR /srv/app

COPY . .

RUN yarn install
RUN yarn build

EXPOSE 1337

CMD ["yarn", "start"]
Enter fullscreen mode Exit fullscreen mode

Then adapt your docker-compose.yml:

strapi:
  build: .
  ports:
    - '1337:1337'
  depends_on:
    - postgres
  environment:
    DATABASE_CLIENT: postgres
    DATABASE_NAME: strapi
    DATABASE_HOST: postgres
    DATABASE_PORT: 5432
    DATABASE_USERNAME: strapi
    DATABASE_PASSWORD: strapi123
Enter fullscreen mode Exit fullscreen mode

โ†’ Docker will build it all in one go.

๐Ÿ“ TL;DR

โœ… strapi/strapi = Strapi v3 (DONโ€™T use it)
โœ… Create your Strapi v4 project locally
โœ… Use node:18-alpine + mounted volume
โœ… Or build a custom Dockerfile

There you go.

Now you can proudly say:

๐Ÿ‘‰ โ€œYes, I have Strapi v4 running in Docker. Not v3. No cheating.โ€


๐Ÿ’ฌ Need help with permissions, relations, API? Ping me ๐Ÿ˜‰
Or share this article with your buddy struggling on Stack Overflow ๐Ÿซ 

TechLink powered. Peace โœŒ๏ธ

๐Ÿ’ป FunkyDev

๐Ÿš€ Built with caffeine and cosmic vibes. ๐Ÿ’ก Don't forget to deploy your dreams!

๐Ÿ” Copyleft 2025 โ€“ Made to remix ๐ŸŽง