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

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

问题描述

docker-compose builddocker 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 的包装器(实际上它是 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,传递给 docker 的上下文和参数.

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

以一个示例 docker-compose.yml 文件结束:

To conclude with an example docker-compose.yml file :

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天全站免登陆