skip to Main Content

Hi guys and excuse me for my English. I’m using docker swarm, when I attempt to deploy docker application with this command

docker stack deploy -c docker-compose.yml -c docker-compose.prod.yml chatappapi

it shows the next error : services.chat-app-api Additional property pull_policy is not allowed

why this happens?
how do I solve this?

docker-compose.yml

version: "3.9"
services:
    nginx:
        image: nginx:stable-alpine 
        ports: 
            - "5000:80"
        volumes:
            - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    chat-app-api:
        build: .
        image: username/myapp
        pull_policy: always
        volumes:
            - ./:/app
            - /app/node_modules
        environment: 
            - PORT= 5000
            - MAIL_USERNAME=${MAIL_USERNAME}
            - MAIL_PASSWORD=${MAIL_PASSWORD}
            - CLIENT_ID=${CLIENT_ID}
            - CLIENT_SECRET=${CLIENT_SECRET}
            - REDIRECT_URI=${REDIRECT_URI}
            - REFRESH_TOKEN=${REFRESH_TOKEN}
        depends_on: 
            - mongo-db
    mongo-db:
        image: mongo
        environment: 
            MONGO_INITDB_ROOT_USERNAME: 'username'
            MONGO_INITDB_ROOT_PASSWORD: 'password'
        ports:
            - "27017:27017"
        volumes: 
            - mongo-db:/data/db
volumes: 
    mongo-db:

docker-compose.prod.yml

version: "3.9"
services: 
    nginx:
        ports: 
            - "80:80"
    chat-app-api:
        deploy:
            mode: replicated
            replicas: 8
            restart_policy:
                condition: any
            update_config:
                parallelism: 2
                delay: 15s
        build:
            context: .
            args: 
                NODE_ENV: production
        environment: 
            - NODE_ENV=production
            - MONGO_USER=${MONGO_USER}
            - MONGO_PASSWORD=${MONGO_PASSWORD}
            - MONGO_IP=${MONGO_IP}
        command: node index.js
    mongo-db:
        environment: 
            MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER}
            MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}

Information

  • docker-compose version 1.29.2
  • Docker version 20.10.8
  • Ubuntu 20.04.2 LTS

Thanks in advance.

3

Answers


  1. Your problem line is in docker-compose.yml

    chat-app-api:
        build: .
        image: username/myapp
        pull_policy: always    # <== this is the bad line, delete it
    

    The docker compose file reference doesn’t have any pull_policy in the api because

    If the image does not exist, Compose attempts to pull it, unless you have also specified build, in which case it builds it using the specified options and tags it with the specified tag.

    I think pull_policy used to be a thing for compose? Maybe keep the latest api documentation open to refer to/search through whilst you’re developing (things can and do change fairly frequently with compose).

    If you want to ensure that the most recent version of an image is pulled onto all servers in a swarm then run docker compose -f ./docker-compose.yml pull on each server in turn (docker stack doesn’t have functionality to run this over an entire swarm yet).

    As an aside: I wouldn’t combine two .yml files with a single docker stack command without a very good reason to do so.

    Login or Signup to reply.
  2. You are mixing docker-compose and docker swarm ideas up in the same files:

    It is probably worth breaking your project up into 3 files:

    docker-compose.yml
    This would contain just the basic service definitions common to both compose and swarm.

    docker-compose.override.yml
    Conveniently, docker-compose and docker compose both should read this file automatically. This file should contain any "port:", "depends_on:", "build:" directives, and any convenience volumes use for development.

    stack.production.yml
    The override file to be used in stack deployments should contain everything understood by swarm and not compose, and b. everything required for production.
    Here you would use configs: or even secrets: rather than volume mappings to local folders to inject content into containers. Rather than relying on ports: directives, you would install an ingress router on the swarm such as traefik. and so on.

    With this arrangement, docker compose can be used to develop and build your compose stack locally, and docker stack deploy won’t have to be exposed to compose syntax it doesn’t understand.

    Login or Signup to reply.
  3. pull_policy is in the latest version of docker-compose.

    To upgrade your docker-compose refer to:
    https://docs.docker.com/compose/install/

    The spec for more info:
    https://github.com/compose-spec/compose-spec/blob/master/spec.md#pull_policy

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search