Запуск контейнера с базами данных
$ cd /data/agis/db $ docker-compose -f agis-db.yml up -d Creating agis-postgis-db ... done Creating agis-elastic-db ... done Creating agis-mongo-db ... done $ docker-compose -f agis-db.yml ps -a Name Command State Ports ----------------------------------------------------------------------------------- agis-elastic-db /bin/bash bin/es-docker Up (healthy) 9200/tcp, 9300/tcp agis-mongo-db docker-entrypoint.sh mongod Up (healthy) 27017/tcp agis-postgis-db docker-entrypoint.sh postgres Up (healthy) 5432/tcp
Перезапуск отдельной базы данных
$ docker-compose -f agis-db.yml restart agis-mongo-db
Остановка контейнеров с базами данных
$ docker-compose -f agis-db.yml down -v Stopping agis-mongo-db ... done Stopping agis-postgis-db ... done Stopping agis-elastic-db ... done Removing agis-mongo-db ... done Removing agis-postgis-db ... done Removing agis-elastic-db ... done Network agis-net is external, skipping $ docker-compose -f agis-db.yml ps Name Command State Ports ------------------------------
$ su - agis $ sudo useradd -r -u 999 -U agis-db $ sudo useradd -r -u 1000 -U elasticsearch $ mkdir -p /data/agis/db/agis-elastic-db/db $ sudo chown elasticsearch:root /data/agis/db/agis-elastic-db/db
Docker-compose для запуска баз данных mongo, elastic и postgresql
Создать файл /data/agis/db/agis-db.yml:
$ cat agis-db.yml version: '2.4' services: agis-mongo-db: image: "mongo:4.4" user: "1000:1000" container_name: agis-mongo-db #Вкл авторизацию: command: [--auth] # command: [--auth] volumes: - ./agis-mongo-db/db:/data/db ports: - "40500:27017" restart: on-failure cpus: 2 mem_limit: 10gb healthcheck: test: echo 'db.stats().ok' | mongo localhost:27017/just4testNur --quiet interval: 5s timeout: 5s retries: 12 agis-elastic-db: image: "docker.elastic.co/elasticsearch/elasticsearch:5.6.4" user: '1000:1000' container_name: agis-elastic-db volumes: - ./agis-elastic-db/db:/usr/share/elasticsearch/data ports: - "40501:9200" - "40502:9300" environment: - discovery.type=single-node - xpack.security.enabled=false restart: on-failure cpus: 1 mem_limit: 4gb healthcheck: test: curl -s http://localhost:9200 >/dev/null; if [[ $$? == 52 ]]; then echo 0; else echo 1; fi interval: 30s timeout: 10s retries: 5 agis-postgis-db: image: postgis/postgis:12-master user: '1000:1000' container_name: agis-postgis-db volumes: - ./agis-postgis-db/data:/var/lib/postgresql/data - ./agis-postgis-db/backups:/var/backups ports: - 40503:5432 environment: - POSTGRES_PASSWORD=InputPassowrdHere - POSTGRES_PORT=5432 # смотрит порт postgres, который запущен в postgis cpus: 2 mem_limit: 4gb healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 10s timeout: 5s retries: 5 networks: default: external: name: agis-net
Запуск elasticsearch из командной строки
$ docker run --name agis-elastic --restart always -it -d -v /data/agis/db/agis-elastic-db/db:/usr/share/elasticsearch/data -p 9209:9200 -p 9309:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:5.6.4