Question

Docker Strapi on Droplet - Content type and admin users disappears after a while

Posted May 2, 2021 994 views
MongoDBDigitalOceanDockerDigitalOcean DropletsStrapi

Hi everyone,
I have been trying for a while to set up a small droplet with a docker Strapi CMS using docker mongodb. For this i am using docker-compose and it seems to work great. I can make it run and access it like i should on the Droplet but after a while it seems like the files automatically disappears. This means that when i load Strapi again, the admin user doesn’t exist and i have to create all the content types again from scratch.

It does not happen because i shut down the containers, it simply happens at some point so i am wondering if it could be because DigitalOcean is restarting and because of that deletes the files that Strapi have made such as the user and content types. I have never had problems with MongoDB not remembering data, it is only now that i use Strapi as a CMS that it has become a problem.

When I use docker-compose the containers are building correct and Strapi is not rebuilding the project, so i conclude i have mounted the volume correctly. As mentioned it seems to be something with the droplet or DigitalOcean.

Here is my docker compose code for Strapi. Maybe it is mounted correctly but something else might be wrong so it deletes the files? If any of you know how to get around this or how to make the files consistent even though DigitalOcean or the droplet restarts automatically, then please share it with me as I can’t find any solution to this problem.


version: '3'

services:
  nodejs:
    build:
      context: .
      dockerfile: Dockerfile
    image: nodejs
    container_name: nodejs
    ports:
      - 8081:8081
    restart: unless-stopped
    networks:
      - app-network

  webserver:
    image: nginx:latest
    container_name: webserver
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - web-root:/var/www/html
      - ./server/nginx-conf:/etc/nginx/conf.d
      - certbot-etc:/etc/letsencrypt
      - certbot-var:/var/lib/letsencrypt
    depends_on:
      - nodejs
    networks:
      - app-network

  certbot:
    image: certbot/certbot
    container_name: certbot
    volumes:
      - certbot-etc:/etc/letsencrypt
      - certbot-var:/var/lib/letsencrypt
      - web-root:/var/www/html
    depends_on:
      - webserver
    command: certonly --webroot --webroot-path=/var/www/html --email E-MAIL --agree-tos --no-eff-email --force-renewal -d DOMAIN

  strapi:
    container_name: strapi
    image: strapi/strapi
    environment:
      - APP_NAME=strapi-app
      - DATABASE_CLIENT=mongo
      - DATABASE_HOST=db
      - DATABASE_PORT=27017
      - DATABASE_NAME=strapi
      - DATABASE_USERNAME=
      - DATABASE_PASSWORD=
      - AUTHENTICATION_DATABASE=strapi
    ports:
      - 1337:1337
    volumes:
      - strapi-app:/srv/app
    depends_on:
      - db
    networks:
      - app-network

  db:
    container_name: mongo
    image: mongo
    environment:
      - MONGO_INITDB_DATABASE=strapi
    ports:
      - 27017:27017
    volumes:     
      - dbdata:/data/db
    restart: always
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

volumes:
  dbdata:
  node_modules:
  certbot-etc:
  certbot-var:
  strapi-app:
  web-root:
    driver: local
    driver_opts:
      type: none
      device: /
      o: bind

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers
Show answer This answer has been marked as resolved by michaelandersen93.

wow, unfortunately i don’t have idea