Difference between 'image' and 'build' within docker compose

后端 未结 2 1372
不知归路
不知归路 2021-02-02 06:44

Please help me understand the difference between \'image\' and \'build\' within docker compose

2条回答
  •  失恋的感觉
    2021-02-02 07:08

    build: expects dockerfile path as an argument, it will build an image first and then use the image to create a container.

    image: expects existing image name as argument , it will launch container using this image.

    Example:docker-compose.yaml

    version: '3'
    services:
      service1:
        build: .
        ports:
          - "5000:5000"
      service2:
        image: "redis:alpine"
    

    service1 will build an image first based on Dockerfile of current path and run container based on this image.

    service2 will download "redis:alpine" image from docker hub and run container on downloaded image.

提交回复
热议问题