docker 实战

课程帖

课堂作业 一

使用docker搭建一个可以访问的jenkins服务

使用docker搭建一个可以访问的testlink服务

使用container模式搭建前端和后端服务

普罗米修斯的配置文件

启动node_exporter :nohup ./node_exporter/node_exporter >> node_exporter.log 2>&1 &

global:
  scrape_interval:     15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
  - job_name: 'node_exporter'
    static_configs:
    - targets: ['docker.testing-studio.com:9100']
  - job_name: 'mysql'
    static_configs:
    - targets: ['docker.testing-studio.com:9104']

docker run --name prometheus -d -p 9090:9090 -v pwd/prometheus.yml:/etc/prometheus/prometheus.yml -v pwd/rules/:/etc/prometheus/ prom/prometheus

cpu使用率:100 - (avg by (instance) (irate(node_cpu_seconds_total{mode=“idle”}[1m])) * 100)
内存使用率:100*(node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Buffers_bytes - node_memory_Cached_bytes) / node_memory_MemTotal_bytes

磁盘使用:100.0 - 100 * ((node_filesystem_avail_bytes{mountpoint=~“/”, device!=“rootfs”} / 1000 / 1000 ) / (node_filesystem_size_bytes{mountpoint=~“/”, device!=“rootfs”} / 1024 / 1024))

启动grafana

docker run --name grafana -d -p 8011:3000 grafana/grafana

模板地址:1 Node Exporter Dashboard 22/04/13 ConsulManager自动同步版 | Grafana Labs

使用普罗米修斯+grafana监控mysql

docker run -d --name mysql-exporter -p 9104:9104 -e DATA_SOURCE_NAME=“root:1qaz9ol.@(docker.testing-studio.com :8888)/mysql” prom/mysqld-exporter

教学项目

https://github.com/ycwdaaaa/techUI

docker 搭建分布式UI自动化框架

docker run --name=hub -p 5001:4444 -e GRID_TIMEOUT=0 -e GRID_THROW_ON_CAPABILITY_NOT_PRESENT=true -e GRID_NEW_SESSION_WAIT_TIMEOUT=-1 -e GRID_BROWSER_TIMEOUT=15000 -e GRID_TIMEOUT=30000 -e GRID_CLEAN_UP_CYCLE=30000 -d selenium/hub:3.7.1-beryllium
docker run --name=chrome -p 5902:5900 -e NODE_MAX_INSTANCES=6 -e NODE_MAX_SESSION=6 -e NODE_REGISTER_CYCLE=5000 -e DBUS_SESSION_BUS_ADDRESS=/dev/null -v /dev/shm:/dev/shm --link hub -d selenium/node-chrome-debug:3.7.1-beryllium
VNC密码是:secret

课堂作业二

不使用–link 搭建docker grid框架
在学习了jenkins课程之后,搭建起全套的CI流程。

k8s部署grid

hub

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: selenium-hub-58
  labels:
    name: selenium-hub-58
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: selenium-hub-58
    spec:
      containers:
      - name: selenium-hub-58
        image: selenium/hub:3.7.1-beryllium
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 4444
        env:
          - name: GRID_TIMEOUT
            value: "0"
          - name: GRID_THROW_ON_CAPABILITY_NOT_PRESENT
            value: "true"
          - name: GRID_NEW_SESSION_WAIT_TIMEOUT
            value: "-1"
          - name: GRID_BROWSER_TIMEOUT
            value: "15000"
          - name: GRID_TIMEOUT
            value: "30000"
          - name: GRID_CLEAN_UP_CYCLE
            value: "30000"
          - name: JAVA_OPTS
            value: "-Xmx512m"
          - name: GRID_MAX_SESSION
            value: "30"
---
apiVersion: v1
kind: Service
metadata:
  name: selenium-hub-58
  labels:
    name: selenium-hub-58
spec:
  type: NodePort
  ports:
  - port: 4444
    targetPort: 4444
    name: port0
    nodePort: 30000
  selector:
    name: selenium-hub-58
  sessionAffinity: None
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: selenium-node-chrome-58
  labels:
    name: selenium-node-chrome-58
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: selenium-node-chrome-58
    spec:
      containers:
      - name: selenium-node-chrome-58
        image: selenium/node-chrome-debug:3.7.1-beryllium
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 5900
        env:
          - name: HUB_PORT_4444_TCP_ADDR
            value: "selenium-hub-58"
          - name: HUB_PORT_4444_TCP_PORT
            value: "4444"
          - name: NODE_MAX_INSTANCES
            value: "30"
          - name: NODE_MAX_SESSION
            value: "30"
          - name: NODE_REGISTER_CYCLE
            value: "5000"
          - name: DBUS_SESSION_BUS_ADDRESS
            value: "/dev/null"
        resources:
          requests:
            memory: "500Mi"
        volumeMounts:
          - mountPath: "/dev/shm"
            name: "dshm"
      volumes:
        - name: "dshm"
          emptyDir:
            medium: "Memory"
      imagePullSecrets:
      - name: docker4paradigm

---
apiVersion: v1
kind: Service
metadata:
  name: selenium-node-chrome-58
  labels:
    name: selenium-node-chrome-58
spec:
  type: NodePort
  ports:
    - port: 5900
      targetPort: 5900
      name: port0
      nodePort: 30001
  selector:
    name: selenium-node-chrome-58
  sessionAffinity: None

课堂作业三

编写可以作为jenkins slave 机器的 dockerfile并制作镜像,连接到jenkins上。

FROM centos

ADD entrypoint.sh /root
ADD jdk /opt/java-1.8

ENV M2_HOME=/usr/local/maven
ENV M2=$M2_HOME/bin
ENV JAVA_HOME=/opt/java-1.8
ENV PATH=$JAVA_HOME:$M2:$PATH

RUN yum install -y wget openssh-server vim git openssh-clients \\
    && /usr/bin/ssh-keygen -A \\
    && wget http://mirror.olnevhost.net/pub/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz \\
    && tar xvf apache-maven-3.0.5-bin.tar.gz \\
    && mv apache-maven-3.0.5  /usr/local/maven \\
    && ssh-keygen -t rsa -f /root/.ssh/id_rsa -N '' \\
    && cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys \\
    && chmod 600 /root/.ssh/authorized_keys \\
    && echo "StrictHostKeyChecking no" > /root/.ssh/config \\
    && echo "UserKnownHostsFile /dev/null" >> /root/.ssh/config \\
    && echo 1qaz9ol.|passwd --stdin root \\
    && echo "export M2_HOME=/usr/local/maven" >> /root/.bashrc \\
    && echo "export M2=$M2_HOME/bin" >> /root/.bashrc \\
    && echo "export JAVA_HOME=/opt/java-1.8" >> /root/.bashrc \\
    && echo "export PATH=$JAVA_HOME:$M2:$PATH" >> /root/.bashrc



ENTRYPOINT ["/bin/bash", "/root/entrypoint.sh"]
FROM selenium/node-chrome-debug:3.7.1-beryllium

USER root

ADD run.sh /root/


RUN apt-get update \\
    && apt-get -y install ttf-wqy-microhei ttf-wqy-zenhei \\
    && apt-get clean \\
    && mkdir -p mkdir -p ~/.vnc \\
    && x11vnc -storepasswd work123 ~/.vnc/passwd

conan 和holmes镜像怎么下载呢?