What is the difference between `docker-compose build` and `docker build`?

前端 未结 5 1641
日久生厌
日久生厌 2020-12-23 03:11

What is the difference between docker-compose build and docker build?

Suppose in a dockerized project path there is a docker-compo

5条回答
  •  感情败类
    2020-12-23 03:13

    Adding to the first answer...

    You can give the image name and container name under the service definition.

    e.g. for the service called 'web' in the below docker-compose example, you can give the image name and container name explicitly, so that docker does not have to use the defaults.

    Otherwise the image name that docker will use will be the concatenation of the folder (Directory) and the service name. e.g. myprojectdir_web

    So it is better to explicitly put the desired image name that will be generated when docker build command is executed.

    e.g. image: mywebserviceImage container_name: my-webServiceImage-Container

    example docker-compose.yml file :

    version: '3.2'
    services:
      web:
        build:
          dockerfile: Dockerfile-alpine
          context: ./web
        ports:
          - 8099:80
        image: mywebserviceImage
        container_name: my-webServiceImage-Container
        depends_on:
          - database
    

提交回复
热议问题