Data get's deleted when strapi container restarts

Hello @Eventyret I am using AWS(ECR)+ AWS (RDS) +AWS(ECS) for runnung strapi but when i re run the task my saved data get’s deleted .

Here is my Dockerfile

FROM node:16

ARG NODE_ENV=development

ENV NODE_ENV=${NODE_ENV}

WORKDIR /opt/

COPY ./package.json ./yarn.lock ./

ENV PATH /opt/node_modules/.bin:$PATH

RUN yarn config set network-timeout 600000 -g && yarn install

WORKDIR /opt/app

COPY ./ .

# Default databse name for rds aws is postgres

# ENV PATH /opt/.env:$PATH

`RUN yarn add pg

RUN yarn build

EXPOSE 1337

CMD ["yarn", "develop"]`

Here is my database.ts file


export default ({ env }) => ({
    connection: {
        client: 'postgres',
        connection: {
            host: env('DATABASE_HOST', process.env.DATABASE_HOST),
            port: env.int('DATABASE_PORT', 5432),
            database: env('DATABASE_NAME', process.env.DB_NAME),
            user: env('DATABASE_USERNAME', process.env.DATABASE_USERNAME),
            password: env('DATABASE_PASSWORD', process.env.DATABASE_PASSWORD),
            ssl: env.bool('DATABASE_SSL', false),
        },
        useNullAsDefault: true,
    },
});

this is my .dockerignore file

.tmp/

.cache/

.git/

dist/

node_modules/

Please provide some solution .

Do you have any other database.ts files per environment ?
Also it’s not recommended to run develop in a production enviroment.

no i have only this database.ts file i am just using for development environment .

what should i change in this dockerfile ?

It’s not the dockerfile, all i’m saying is don’t use develop.
Like if you are developing then run it locally with develop.

If it’s in a container it should be in production mostly.

You should configure environments per case.
So creating config/env/X/database.ts etc :slight_smile:

Don’t think it’s anything wrong with your dockerfile tbh

so how can i add content type builder r plugins while it is running in container ?

If it runs in a container you need to use things like docker-compose and bind-mount the API folder. etc
If it’s a new collection.
If it’s just data you can just add data as normal.

@Eventyret images that are saved in my data get deleted after re run the container

I think you need to bind mount the uploads folder then if you are talking about “images” which people upload etc.
Else it’s stored inside the container, you remove the container the images goes, and the database entry exists.

@Eventyret can you please elaborate how we can bind mount the uploads folder while we are saving images it should be saved in database .

@Eventyret images are saving in media library after uploading .

@Eventyret i am facing this issue when i am hosting strapi on ecs using ecr through docker image .

even im facing this issue

So most of the time when people get this issue, it’s one of the following scenario:

You are running docker with development and using sqlite. To fix this make sure you are running it with production and not development Also make sure your config folder has two settings, 1 for development 1 for production.

The important thing here is, if you are using sqlite in development, when you restart the container the sqlite is deleted and recreated. Meaning you loose the data.

The data should not just delete itself.

When it comes to images not saving, it’s kind of the same scenario, but you need to bind-mount the public folder on the server so you have persistent storage. It’s recommended when using docker to not use bind mounts, rather use a upload service like cloudinary, S3 etc. to store your uploads.

This issue still persist.
I’m using PostgreSQL as database on both Mac and Ubuntu.
I don’t have any docker environment set, nor something custom outside Strapi defaults.

In my case all relations and role settings are deleted in development.
Every time I run the development environment I have to re-set all the relations again and again.
I’m currently using Strapi 4.7.1 and the issue exists from version 4.6.0 onwards.

1 Like

Have you tried 4.8.1 ?
Seems they did some fixes

@Eventyret I haven’t yet, I didn’t even know that there is v4.8.x available :slight_smile:

Thanks for the update, I will check it.

We’re facing the same issue. Random parts of data dissappear. It’s not whole tables, just some fields, and the config part of fields. For example, when we make changes to the Content Type layout, some fields lose the config, and the content disappears as well.

We’ve had it happen 3 times in the past 4 months!!! Absolutely unacceptable. We are 100% using Postgres DB, both the DB and Strapi are hosted on Heroku. We’re using NextJS on Vercel to pull the data from Strapi and build a static site, but random parts of data disappear.

We’re even lost some images on some content types, but when I go check the files_related_morphs table, I can still see all of the images related to content types there, but it doesn’t appear in the Content Editor nor the API…

Horrible. Never using Strapi for production sites again in the future.

1 Like

Thank you for your feedback :pray: @gmenih
One question I have is regarding your images. What type of provider are you using to upload images?
Are you using local upload provider by any chance ? :slight_smile:

No, we’re using the S3 provider.