Docker swarm: 'build' configuration in docker compose file ignored during stack deployment

后端 未结 3 968
我在风中等你
我在风中等你 2021-02-02 11:02

We have created a docker compose file with multiple services. The images for these services are built in runtime using \'build\' configuration option. The corresponding Dockerfi

相关标签:
3条回答
  • 2021-02-02 11:30

    If anyone is still on this you can tag the built image in compose by setting the image parameter along with the build parameter, as you can see in the build section of the docs. So the file should look like:

    version: '3'
    services:
      db2server:
        image: <your registry here>/db2server
        build: ./db2server
        ports:
          - "50005:50000"
        command: ["db2start"]
      appruntime:
        image: <your registry here>/appruntime
        build: ./appruntime
        depends_on:
         - db2server
    

    then you can do:

    docker-compose build
    docker-compose push
    docker stack deploy -c /home/docker/docker-compose.yml app
    
    0 讨论(0)
  • 2021-02-02 11:37

    Short answer is, you can not use the build command with docker stack deploy.

    From the docs:

    Note: The docker stack command build option is ignored when deploying a stack in swarm mode with a (version 3) Compose file. The docker stack command accepts only pre-built images.

    An alternative is to build the docker image before deploying the your swarm cluster.

    Use the docker build command to create the docker image; Push the created image to a (public or private) docker registry; and reference it in your docker compose file.

    0 讨论(0)
  • 2021-02-02 11:40

    The compose file serves both tools: docker-compose cli, and docker stack cli. the "build" options work in docker-compose but are ignored by stack commands, and the "deploy" options work in stack commands but are ignored by docker-compose.

    Swarm is not designed to build your images for you. It assumes you're images are available in a image registry. Multiple nodes in a Swarm can't share images with each other, so a registry (either remote or running on the Swarm itself) is the only way they can all ensure they can pull the same exact image.

    So the typical example is to either have Docker Hub auto-build your images based on code commits, or have your CI/CD platform build the images and push to a registry. Then your stack deploy commands will pull the proper image from that registry.

    0 讨论(0)
提交回复
热议问题