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
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!
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.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Click below to sign up and get $200 of credit to try our products over 60 days!