美文网首页
docker-compose(单机版容器编排工具)

docker-compose(单机版容器编排工具)

作者: 口口帅日日 | 来源:发表于2020-04-17 22:36 被阅读0次

    前提需要声明版本
    这里容器的连接是双向的

    yum install docker-compose -y
    [root@master wordpress]# cat docker-compose.yml
    version: '3'

    services:
    db:
    image: mysql:5.7
    volumes:
    - /data/db_data:/var/lib/mysql
    restart: always
    environment:
    MYSQL_ROOT_PASSWORD: somewordpress
    MYSQL_DATABASE: wordpress
    MYSQL_USER: wordpress
    MYSQL_PASSWORD: wordpress

    wordpress:
    depends_on:
    - db
    image: wordpress:latest
    volumes:
    - /data/web_data:/var/www/html
    ports:
    - "80:80"
    restart: always
    environment:
    WORDPRESS_DB_HOST: db
    WORDPRESS_DB_USER: wordpress
    WORDPRESS_DB_PASSWORD: wordpress

    docker-compose up -d #启动服务
    docker-compose restart db或wordpress(服务名称)

    服务之间通过dns解析

    root@a7fad202cb7a:/var/www/html# cat /etc/resolv.conf
    nameserver 127.0.0.11
    options ndots:0

    zabbix/zabbix-server-mysql                       latest              e36e7fa7e11a        3 years ago         106MB
    zabbix/zabbix-web-nginx-mysql                    latest              386dc9afc1c4        3 years ago         174MB
    zabbix/zabbix-java-gateway                       latest              4257519fd740        3 years ago         148MB
    
    
    [root@master zabbix]# cat docker-compose.yml 
    version: '3'
    
    services:
    mysql-server:
        image: mysql:5.7
        restart: always
        command: --character-set-server=utf8 --collation-server=utf8_bin
        environment:
        MYSQL_ROOT_PASSWORD: root_pwd
        MYSQL_DATABASE: zabbix
        MYSQL_USER: zabbix
        MYSQL_PASSWORD: zabbix_pwd
    zabbix-java-gateway:
        image: zabbix/zabbix-java-gateway:latest
        restart: always    
    
    zabbix-server:
        depends_on:
        - mysql-server
        - zabbix-java-gateway
        image: zabbix/zabbix-server-mysql:latest 
        ports:
        - "10051:10051"
        restart: always
        environment:
        DB_SERVER_HOST: mysql-server
        MYSQL_DATABASE: zabbix
        MYSQL_USER: zabbix
        MYSQL_PASSWORD: zabbix_pwd
        MYSQL_ROOT_PASSWORD: root_pwd
        ZBX_JAVAGATEWAY: zabbix-java-gateway
    
    zabbix-web: 
        depends_on:
        - mysql-server
        - zabbix-server
        image: zabbix/zabbix-web-nginx-mysql:latest
        ports: 
        - "80:80"
        restart: always
        environment:
        DB_SERVER_HOST: mysql-server
        MYSQL_DATABASE: zabbix
        MYSQL_USER: zabbix
        MYSQL_PASSWORD: zabbix_pwd
        MYSQL_ROOT_PASSWORD: root_pwd
    

    相关文章

      网友评论

          本文标题:docker-compose(单机版容器编排工具)

          本文链接:https://www.haomeiwen.com/subject/digxuhtx.html