Skip to content

Instantly share code, notes, and snippets.

@pirate
Last active November 26, 2024 07:34
Show Gist options
  • Save pirate/1fafaa18a47254f388aa5c0f79f7d263 to your computer and use it in GitHub Desktop.
Save pirate/1fafaa18a47254f388aa5c0f79f7d263 to your computer and use it in GitHub Desktop.
Example database container setups for PostgreSQL, MariaDB, Redis, Memcached, MongoDB, Neo4j, Hasura GraphQL, CockroachDB, and TiDB in Docker Compose
# Example database container setups for PostgreSQL, MariaDB, Redis, Memcached, MongoDB, Neo4j, Hasura GraphQL, CockroachDB, and TiDB in Docker Compose
# https://gist.github.com/pirate/1fafaa18a47254f388aa5c0f79f7d263
# Goes well with these docker-compose networking/ingress container examples:
# https://gist.github.com/pirate/1996d3ed6c5872b1b7afded250772f7c
version: '2.4'
services:
postgres:
# easy upgrades: https://github.com/tianon/docker-postgres-upgrade
# admin shell: docker-compose exec postgres env PGPASSWORD=examplepass psql -U admin postgres
# dump backup: docker-compose exec postgres env PGPASSWORD=examplepass pg_dumpall -U admin | pv | gzip -9 > ./data/backups/$(date +%s)__all.sql.gz
image: postgres:alpine
expose:
- 5432
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: examplepass
volumes:
# optional, restore from the latest backup on first run
# - ./data/backups/latest.sql:/docker-entrypoint-initdb.d/dump.sql
- ./data/postgres:/var/lib/postgresql/data
cpus: 2
mem_limit: 4096m
mariadb:
image: mariadb:latest
expose:
- 3306
environment:
MYSQL_DATABASE: someapp
MYSQL_USER: someapp
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- ./data/mariadb:/var/lib/mysql
cpus: 2
mem_limit: 4096m
redis:
image: redis:alpine
command: redis-server --appendonly yes
expose:
- 6379
volumes:
- ./data/redis:/data
memcached:
image: memcached:latest
expose:
- 11211
mongodb:
image: mongo:latest
expose:
- 27017
volumes:
- ./data/mongodb:/data/db
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: somestrongpassword
neo4j:
image: neo4j:latest
expose:
- 7474 # HTTP API
- 7687 # BOLT API
environment:
NEO4J_AUTH: none
volumes:
- ./data/neo4j:/data:Z
hasura:
image: hasura/graphql-engine:latest
expose:
- 8080 # GraphQL HTTP API
depends_on:
- postgres
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to false on prod
HASURA_GRAPHQL_DEV_MODE: "true" # set to false on prod
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
HASURA_GRAPHQL_ADMIN_SECRET: someadminpasswordhere
cockroachdb:
image: cockroachdb/cockroach:latest
command: start --insecure
hostname: cockroachdb_node_1
expose:
- 26257 # inter-cluster communication
- 8080 # DB console web UI
volumes:
- ./data/cockroachdm:/cockroach/cockroach-data
tidb:
image: pingcap/pd:latest
hostname: tidb_node_1
expose:
- 2379
volumes:
- ./etc/tidb/pd.toml:/pd.toml:ro
- ./data/tidb:/data
- ./logs/tidb:/logs
command:
- --name=tidb_node_1
- --client-urls=http://0.0.0.0:2379
- --peer-urls=http://0.0.0.0:2380
- --advertise-client-urls=http://tidb_node_1:2379
- --advertise-peer-urls=http://tidb_node_1:2380
- --initial-cluster=tidb_node_1=http://tidb_node_1:2380,pd1=http://tidb_node_2:2380,pd2=http://tidb_node_3:2380
- --data-dir=/data/tidb_node_1
- --config=/pd.toml
- --log-file=/logs/pd0.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment