Can docker compose skip build if the image is present?

后端 未结 2 2047
情书的邮戳
情书的邮戳 2021-01-02 01:48

Is it possible to run docker-compose up in such a way that it will only build if the image isn\'t present in the repository?

I\'m working on a test sce

相关标签:
2条回答
  • 2021-01-02 02:04

    i am using docker-compose v2.1

    when we run docker compose up it check image is exist or not. if not exist then only it build that image otherwise it will skip that part

    docker-compose

    version: '2.1'
    
    services:
      devimage:
        image: nodedockertest
        build: .
        environment:
          NODE_ENV: development
        ports:
          - 8000:8000
    

    0 讨论(0)
  • 2021-01-02 02:06

    You can use docker-compose pull to fetch images. Then if they are present already, Compose will not try to build them again.

    To be really sure to avoid rebuilds, you can use --no-build.

    docker-compose pull
    docker-compose up -d --no-build
    

    Your real problem is that you are specifying a build context, but then trying to use docker-compose without that build context being present.

    When docker-compose runs, even if it has no plan to do a build, it will verify the build context at least exists. If it doesn't, then it will fail.

    All you need to do to satisfy this requirement is create an empty directory for any missing build context. That should make docker-compose happy enough to run.

    mkdir -p local-repo1 local-repo2
    
    0 讨论(0)
提交回复
热议问题