docker build

命令:docker build

[[email protected] ~]# docker build --help

Usage:    docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

Options:
      --add-host list              Add a custom host-to-IP mapping (host:ip)
      --build-arg list             Set build-time variables
      --cache-from stringSlice     Images to consider as cache sources
      --cgroup-parent string       Optional parent cgroup for the container
      --compress                   Compress the build context using gzip
      --cpu-period int             Limit the CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int              Limit the CPU CFS (Completely Fair Scheduler) quota
  -c, --cpu-shares int             CPU shares (relative weight)
      --cpuset-cpus string         CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string         MEMs in which to allow execution (0-3, 0,1)
      --disable-content-trust      Skip image verification (default true)
  -f, --file string                Name of the Dockerfile (Default is ‘PATH/Dockerfile‘)
      --force-rm                   Always remove intermediate containers
      --help                       Print usage
      --isolation string           Container isolation technology
      --label list                 Set metadata for an image
  -m, --memory bytes               Memory limit
      --memory-swap bytes          Swap limit equal to memory plus swap: ‘-1‘ to enable unlimited swap
      --network string             Set the networking mode for the RUN instructions during build (default "default")
      --no-cache                   Do not use cache when building the image
      --pull                       Always attempt to pull a newer version of the image
  -q, --quiet                      Suppress the build output and print image ID on success
      --rm                         Remove intermediate containers after a successful build (default true)
      --security-opt stringSlice   Security options
      --shm-size bytes             Size of /dev/shm
  -t, --tag list                   Name and optionally a tag in the ‘name:tag‘ format
      --target string              Set the target build stage to build.
      --ulimit ulimit              Ulimit options (default [])

使用这个命令来搭配Dockerfile 创建一个image

PATH or URL  在这2项中的文件被当作资源上下文. 创建image过程中,所有的文件都可能会被标记,比如说执行 ADD (link is external) 项. 当一个Dockerfile只有 URL STDIN (docker build - < Dockerfile), 那么就没有上下文了.

如果 URL 中指定了一个git repo,那么这个git repo也会被使用。 这个git repo会被当作子目录 (git clone -recursive). A fresh git clone occurs in a temporary directory on your local host, and then this is sent to the Docker daemon as the context. 反正如果使用git你必须处理好git的凭证和假如需要的VPN设置.

.dockerignore 在 PATH 项的根目录,这提供一种指定忽略的方式. 符合忽略规则的文件或目录将被忽略。

从官网文档来看https://docs.docker.com/engine/reference/builder/#usage

首先建议一个新的目录,这个文件下面是你需要创建这个镜像时所用到的文件,还有一个叫“Dockerfile”的文件,而这个文件就是我们构建镜像文档文。我们要写指令就是放在这个文件里。

我们可以用-f 参数来指定其它地方的dockerfile

$ docker build -f /path/to/a/Dockerfile .

有一个比较搞笑的插曲,当我学习的时候,一直在纠结为什么docker build 不成功,一直报错。原来我错误的认为,这个Dockerfile是一个文件夹,里面放指令文件。还折腾了好几个小时,不断各种百度。

我们可以使用-t来指定repository 和tag

$ docker build -t shykes/myapp .
时间: 2024-08-28 15:17:03

docker build的相关文章

解决Docker build时 Sending build context to Docker daemon 过大的问题

当使用Dockerfile Build镜像时,优势会发现发送到Daemo的内容过大 build image:q_build/javaweb:20150910174642Sending build context to Docker daemon 4.768 GBSending build context to Docker daemon  Step 0 : FROM 192.168.100.123:5000/q_basic/javaweb:1.0  ---> 0aab72ab2945 Step 

【云计算】docker build如何支持参数化构建?

docker 1.9.0版本之后,已经支持docker build参数化构建. docker 版本更新记录: github讨论: 参开资料: https://github.com/docker/docker/issues/14634 http://stackoverflow.com/questions/34174499/docker-build-argument https://github.com/docker/docker/blob/master/CHANGELOG.md#190-2015-

docker build报错

docker build 遇到问题 "can  not stat ... APPData\Local\Application Data" 解决方法:

docker commit 与 docker build

在使用Docker的过程中,我们除了从Docker Hub上下载已经做好的镜像,很多时候需要我们自己制作镜像.下面想在这个文章中说明一下镜像的制作方法. 制作镜像的方式主要有两种: 通过docker commit 制作镜像 通过docker build 制作镜像 这两种方式都是通过改进已有的镜像来达到自己的目的.制作基础镜像,会在另外一篇文章"从零开始制作基础镜像"中介绍. docker commit docker commit 是往版本控制系统里提交一次变更.使用这种方式制作镜像,本

docker: &quot;build&quot; requires 1 argument. See &#39;docker build --help&#39;.

http://bbs.csdn.net/topics/391040030 docker build  --tag="ouruser/sinatra:v3" -<Dockerfile  docker build -t jamtur01/nginx <Dockerfile 所在目录>如果是当前目录,简单输入 "docker build -t jamtur01/nginx ."即可. docker: "build" requires

docker build python环境时出现了个错误

前段时间面试,面试官问我除了简历这些你还有其他什么水平吗,我想了想我说我解决bug比普通人更好一些,然而面试官一脸不屑的跟我讲,解决bug呢更多的是需要经验,当时给我出了个问题是redis就是get不到,实际是有值的,这种bug怎么解,我说那就看日志了...反正说了一些思路,面试官予以否定.理由是找bug更多的是需要经验,当时也没什么可反驳的好像说的对,直到刚刚遇到了一个问题,在使用docker的时候build python相关的镜像,出现了如下错误 Get:9 http://archive.u

docker build 的 cache 机制

cache 机制注意事项 可以说,cache 机制很大程度上做到了镜像的复用,降低存储空间的同时,还大大缩短了构建时间.然而,不得不说的是,想要用好 cache 机制,那就必须了解利用 cache 机制时的一些注意事项. 1. ADD 命令与 COPY 命令:Dockerfile 没有发生任何改变,但是命令ADD run.sh / 中 Dockerfile 当前目录下的 run.sh 却发生了变化,从而将直接导致镜像层文件系统内容的更新,原则上不应该再使用 cache.那么,判断 ADD 命令或

Jenkins Docker安装及Docker build step插件部署配置

Docker-build-step插件安装部署1.打开系统管理,插件管理,找到Docker build step插件,勾选选中,点击直接安装,安装完成后重启一下Jenkins容器:2.使用终端登录到B服务器,修改/usr/lib/systemd/system/docker.service 为: 将其中第11行的 ExecStart=/usr/bin/dockerd 替换为:ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///va

执行Docker build时,有部分需要×××的需求,通过引入http_proxy 解决:

对第一种方法改进.在在Docker file 里面先写上,这种会增加镜像大小 ENV http_proxy http://ip:port 最后在把ENV http_proxy "" 2. 在build 中加入参数解决: docker build \--build-arg http_proxy=http://10.188.61.2:8118 \--build-arg https_proxy=https://10.188.61.2:8118 \-f Dockerfile . -t imag