Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I retain my content types within a dockerized strapi

Tags:

docker

strapi

I've been using strapi for docker (https://github.com/strapi/strapi-docker), but whenever I rebuild my container the data all disappears. I can still see it in the database, but the admin isn't recognizing it.

I tried recreating the content type, and then the records from the database appeared, but when I rebuild the container again the content type disappears

Where are content definitions stored? Is this a bug with the app? (I think strapi-docker is using an alpha release)

How to I get strapi to retain my content definitions in the database, so I can use a stateless container?

UPDATE

I tried looking at the attached volume -

  api:
    build: .
    env_file: './dev.env'
    ports:
      - 1337:1337
    volumes:
      - ./strapi-app:/usr/src/api/strapi-app
      #- /usr/src/api/strapi-app/node_modules
    restart: always

But there's nothing in it -

Aidans-MacBook:strapi-docker aidan$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                   PORTS                    NAMES
02b098286ada        strapi-docker_api   "docker-entrypoint.s…"   24 minutes ago      Up 5 minutes (healthy)   0.0.0.0:1337->1337/tcp   strapi-docker_api_1
Aidans-MacBook:strapi-docker aidan$ docker inspect -f "{{.Mounts}}" 02b098286ada
[{bind  /Users/aidan/Documents/Code/beefbook/strapi-docker/strapi-app /usr/src/api/strapi-app  rw true rprivate}]
Aidans-MacBook:strapi-docker aidan$ ls /Users/aidan/Documents/Code/beefbook/strapi-docker/strapi-app
Aidans-MacBook:strapi-docker aidan$ 
like image 442
Aidan Ewen Avatar asked Sep 04 '19 16:09

Aidan Ewen


2 Answers

you need to mount the directory to keep the file persistent.

- ./strapi-app:/usr/src/api/strapi-app For application

- ./db:/data/db For DB


version: '3'

services:
  api:
    build: .
    image: strapi/strapi
    environment:
      - APP_NAME=strapi-app
      - DATABASE_CLIENT=mongo
      - DATABASE_HOST=db
      - DATABASE_PORT=27017
      - DATABASE_NAME=strapi
      - DATABASE_USERNAME=
      - DATABASE_PASSWORD=
      - DATABASE_SSL=false
      - DATABASE_AUTHENTICATION_DATABASE=strapi
      - HOST=localhost
    ports:
      - 1337:1337
    volumes:
      - ./strapi-app:/usr/src/api/strapi-app
      #- /usr/src/api/strapi-app/node_modules
    depends_on:
      - db
    restart: always

  db:
    image: mongo
    environment:
      - MONGO_INITDB_DATABASE=strapi
    ports:
      - 27017:27017
    volumes:
      - ./db:/data/db
    restart: always

Run the docker-compose up and you will see the data is now has been persistent.

updated:

After investigation by @Aidan

it's used the APP_NAME env var (the default is "strapi-app"). so the correct mount is /usr/src/api/beef-content (since, in my case, the APP_NAME is beef-content). I'll use that to mount my volume

like image 99
Adiii Avatar answered Oct 21 '22 19:10

Adiii


I may have a solution with my project "strapidocker-tools": https://github.com/OliCpg/strapidocker-tools

This will let you backup, move and restore full dockerised strapi project.

Be aware that it will work with two docker containers named strapi and strapi_db. You should not rename them (i'll change that later on). They get recreated upon restore.

Still a work in progress and not very elegant at the present time but it works for me.

Feedback is welcome.

like image 1
Olibe Avatar answered Oct 21 '22 17:10

Olibe