Docker相关构建

前提条件:

先在某一路径下创建docker-compose.yml文件
操作系统为ubuntu

version: '2'
services:

# mysql

version: '2'
services:
    mysql:  
        # network_mode: "host" //否则外部无法连接
        image: "docker.io/mysql:5.7"
        environment:
            MYSQL_ROOT_PASSWORD: 'root'
            MYSQL_USER: "XXX"
            MYSQL_PASS: "123456"

        restart: always        
        volumes:
            - "./mysql/db:/var/lib/mysql"
            - "./mysql/conf/my.cnf:/etc/my.cnf"
            - "./mysql/init:/docker-entrypoint-initdb.d/"

        # centos 7 否则或报错 chown: cannot read directory '/var/lib/mysql/': Permission denied
      # - "./mysql/db:/var/lib/mysql:Z"
      #  - "./mysql/conf/my.cnf:/etc/my.cnf"
      #  - "./mysql/init:/docker-entrypoint-initdb.d:Z"


        ports:
            - "3306:3306"

    postgres:
      image: "postgres:10"
      container_name: "postgresql"
      restart: always
      environment:
            POSTGRES_DB: "db_postgres"
            POSTGRES_USER: "postgres"
            POSTGRES_PASSWORD: 123456
      ports:
          - "5432:5432"
      volumes:
        - "./postgresql/data:/var/lib/postgresql/pgdata"  


# pgSQL

    postgres:
      image: "postgres:10"
      container_name: "postgresql"
      restart: always
      environment:
            POSTGRES_DB: "db_postgres"
            POSTGRES_USER: "postgres"
            POSTGRES_PASSWORD: 123456
      ports:
          - "5432:5432"
      volumes:
        - "./postgresql/data:/var/lib/postgresql/pgdata"  


你可能感兴趣的:(Docker相关构建)