postgresqldockerdocker-composegitlabdocker-volume

Docker volume is cleared on every restart via docker-compose on ubuntu


Docker volume is cleared on every restart via docker-compose on ubuntu server, but on my pc everything works properly. Volume always contains data, even after restart. How to solve this? Thanks.

My docker-compose file contains the following:

  db:
    image: postgres:14-alpine
    container_name: content_hunter_db
    privileged: true

    environment:
      POSTGRES_DB: "content_hunter"
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: "postgres"
      PGDATA: /var/lib/postgresql/data/

    ports:
      - "5432:5432"

    volumes:
      - content_hunter_volume:/var/lib/postgresql/data/:rw

    volumes:
        content_hunter_volume:
            name: "content_hunter_volume"

Part of my .gitlab-ci:

deploy:
  stage: deploy
  script:
    - echo "Deploying application..."
    - docker login -u "gitlab-ci-token" -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker-compose down
    - docker-compose up -d
    - echo "Application successfully deployed"

P.S

I'm using shell gitlab runner


Solution

  • Use docker compose instead of docker-compose