- 使用docker commit和dockerfile构建镜像
- 使用多from指令构建镜像
- 讲述镜像系统的原理
镜像:repo(仓库的ip/域名+端口号)/路径/镜像名称:tag
dockerfile解决的问题:
- 镜像制作过程自动化:利于迭代。
- 以dockerfile形式制作的镜像把镜像的制作过程保存了下来,易于维护 ,作者和其他人都可以通过查看dockerifle的方式去知晓这个镜像的所有内容。
样例:
dockerfile:
FROM centos:7
ADD entrypoint.sh /root
ADD requirements.txt /root
WORKDIR /root
USER root
RUN yum install -y epel-release \
&& yum install -y python34 git python34-setuptools python34-devel.x86_64 \
&& easy_install-3.4 pip \
&& yum install -y gcc \
&& yum install -y soci-mysql-devel.x86_64 \
&& ln -s /usr/local/mysql/bin/mysql /usr/bin \
&& pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
ENTRYPOINT ["/root/entrypoint.sh"]
启动脚本:
#!/bin/bash
mkdir -p /opt/web
cd /opt/web
git clone https://github.com/ycwdaaaa/holmes.git
cd holmes
pip3 install -r requirement.txt -i https://mirrors.aliyun.com/pypi/simple/
/usr/bin/python3.4 app.py
while true
do
sleep 10
done
搭建镜像仓库:
docker pull registry:2
docker run -d -p 5000:5000 -v /usr/local/registry:/var/lib/registry --restart=always --name registry registry:2
docker pull busybox
docker tag busybox localhost:5000/bosybox:v1.0
docker push localhost:5000/bosybox:v1.0
curl http://localhost:5000/v2/_catalog
多FROM指令
FROM centos:6.9 as builder
# 下载基础工具
RUN echo "this is a test" > gaofei.tar
FROM busybox
WORKDIR /root
COPY --from=builder gaofei.tar .
启动grid的命令:
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
作业:
https://github.com/ycwdaaaa/holmes
https://github.com/ycwdaaaa/conan
使用dockerfile制作这两个项目的镜像