Question

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

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

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Accepted Answer

I finally figured it out! Unfortunately it happened because of an automatic script hacking my MongoDB database. In the docker-compose above i am exposing port 27017, and apparently the script takes advantage of that. When i looked into the database i saw a readme telling me to transfer bitcoins to get back my data (which i did not do).

Instead I took away ports in DB so the ports wouldnt be exposed, and then made sure it was attached to the network. When it is attached to the network the ports will be accessible to everything inside the network.

Since this change i haven’t had a single problem with Strapi or MongoDB.

wow, unfortunately i don’t have idea

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel