AlanPadi95/docker-awx-stack

[BUG] initdb: error: directory "/var/lib/postgresql/data" exists but is not empty If you want to create a new database system, either remove or empty the directory "/var/lib/postgresql/data" or run initdb with an argument other than "/var/lib/postgresql/data"

AlanPadi95 opened this issue · 1 comments

Problem description

On CentOS, when the stack is going to be deployed, the PostgreSQL service is always stopped because of an error creating the DB os using an existing DB.

Extra information

On MacOs, when I type docker stack deploy -c docker-compose.yml awx all services are up & running.

MacOS Docker version: Docker version 19.03.5, build 633a0ea
MacOS Docker Compose version: docker-compose version 1.25.4, build 8d51620a

Stack configuration

version: '3.7'
services:

  web:
    image: ansible/awx_web:9.1.0
    depends_on:
      - rabbitmq
      - memcached
      - postgres
    ports:
      - "8052:8052"
    hostname: awxweb
    user: root
    deploy:
      mode: replicated
      replicas: 1
    volumes:
      - "./config/SECRET_KEY.txt:/etc/tower/SECRET_KEY"
      - "./config/environment.sh:/etc/tower/conf.d/environment.sh"
      - "./config/credentials.py:/etc/tower/conf.d/credentials.py"
      - "./config/nginx.conf:/etc/nginx/nginx.conf:ro"
      - "./projects:/var/lib/awx/projects:rw"
      - "./inventories:/var/lib/awx/inventories:rw"
      # - "/etc/pki/ca-trust/source/anchors:/etc/pki/ca-trust/source/anchors:ro' }}"
      # - "ssl_certificate:/etc/nginx/awxweb.pem:ro"
    environment:
      http_proxy: ''
      https_proxy: ''
      no_proxy: ''

  task:
    image: ansible/awx_task:9.1.0
    depends_on:
      - rabbitmq
      - memcached
      - web
      - postgres
    hostname: awx
    user: root
    deploy:
      mode: replicated
      replicas: 1
    volumes:
      - "./config/SECRET_KEY.txt:/etc/tower/SECRET_KEY"
      - "./config/environment.sh:/etc/tower/conf.d/environment.sh"
      - "./config/credentials.py:/etc/tower/conf.d/credentials.py"
      - "./projects:/var/lib/awx/projects:rw"
      # - "/etc/pki/ca-trust/source/anchors:/etc/pki/ca-trust/source/anchors:ro"
      # - "ssl_certificate:/etc/nginx/awxweb.pem:ro"
    environment:
      http_proxy: ''
      https_proxy: ''
      no_proxy: ''

  rabbitmq:
    image: ansible/awx_rabbitmq
    ports:
      - "5672:5672"
      - "15672:15672"
    deploy:
      mode: replicated
      replicas: 1
    environment:
      RABBITMQ_DEFAULT_VHOST: "awx"
      RABBITMQ_DEFAULT_USER: "guest"
      RABBITMQ_DEFAULT_PASS: "changeme"
      RABBITMQ_ERLANG_COOKIE: "cookiemonster"
      http_proxy: ''
      https_proxy: ''
      no_proxy: ''

  memcached:
    image: "memcached"
    ports:
      - "11211:11211"
    deploy:
      mode: replicated
      replicas: 1
    environment:
      http_proxy: ''
      https_proxy: ''
      no_proxy: ''

  postgres:
    image: postgres
    user: root
    ports:
      - "5432:5432"
    deploy:
      mode: replicated
      replicas: 1
    volumes:
      - ./postgres/data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: awx
      POSTGRES_PASSWORD: changeme
      POSTGRES_DB: awx
      PGDATA: /var/lib/postgresql/data/pgdata
      http_proxy: ''
      https_proxy: ''
      no_proxy: ''
  
  metricbeat:
    image: docker.elastic.co/beats/metricbeat:${ELASTIC_VERSION:-7.5.2}
    user: root
    environment:
      - KIBANA_HOST='${KIBANA_HOST}:5601'
      - ELASTIC_HOST='${ELASTIC_HOST}:9200'
      - ELASTICSEARCH_USERNAME=${ELASTICSEARCH_USERNAME-elastic}
      - ELASTICSEARCH_PASSWORD=${ELASTICSEARCH_PASSWORD-changeme}
      - AWX_DB_USER=${AWX_DB_USER:-awx}
      - AWX_DB_PASS=${AWX_DB_PASS:-changeme}
      - AWX_RABBITMQ_USER=${AWX_RABBITMQ_USER:-guest}
      - AWX_RABBITMQ_PASS=${AWX_RABBITMQ_PASS:-changeme}
    configs:
      - source: metricbeat_config
        target: /usr/share/metricbeat/metricbeat.yml
    command: -system.hostfs=/hostfs
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro
      - /proc:/hostfs/proc:ro
      - /:/hostfs:ro
      - ./metricbeat/dashboards:/usr/share/metricbeat/kibana/7/dashboard:ro
    deploy:
      mode: replicated
      replicas: 1

configs:
  metricbeat_config:
    file: ./metricbeat/config/metricbeat.yml

