课程大纲
- 使用docker commit和dockerfile构建镜像
- 使用多from指令构建镜像
- 讲述镜像系统的原理
镜像:repo(仓库的ip/域名+端口号)/路径/镜像名称:tag
dockerfile解决的问题:
- 镜像制作过程自动化:利于迭代。
- 以dockerfile形式制作的镜像把镜像的制作过程保存了下来,易于维护 ,作者和其他人都可以通过查看dockerifle的方式去知晓这个镜像的所有内容。
PPT
样例:
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 .