Nginx [SOLVED]: Unknown mode: host in docker stack deploy

Nginx [SOLVED]: Unknown mode: host in docker stack deploy

Home Forums Nginx Nginx [SOLVED]: Unknown mode: host in docker stack deploy

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36713

    Anonymous

    QuestionQuestion

    My primary goal is to make Nginx service available from only one machine when I expose ports and do stack deploy in docker swarm (Usually we can access exposed service from any machine in the docker swarm cluster). For that I have seen mode: host option.

    But when I use it in docker compose file and do stack deploy then I am getting error service nginx: Unknown mode: host.

    nginx.yml file

    version: "3.4"
    services:
        nginx:
            image: ramidavalapati/nginx:tag1
            deploy:
                mode: host
                restart_policy:
                    condition: on-failure
                placement:
                    constraints: [node.hostname == ram-ThinkPad-E470]
            ports:
                - 80:80
                - 443:443
            volumes:
                - /home/ram/nginxDocker/nginx.conf:/etc/nginx/nginx.conf
                - /home/ram/nginxDocker/logs/access.log:/var/log/nginx/access.log
                - /home/ram/nginxDocker/logs/error.log:/var/log/nginx/error.log
            networks:
                - all
            command: ["nginx", '-g', 'daemon off;']
    
    networks:
        all:
            external: true
    

    Deploy:
    $ sudo docker stack deploy -c nginx.yml nginx

    #36714

    Anonymous

    Accepted AnswerAnswer

    My primary goal is to make Nginx service available from only one machine when I expose ports and do stack deploy (Usually we can access exposed service from any machine in the docker swarm cluster)

    What I understood is, publish and expose ports to only one node and access it only from that node.

    When you publish and expose ports for a service (in your case Nginx) then by default you can access that service from any of the nodes which are the part of docker swarm.

    But if you want your service should only available from one node then you can use your ports section as from

    ports:
      - target: 80
        published: 80
        protocol: tcp
        mode: host
      - target: 443
        published: 443
        protocol: tcp
        mode: host
    

    This makes your service should only available from the machines in which its containers are running.

    Now if you want your service containers should only run on a specific machine then you can use constraints as @Miguel A.C. mentioned.

    Source: https://stackoverflow.com/questions/47976309/unknown-mode-host-in-docker-stack-deploy
    Author: prasanna
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.