django docker-compose当我在做“ docker-compose down”然后再次“ up”时,从mongo数据库中删除数据

时间:2018-11-21 06:13:34

标签: python django docker

DockerFile:

    FROM python:3.6

    WORKDIR /usr/src/jobsterapi
    COPY ./ ./
    RUN pip install -r requirements.txt

    CMD ["/bin/bash"]

docker-compose.yml

    version: "3"

    services:
      jobster_api:
        container_name: jobster
        build: ./
        # command: python manage.py runserver 0.0.0.0:8000
        command: "bash -c 'python src/manage.py makemigrations --no-input && python src/manage.py migrate --no-input && python src/manage.py runserver 0.0.0.0:8000'"
        working_dir: /usr/src/jobster_api
        environment:
          REDIS_URI: redis://redis:6379
          MONGO_URI: mongodb://jobster:27017
        ports:
          - "8000:8000"
        volumes:
          - ./:/usr/src/jobster_api
        links:
          - redis
          - elasticsearch
          - mongo


      #redis
      redis:
        image: redis
        environment:
          - ALLOW_EMPTY_PASSWORD=yes
        ports:
          - "6379:6379"

      elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.5.0
        ports:
          - "9200:9200"
          - "9300:9300"

      mongo:
        image: mongo
        ports:
          - "27017:27017"

我已经使用以下docker-compose在docker内部使用mongodb设置了django 命令。一切正常。但是当我添加任何记录时 使用“ docker exec -it'img id'/ bin / bash”,它正在插入数据(我尝试为Django创建超级用户 管理面板)。但是,当我在“ docker-compose down”之后再次使它“ docker-compose up”时,它是 从数据库中删除所有显示空记录的数据。因此我下次也无法访问管理面板。

请看看......

1 个答案:

答案 0 :(得分:0)

添加卷
mongo:
    image: mongo
    ports:
      - "27017:27017"
    volumes:
      - insert_mongos_stored_area

https://docs.docker.com/storage/volumes/