zoukankan      html  css  js  c++  java
  • docker-compose

    # 重启docker, 容器不死
    方法1: docker run -d --restart=always nginx:latest
    systemctl restart docker
    方法二: 默认所有容器都起,修改配置文件
    /etc/docker/daemon.json
    {
        "registry-mirrors":["http://b7a9017d.m.caocloud.io"],
        "insecure-registries":["10.0.0.7:5000"],
        "live-restore":true
    }
    

    Docker 的几种网络类型

    # docker container inspect 可以查看网络类型
    # docker network ls
    none: 不为容器配置任何网络功能 --net=none
    bridge: docker 默认的网络类型(桥接模式)
    hosts : 和宿主机共享网络
    container: 与另一个运行中的容器共享network namespace 
    docker run -it --network container:容器ID  
    

    跨主机网络通讯 macvlan

    默认一个屋里网卡,只有一个屋里地址,虚拟多个mac地址
    # 创建macvlan网络
    docker network create --driver macvlan --subnet 10.0.0.0/24 --gateway 10.0.0.254 -o parent=eth0 macvlan_1  # 在两台虚拟机都执行
    # ubanto 需要设置混杂模式(不是自己的数据包也接收)
    # ip link set eth1 promisc on 
    # 创建使用macvlan网络的容器
    docker run -it --network macvlan_1 --ip=10.0.0.101 镜像  # 虚拟机1
    docker run -it --network macvlan_1 --ip=10.0.0.102 镜像  # 虚拟机2
    
    '''
    本地shell 
    ssh root@10.0.0,102 也可以进入容器中
    '''
    

    跨主机通信之 overlay

    1. 准备工作
    docker01 
    docker run -d -p 8500:8500 --restart=always -h consul --name consul progrium/consul -server -bootstrap
    设置容器主机名
    consul: key,value 类型的存储数据库
    
    docker01, 02 修改
    vim /etc/docker/daemon.json
    {
        "hosts":["tcp://0.0.0.0:2376","unix:///var/run/docker.socket"],
        "cluster-store":"consul://10.0.0.7:8500",
        "cluster-advertise":"10.0.0.11:2367"
    }
    vim /usr/lib/systemd/system/docker.service
    systemctl daemon-reload
    systemctl restart docker
    2. 创建overlay 网络
    docker network create -d overlay --subnet 172.16.1.0/24 --gate 172.16.1.254 ol1   # global网络
    3. 启动容器测试
    docker run -it --network ol1 --name octivia -h octivia centos6.9_ssh_nginx:v3
    # 容器间可以相互ping通
    
    应用要被外界访问,使用端口映射
    

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

    # 一次起多个容器
    yum install -y python2-pip # 需要epel源
    pip install docker-comose  # 清华源pypi 加速
    # 新建目录/opt/wordpress
    vim docker-compose.yml
    version: '3'
    配置要启动的容器  # 没有的话自动pull
    
    # docker-compose up 进行启动
    docker-compose up -d  # 后台运行
    docker-compose up --scale  wordpress=3 #起了三个,可以做负载均衡
    
    # 配置负载均衡
    yum install nginx -y
    另一台服务器起nginx 挂三个wordpress
    nginx 还需要做端口映射
    -- # nginx 文件最小化
    grep -Ev '^$|#' /etc/nginx/nginx.conf.default >/etc/nginx/nginx.conf
    upstream wordpress {
        server 10.0.0.7:33213;
        server 10.0.0.7:33214;
        server 10.0.0.7:33215;
    }
    location / {
        proxy_pass http://wordpress; 
        proxy_set_header Host $host;
    }
    # 查看负载均衡
    找到持久化的卷,添加文件info.php
    cd /var/lib/docker/volumes/wordpress_web_data/_data/
    vim info.php
    <?php phpinfo(); ?>
    访问 10.0.0.7/info.php  # 刷新每次的ip地址不同,即实现了负载均衡
     
    

    其他命令

    vim 快捷键
    dgg  从当前行删到开头
    dG  从当前行删到行尾
    
  • 相关阅读:
    严蔚敏数据结构习题3.14
    Effective C++ Item 34 Differentiate between inheritance of interface and inheritance of implementation
    Effective C++ Item 33 Avoid hiding inherited names
    Effective C++ Item 19 Treat class design as type design
    Effective C++ Item 18 Make interfaces easy to use correctly and hard to use incorrectly
    Effective C++ Item 17 Store newed objects in smart pointer in standalone statements
    Effective C++ Item 16 Use the same form in corresponding uses of new and delete
    Effective C++ Item 15 Provide access to raw resources in resource-managing classes
    Effective C++ Item 14 Think carefully about copying behavior in resource-managing classe
    Effective C++ Item 13 Use object to manage resources
  • 原文地址:https://www.cnblogs.com/Afrafre/p/11458357.html
Copyright © 2011-2022 走看看