Docker setup

Docker version 19.03.5, build 633a0ea
docker-compose version 1.25.0, build 0a186604

Docker logs

initdb: error: directory "/var/lib/postgresql/data" exists but is not empty If you want to
create a new database system, either remove or empty the directory
"/var/lib/postgresql/data" or run initdb with an argument other than
"/var/lib/postgresql/data". initdb: error: directory "/var/lib/postgresql/data" exists but
is not empty If you want to create a new database system, either remove or empty
the directory "/var/lib/postgresql/data" or run initdb with an argument other than
"/var/lib/postgresql/data". The files belonging to this database system will be owned
by user "postgres". This user must also own the server process.

[SOLVED]

Change the PGDATA environment variable from /var/lib/postgresql/data/pgdata to /tmp

version: '3.7'
services:

  web:
    image: ansible/awx_web:9.1.0
    depends_on:
      - rabbitmq
      - memcached
      - postgres
    ports:
      - "8052:8052"
    hostname: awxweb
    user: root
    deploy:
      mode: replicated
      replicas: 1
    volumes:
      - "./config/SECRET_KEY.txt:/etc/tower/SECRET_KEY"
      - "./config/environment.sh:/etc/tower/conf.d/environment.sh"
      - "./config/credentials.py:/etc/tower/conf.d/credentials.py"
      - "./config/nginx.conf:/etc/nginx/nginx.conf:ro"
      - "./projects:/var/lib/awx/projects:rw"
      - "./inventories:/var/lib/awx/inventories:rw"
      # - "/etc/pki/ca-trust/source/anchors:/etc/pki/ca-trust/source/anchors:ro' }}"
      # - "ssl_certificate:/etc/nginx/awxweb.pem:ro"
    environment:
      http_proxy: ''
      https_proxy: ''
      no_proxy: ''

  task:
    image: ansible/awx_task:9.1.0
    depends_on:
      - rabbitmq
      - memcached
      - web
      - postgres
    hostname: awx
    user: root
    deploy:
      mode: replicated
      replicas: 1
    volumes:
      - "./config/SECRET_KEY.txt:/etc/tower/SECRET_KEY"
      - "./config/environment.sh:/etc/tower/conf.d/environment.sh"
      - "./config/credentials.py:/etc/tower/conf.d/credentials.py"
      - "./projects:/var/lib/awx/projects:rw"
      # - "/etc/pki/ca-trust/source/anchors:/etc/pki/ca-trust/source/anchors:ro"
      # - "ssl_certificate:/etc/nginx/awxweb.pem:ro"
    environment:
      http_proxy: ''
      https_proxy: ''
      no_proxy: ''

  rabbitmq:
    image: ansible/awx_rabbitmq
    ports:
      - "5672:5672"
      - "15672:15672"
    deploy:
      mode: replicated
      replicas: 1
    environment:
      RABBITMQ_DEFAULT_VHOST: "awx"
      RABBITMQ_DEFAULT_USER: "guest"
      RABBITMQ_DEFAULT_PASS: "changeme"
      RABBITMQ_ERLANG_COOKIE: "cookiemonster"
      http_proxy: ''
      https_proxy: ''
      no_proxy: ''

  memcached:
    image: "memcached"
    ports:
      - "11211:11211"
    deploy:
      mode: replicated
      replicas: 1
    environment:
      http_proxy: ''
      https_proxy: ''
      no_proxy: ''

  postgres:
    image: postgres
    user: root
    ports:
      - "5432:5432"
    deploy:
      mode: replicated
      replicas: 1
    volumes:
      - ./postgres/data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: awx
      POSTGRES_PASSWORD: changeme
      POSTGRES_DB: awx
      PGDATA: /tmp
      http_proxy: ''
      https_proxy: ''
      no_proxy: ''
  
  metricbeat:
    image: docker.elastic.co/beats/metricbeat:${ELASTIC_VERSION:-7.5.2}
    user: root
    environment:
      - KIBANA_HOST='${KIBANA_HOST}:5601'
      - ELASTIC_HOST='${ELASTIC_HOST}:9200'
      - ELASTICSEARCH_USERNAME=${ELASTICSEARCH_USERNAME-elastic}
      - ELASTICSEARCH_PASSWORD=${ELASTICSEARCH_PASSWORD-changeme}
      - AWX_DB_USER=${AWX_DB_USER:-awx}
      - AWX_DB_PASS=${AWX_DB_PASS:-changeme}
      - AWX_RABBITMQ_USER=${AWX_RABBITMQ_USER:-guest}
      - AWX_RABBITMQ_PASS=${AWX_RABBITMQ_PASS:-changeme}
    configs:
      - source: metricbeat_config
        target: /usr/share/metricbeat/metricbeat.yml
    command: -system.hostfs=/hostfs
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro
      - /proc:/hostfs/proc:ro
      - /:/hostfs:ro
      - ./metricbeat/dashboards:/usr/share/metricbeat/kibana/7/dashboard:ro
    deploy:
      mode: replicated
      replicas: 1

configs:
  metricbeat_config:
    file: ./metricbeat/config/metricbeat.yml