ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

使用Dockerfile创建镜像

2022-04-07 10:35:13  阅读:206  来源: 互联网

标签:npm WARN Pull 创建 --- 镜像 docker Dockerfile


1、基本结构

Dockerfile由一行行命令语句组成,并且支持以#开头的注释行。

一般而言,Dockerfile主体内容分为四部分:基础镜像镜像、维护者信息、镜像操作指令和容器启动时执行指令

2、指令说明

Dockerfile中指令的一般格式为:INSTRUCTION arguments,包括配置指令(配置镜像信息)和操作指令(具体执行操作)

分类 指令 说明
配置指令 ARG 定义创建镜像过程中使用的变量
FROM 指定所创建镜像的基础镜像
LABEL 为生成的镜像添加元数据标签信息
EXPOSE 声明镜像内服务监听的端口
ENV 指定环境变量
ENTRYPOINT 指定镜像的默认入口命令
VOLUME 创建一个数据卷挂载点
USER 指定运行容器时的用户名或UID
WORKDIR 配置工作目录
ONBUILD 创建子镜像时指定自动执行的操作指令
STOPSIGNAL 指定退出的信号值
HEALTHCHECK 配置所启动容器如何进行健康检查
SHELL 指定默认shell类型
操作指令 RUN 运行指定命令
CMD 启动容器时指定默认执行的命令
ADD 添加内容到镜像
COPY 复制内容到镜像

示例:

FROM node
MAINTAINER Taolei
RUN git clone -q https://github.com/docker-in-practice/todo.git
WORKDIR todo
RUN npm install > /dev/null
EXPOSE 8000
CMD ["npm","start"]

构建过程如下:

[root@aliyun docker]# pwd
/home/docker
#构建一个镜像
[root@aliyun docker]# docker build .
Sending build context to Docker daemon  2.048kB
Step 1/7 : FROM node
latest: Pulling from library/node
0e29546d541c: Pull complete 
9b829c73b52b: Pull complete 
cb5b7ae36172: Pull complete 
6494e4811622: Pull complete 
6f9f74896dfa: Pull complete 
f2930ff7fb60: Pull complete 
c1d26179dd86: Pull complete 
1fa56dd41537: Pull complete 
321141c774e9: Pull complete 
Digest: sha256:36aca218a5eb57cb23bc790a030591382c7664c15a384e2ddc2075761ac7e701
Status: Downloaded newer image for node:latest
 ---> a283f62cb84b
Step 2/7 : MAINTAINER Taolei
 ---> Running in c367d3410334
Removing intermediate container c367d3410334
 ---> e7567eaaf35c
Step 3/7 : RUN git clone -q https://github.com/docker-in-practice/todo.git
 ---> Running in 9191275f23b1
Removing intermediate container 9191275f23b1
 ---> 5d80658a509b
Step 4/7 : WORKDIR todo
 ---> Running in f297028141cf
Removing intermediate container f297028141cf
 ---> a81464358a14
Step 5/7 : RUN npm install > /dev/null
 ---> Running in 19d637151604
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'minifyify@4.4.0',
npm WARN EBADENGINE   required: { node: '0.10.x' },
npm WARN EBADENGINE   current: { node: 'v17.3.0', npm: '8.3.0' }
npm WARN EBADENGINE }
npm WARN deprecated graceful-fs@2.0.3: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated buffer-browserify@0.2.5: Package not maintained. Recent browserify uses https://github.com/feross/buffer
npm WARN deprecated mkdirp@0.3.5: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated mkdirp@0.3.5: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated minimatch@0.3.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@0.3.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated react-tools@0.11.2: react-tools is deprecated. For more information, visit https://fb.me/react-tools-deprecated
npm notice 
npm notice New minor version of npm available! 8.3.0 -> 8.6.0
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.6.0>
npm notice Run `npm install -g npm@8.6.0` to update!
npm notice 
Removing intermediate container 19d637151604
 ---> d1b737e8b68f
Step 6/7 : EXPOSE 8000
 ---> Running in 27157638d7d6
Removing intermediate container 27157638d7d6
 ---> 6fafd82e1672
Step 7/7 : CMD ["npm","start"]
 ---> Running in fe6d70c5ec05
Removing intermediate container fe6d70c5ec05
 ---> eafa085c10fa
Successfully built eafa085c10fa

步骤说明:

  1. docker会上传docker build指定目录下的文件和目录
  2. 每个构建步骤从1开始按顺序编号,并与命令一起输出
  3. 每个命令会导致一个新镜像被创建出来,其镜像ID在此输出
  4. 为节省空间,在继续前每个中间容器会被移除
  5. 构建的调试信息在此输出
  6. 此次构建的最终镜像ID,可用于打标签

打标签

#打标签前
[root@aliyun docker]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
<none>       <none>    eafa085c10fa   7 minutes ago   1.1GB
busybox      latest    beae173ccac6   3 months ago    1.24MB
node         latest    a283f62cb84b   3 months ago    993MB
#打标签时
[root@aliyun docker]# docker tag eafa085c10fa todoapp
#打标签后
[root@aliyun docker]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
todoapp      latest    eafa085c10fa   8 minutes ago   1.1GB
busybox      latest    beae173ccac6   3 months ago    1.24MB
node         latest    a283f62cb84b   3 months ago    993MB

标签:npm,WARN,Pull,创建,---,镜像,docker,Dockerfile
来源: https://www.cnblogs.com/Torres-tao/p/16111020.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有