docker-compose build和docker build有什么区别? [英] What is the difference between `docker-compose build` and `docker build`?

查看:1357
本文介绍了docker-compose build和docker build有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

docker-compose build docker build 有什么区别?

假设在dockerized项目路径中有一个 docker-compose.yml 文件:

Suppose in a dockerized project path there is a docker-compose.yml file:

docker-compose build

然后

docker build


推荐答案

docker-compose 可以看作是Docker CLI的包装器(实际上,它是Docker CLI中的另一个实现)注释中表示为的python ),以节省时间并避免500个字符长的行(并同时启动多个容器)。它使用名为 docker-compose.yml 的文件来检索参数。

docker-compose can be considered a wrapper around the docker CLI (in fact it is another implementation in python as said in the comments) in order to gain time and avoid 500 characters-long lines (and also start multiple containers at the same time). It uses a file called docker-compose.yml in order to retrieve parameters.

您可以找到有关docker-compose文件格式此处

You can find the reference for the docker-compose file format here.

所以基本上 docker-compose build 会读取您的 docker-compose.yml ,查找所有服务包含 build:语句并为每个运行 docker build

So basically docker-compose build will read your docker-compose.yml, look for all services containing the build: statement and run a docker build for each one.

每个 build: 可以指定 Dockerfile ,上下文和args传递给docker。

Each build: can specify a Dockerfile, a context and args to pass to docker.

最后示例 docker-compose.yml 文件:

version: '3.2'

services:
  database:
    image: mariadb
    restart: always
    volumes:
      - ./.data/sql:/var/lib/mysql

  web:
    build:
      dockerfile: Dockerfile-alpine
      context: ./web
    ports:
      - 8099:80
    depends_on:
      - database 

调用 docker-compose build 时,仅 web 目标将需要构建映像。 docker build 命令如下所示:

When calling docker-compose build, only the web target will need an image to be built. The docker build command would look like :

docker build -t web_myproject -f Dockerfile-alpine ./web

这篇关于docker-compose build和docker build有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