Dockerfile详解
发布日期:2019-12-02 07:51   浏览次数:
19人阅读 2019-11-26 10:05:12

制造Docker image有两种方式: 一是运用Docker container(docker save container_name -o test.tar ) ,再导出image,而是运用Dockerfile, 将一切举措导入到文件中,运用build命令制造成镜像。
一,Dockerfile根本构造
普通的Dockerfile分为四个局部:根底镜像信息,维护者信息,镜像操作指令和容器启动时的指令
FROM nginx:1.13.5-alpine MAINTAINER SXY Team <http://cywx.cn> #设置时区 RUN echo 'Asia/Shanghai' >/etc/timezone ARG SIBE_VERSION=0 COPY images/files/entrypoint.sh /usr/local/bin/ RUN chmod u+x /usr/local/bin/entrypoint.sh # Update to get support for Zip/Unzip, Bash RUN apk --update add zip unzip bash wget ENV WWW_TARGET /var/www/html/ COPY images/files/mysite.template /etc/nginx/conf.d/default.conf ADD dist/ /tmp/ RUN mkdir -p ${WWW_TARGET} \ && mv /tmp/ ${WWW_TARGET} \ && rm -rf /tmp/ ENV MGMT_API_URL http://192.168.3.223:19980 ENV MGMT_API_AUTHORIZATION d2ViX2FwcDpjaGFuZ2VpdA== RUN cp /var/www/html/scripts/http/configuration.json /var/www/html/scripts/http/configuration.json.template RUN cp /var/www/html/scripts/http/configuration.json /var/www/html/scripts/http/configuration.json.template2 # forward request and error logs to docker log collector RUN mkdir -p /var/log/webui && ln -sf /dev/stdout /var/log/webui/access.log \ && ln -sf /dev/stderr /var/log/webui/error.log EXPOSE 80 443 ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] CMD ["nginx", "-g", "daemon off;"] entrypoint中的信息 [root@test-227 files]# cat entrypoint.sh #!/bin/bash setup() { echo "Configure 1 management api url to ${MGMT_API_URL}" cat /var/www/html/scripts/http/configuration.json.template | \ sed "s#http://192.168.3.223:19980#${MGMT_API_URL}#g" > /var/www/html/scripts/http/configuration.json.template2 cat /var/www/html/scripts/http/configuration.json.template2 echo "Configure 2 AUTHORIZATION to ${MGMT_API_AUTHORIZATION}" cat /var/www/html/scripts/http/configuration.json.template2 | \ sed "s#d2ViX2FwcDpjaGFuZ2VpdA==#${MGMT_API_AUTHORIZATION}#g" > /var/www/html/scripts/http/configuration.json cat /var/www/html/scripts/http/configuration.json } setup exec "$@"
FROM:指定根底镜像,要在哪个镜像树立
FROM <image> 或许 FROM <image>:<tag>
第一条指令必需为FROM指令

MAINTAINER: 指定维护者信息
MAINTAINER <name>

RUN: 在镜像中要执行的命令
RUN <command> 或许 RUN ["executable","param1","param2"]
前者将shell终端中运转命令,即/bin/bash -c;后者则运用exec执行,指定运用其他终端可以经过第二种方式完成,例如RUN ["/bin/bash", "-c", "echo hello"]

WORKDIR: 指定以后任务目录,相当于cd
WORKDIR /path/to/workdir
为后续的RUN,CMD,ENTRYPOINT指令配置任务目录,可以运用多个WORKDIR指令,后续命令假如参数是绝对途径,则会基于之前命令指定的途径,例如

« 上一篇:没有了
» 下一篇:没有了
  • 友情链接:
Copyright(C) 2007-2010 EntLib.com(上海闵行区浦江镇863软件孵化基地) - 企业级的电子商务系统 基于Microsoft .Net Framework / ASP.Net / C# / AJAX 平台构建的标准电子商务系统 All Rights Reserved (R)    沪ICP备08014628号