2

Docker | 构建镜像

 2 years ago
source link: https://ijayer.github.io/post/tech/devops/docker/20170410-build-image/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

构建镜像 docker build

$ docker build [选项] <上下文路径/URL/->
$ docker build -t nginx:v3 .

镜像构建的上下文(Context)

docker build工作原理

C/S模式,Docker Client通过Docker Daemon提供的REST API以远程调用的方式与服务器进行交互;而docker build构建镜像是在服务端进行,其所需文件由客户端打包上传

构建镜像时的上下文路径,即docker build打包的文件所依赖的路径;用户指定构建镜像的上下文路径后,docker build命令会去打包该路径下的所有内容,然后上传给docker引擎进行构建

$ docker build -t nginx:v3 ../nginx
$ COPY ./package.json /app/     

这里./package.json是相对于docker build指定的路径,在上下文中为:../nginx/package.json,而不是执行docker build命令所在目录。

.dockerignore

类似.gitignore, 用户忽略不需要作为上下文传递给docker引擎的文件

其他docker build用法

直接用git repo进行构建

$ docker build https://github.com/twang2218/gitlab-ce-zh.git#:8.14

用给定的tar压缩包进行构建

$ docker build http://server/context.tar.gz

从标准输入读取Dockerfile进行构建

$ docker build - < Dockerfile
$ cat Dockerfile | docker build -

从标准输入中读取上下文进行构建

$ docker build - < context.tar.gz

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK