zoukankan      html  css  js  c++  java
  • 镜像制作

    1.镜像源

    阿里云镜像源

    https://opsx.alibaba.com/mirror/

    基于centos镜像的nginx镜像制作

    vi /etc/nginx/nginx.conf

    user nginx;

    daemon off;

    检查语法

     nginx -t

    docker commit --help

    修改容器信息

    -m, --message string   Commit message  提交容器信息

    docker commit -m  'add nginx images'  mynginx  hei/my_nginx

                                      容器  制作后的镜像名

    docker commit -m 'add nginx images' mynginx hei/my_nginx:v1

                                                     tag

    启动制作的镜像

    docker run -d --name nginx_web hei/my_nginx:v1  nginx

                                              制作的镜像没有默认命令 要加

    官方镜像

    https://hub.docker.com/

    上传至官方镜像库

    docker login 登录官网

    docker images 获取制作的镜像ID

    docker tag   999f27d9f64a(制作的镜像ID)  docker.io/your_login_name/image_name 重命名

    docker push  docker.io/you_login_name/image_name 上传

    2.网络连接 

    docker run -d --name nginx_web -P docker.io/nginx

    d0507c554898        docker.io/nginx     "nginx -g 'daemon ..."   About a minute ago   Up About a minute   0.0.0.0:32768->80/tcp   nginx_web

    -P 开启随机端口映射

    本地的32768端口映射到容器的80端口

    docker run -d --name web -p 80:80 docker.io/nginx

    -p

    本地80端口映射到容器的80端口

    docker run -d --name web -p 80:80/udp  docker.io/nginx

    指定udp协议

    docker run --name web2 --link web1:shop_web  -d -p 8080:80 docker.io/nginx

    创建容器web2

    --link web1:互联到web1

    shop_web  容器主机别名

    查看 docker的网络类型

    docker network ls

    宿主机与宿主机之间docker互联互通

    node1

     vi /usr/lib/systemd/system/docker.service

    加上 --bip=192.168.58.1/24

    node2

     vi /usr/lib/systemd/system/docker.service

    加上 --bip=192.168.158.1/24

    node1:

    route add -net 192.168.158.0/24 gw 192.168.81.110  (node2 IP)

    docker run -it -d --name host1  centos  bash

    yum install net-tools -y

    ping -c 1 192.168.158.2  ping一次

    node2:

    route add -net 192.168.58.0/24 gw  192.168.81.100 (node1 IP)

    docker run -it -d  --name host2  centos  bash

    yum install net-tools -y

    tcpdump详解

    https://www.cnblogs.com/howhy/p/6396664.html

    node1 -->host1容器

    ping -c 1 192.168.158.2  ping一次

    node2抓包分析

    tcpdump -i ens33 -vnn icmp

    tcpdump -i docker0 -vnn icmp

    3.数据卷管理

    docker rm -fv xxx  才能把文件删了

     docker run -it --name node1 --rm -v /data centos bash

    --rm  关闭自动删除

    -v 指定挂载宿主机的目录

    /data 挂载到宿主机根分区

    docker run -it --name node1 --rm -v /opt:/opt centos bash   容器的/opt 挂载到 宿主机的/opt

                                 宿主机目录:容器目录

    docker run -it --name node1 --rm -v /test:/opt centos bash  容器的/opt 挂载到宿主机的/test

    docker run -it --name node1 --rm -v /test:/opt:ro centos bash   ro:挂载只读

    4.数据卷容器

    docker run -it --name node01 --volumes-from node1 centos bash

    继承 node1的挂载

    5.Dockerfile

    全自动构建镜像的文件

    ls  /root/dockerfile   

    Dockerfile  index.html

    cat Dockerfile

    #!this is dockerfile for nginx

    #base image

    From centos

    #维护者信息

    MAINTAINER weihu xinxi

    #相关操作

    RUN rpm -ivh https://mirrors.aliyun.com/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

    RUN yum install nginx -y

    #添加文件

    ADD index.html /usr/share/nginx/html/index.html

    #添加参数

    RUN echo "daemon off;" >> /etc/nginx/nginx.conf

    #设置开放端口

    EXPOSE 80

    #添加默认执行命令

    CMD "nginx"

    cat index.html

    <h1>This is test page</h1>

    执行创建镜像命令

    docker build -t new/nginx:latest  /root/dockerfile/

                 镜像名:tag      Dockerfile文件存放目录位置

    查看创建好的镜像

    docker images

    6.私库搭建

    cd /opt/

    mkdir auth

    生成存储密码文件

     docker run --entrypoint htpasswd registry:2 -Bbn hello 123456 > auth/htpasswd

     cat auth/htpasswd

    建仓库

     docker run -d -p 5000:5000 --restart=always --name registry1  -v `pwd`/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e "REGISTRY_AUTH_HTPASSWD_PATH=auth/htpasswd" registry

    解读:

     docker run -d -p 5000:5000 --restart=always --name registry1   docker重启,registry1也重启  

    -v `pwd`/auth:/auth   挂载

    -e "REGISTRY_AUTH=htpasswd" 认证

    -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" 注册

    -e "REGISTRY_AUTH_HTPASSWD_PATH=auth/htpasswd" 指定文件

    registry 启动建仓

    查看仓库

    docker ps

    登陆

    docker login 127.0.0.1:5000

    要上传的镜像重命名

    docker tag 276408de9b28 127.0.0.1:5000/hello/nginx

    上传

    docker push 127.0.0.1:5000/hello/nginx

    测试下载

    docker pull 127.0.0.1:5000/hello/nginx

    下载完之后改名再用

    7.docker容器编排

    yum install python-pip -y

    pip install docker-compose

    docker-compose version 查看版本

    docker-compose --help 查看帮助

    mkdir compose && cd compose

    compose文件

    vim docker-compose.yml

    web1:   定义容器名

      image: nginx  使用的镜像 官方镜像

      expose:

        - 80

      volumes: 定义挂载存储

        - ./web1:/usr/share/nginx/html

    web2:

      image: nginx

      expose:

        - 80

      volumes:

        - ./web2:/usr/share/nginx/html

    haproxy:

      image: haproxy

      volumes:

        - ./haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg 本地文件 容器挂载的文件路径

      links:

        - web1

        - web2

      ports:

        - "80:80" 物理机端口映射与容器端口

      expose:

        - "80"  容器暴露端口

    文件准备:

    cd compose && mkdir haproxy web1 web2

    vim haproxy.cfg

    global

            log 127.0.0.1  local0

            log 127.0.0.1  local1 notice

    defaults                        

            log     global          

            mode    http            

            option  httplog         

            option  dontlognull     

            timeout  connect    5000ms      #--连接超时

            timeout  client    50000ms      #--客户端连接超时时间 毫秒

            timeout  server    50000ms      #--服务器连接超时时间

            stats uri /status

    frontend  balancer

              bind 0.0.0.0:80 #--配置haproxy服务器的名称与IP地址和端口

              default_backend web_backends

    backend   web_backends

               balance roundrobin      

               server server1 web1:80 #--配置真实服务器的地址和端口

               server server2 web2:80 #--配置真实服务器的地址和端口

    echo web1 > web1/index.html

    echo web2 > web2/index.html

    编排:

    docker-compose up -d  后台编排

    docker-compose start/stop/rm  开始/停止/删除容器

    参考:https://blog.csdn.net/qwqq233/article/details/90756902

  • 相关阅读:
    c#基础问题笔记(一)
    自动化技术中的进给电气传动研习笔记2
    自动化技术中的进给电气传动研习笔记1
    汉字在电脑中是如何存储与编码的呢?
    三十分钟掌握STL
    python练习:函数2
    python练习:函数3
    Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form ResumeForm needs updating.
    vue 数组对象取对象的属性: Cannot read property 'xxxx' of undefined
    python练习:函数4
  • 原文地址:https://www.cnblogs.com/leiwenbin627/p/11210833.html
Copyright © 2011-2022 走看看