常见应用 Docker Compose 启动

Mysql

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
services:
  db:
    image: mysql:8
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: suyiiyii
      MYSQL_DATABASE: database
    ports:
      - 3306:3306
    volumes:
      - db-data:/var/lib/mysql

volumes:
  db-data:

Mongo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14

services:

  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example
    volumes:
	    mongodata:/data/db
      
volume:
	mongodata:

Postgres

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18

services:
  postgres:
    image: postgres:latest
    container_name: my_postgres
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-mysecretpassword}
      - POSTGRES_DB=${POSTGRES_DB:-mydatabase}
      - POSTGRES_USER=${POSTGRES_USER:-postgres}
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    restart: unless-stopped

volumes:
  postgres_data:
    name: postgres_data
Licensed under CC BY-NC-SA 4.0