docker镜像搭建实战-课程贴

预习内容:
dockerfile 语法

课堂作业一:编写一个基于后端服务的dockerfile
代码地址:https://github.com/ycwdaaaa/holmes.git

答案:
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 .

扩展阅读:
https://testerhome.com/articles/18471