DEV Community

Cover image for Building a Local Development Environment: Running a Next.js Full-Stack App with PostgreSQL and Minio S3 Using Docker

Building a Local Development Environment: Running a Next.js Full-Stack App with PostgreSQL and Minio S3 Using Docker

Alex on January 06, 2024

Table of Contents Introduction Prerequisites Building a local development environment 1. Create a Next.js application 2. Configure N...
Collapse
 
proteusiq profile image
Prayson Wilfred Daniel • Edited

Nice 👌🏾. We could also pass secrets environments variables not plainly with something like …?


version: "3.9"
services:
  web:
    build:
      context: ../
      dockerfile: compose/web.Dockerfile
      args:
        NEXT_PUBLIC_CLIENTVAR: "clientvar"
    ports:
      - 3000:3000
    volumes:
      - ../:/app
    environment:
      - DATABASE_URL=postgresql://postgres:postgres@db:5432/myapp-db?schema=public
      - S3_ENDPOINT=minio
      - S3_PORT=9000
      - S3_ACCESS_KEY=minio
      - S3_SECRET_KEY_FILE=/run/secrets/s3_secret_key
      - S3_BUCKET_NAME=s3bucket
    secrets:
      - s3_secret_key
    depends_on:
      - db
      - minio
  db:
    image: postgres:15.3
    container_name: postgres
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD_FILE: /run/secrets/db_password
      POSTGRES_DB: myapp-db
    volumes:
      - postgres-data:/var/lib/postgresql/data
    secrets:
      - db_password
    restart: unless-stopped
  minio:
    image: bitnami/minio:latest
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - minio_storage:/data
    secrets:
      - s3_secret_key

secrets:
  db_password:
    file: ./db_password.txt  # Path to the file containing the DB password
  s3_secret_key:
    file: ./s3_secret_key.txt  # Path to the file containing the S3 secret key

volumes:
  postgres-data:
  minio_storage:
Enter fullscreen mode Exit fullscreen mode

Nice 😊 work!

Collapse
 
alexefimenko profile image
Alex • Edited

Thanks!

Right, you should never ever add real API keys or secrets in config files that are stored on GitHub. If you want to use other secrets, like GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET, you should store them in .env file and add it to .gitignore. Then you can use them in docker-compose.yml file like this:

    environment:
      - ...
      - GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
      - GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
Enter fullscreen mode Exit fullscreen mode

And run docker-compose like this:

docker-compose -f compose/docker-compose.yml --env-file .env up
Enter fullscreen mode Exit fullscreen mode
Collapse
 
proteusiq profile image
Prayson Wilfred Daniel • Edited

Totally. These files are not to be committed 🤭. By docker compose secrets, the sensitive variables are not stored as plain texts.

Collapse
 
dpark profile image
Dan

Thanks for this post!

Whoa t3.app is neat, makes the set up super simple. Curious for thoughts on something I'm working on which is probably overbuilt for this type of tutorial: github.com/kurtosis-tech/kurtosis

Collapse
 
alexefimenko profile image
Alex

Wow, Kurtosis is a great project!
I definitely need some time to learn more about it, thanks for sharing!

Collapse
 
dpark profile image
Dan

For sure! Please feel free to hmu if you have any feedback or questions :)

Collapse
 
dipayansukul profile image
Dipayan Sukul

Very nicely written and described

Collapse
 
saruf_ratul profile image
Saruf Ratul

Good one

Collapse
 
dev_sd profile image
Soumajit Das

Really awesome post.

Collapse
 
twdor profile image
Adrian Ghitescu

Niceeee 😊 !!!

Collapse
 
makershihab profile image
Maker Shihab

Nice 🌺 work!

Collapse
 
random_ti profile image
Random

Handy Tutorial Thanks for sharing this 🤝

Collapse
 
john90 profile image
John bobby

Awesome 😎

Collapse
 
andrewbuk profile image
Andrew Buk

Good stuff. Thanks

Collapse
 
nxquan profile image
nxquan

Good job!

Some comments have been hidden by the post's author - find out more