Docker Community Forums

Share and learn in the Docker community.

Cannot set nginx bind mount in docker stack yml

Hi,

I cannot set the nginx bind mount in docker stack yml, for a custom nginx service.

In docker-stack. yml :

  proxy:
    image: nginx:1.13
    ports:
      - '80:80'
    volumes:
      - type: "bind"
        source: "./proxy/my-nginx.conf"
        target: "/etc/nginx/nginx.conf"
#      - "./proxy/my-nginx.conf:/etc/nginx/nginx.conf"
    networks:
      - frontend
      - backend
    deploy:
      placement:
        constraints: [node.role == manager]

I tried both short form and long form.

docker stack deploy --compose-file docker-stack.yml vote

Short form :
docker service ps vote_proxy
“invalid mount config for type…”

Long form, service is not even created :
services.proxy.volumes.0 must be a string

And if I try to first create custum nginx image, I get this :
docker service ps vote_proxy :
“No such image: mynginx:latest”

The syntax should be just fine, if you switch to absolute paths on the source value as well.

Though, on swarm stack deployments you typicaly would use a config instead of a bind, because the bind will fail if you have more than one node that fullfils the placement contrain and the file does not exist in the same location on every node!

A config instead of a bind ?
How ? I simply want my “my-nginx.conf” copied in place of the nginx config.

And why “No such image: mynginx:latest” ? Should I built the image in all nodes ?

You are not seriously running a swarm and build your own images without running a private container registry, are you? Dock swarm is neither responsible to distribute the image amongst nodes (hint: run your own private container registry), nor distribute the content of volumes amongst them (hint: use a remote share, preferably nfsv4).

You should make it a habit to lookup configuration items in the compose file version 3 reference when it commes to swarm stack compose files.

I was trying with the official nginx. But the bind mount is not working.

So I’m building a local image with that bind, and I want to use that in my docker-machine swarm.
Is this possible ?

I have no idea what private container registry is, I will look.
And using remote share, no idea how. I’m new to Docker swarm

But in my case, what would be best to do ?

The app is working without nginx.
I just want to add the nginx proxy to my docker stack yml file.

Here is the proxy I want to add :

Stick with the offical image and use “configs” (chek the long syntax!) to “mount” the nginx.conf.

Good luck!

Thank I got it working with the “configs”.

But cannot start it back again :

The postgres and worker service stays at replica 0/1.

Do you know why ?

docker service logs vote_db
and
docker service logs vote_worker :

Empty, buy they are running (but 0/1 replica).

Take a look at the output of: docker stack ps ${stackname} --no-trunc.

Some people read docs, get to a certain point and then share the relevant information and ask for support…
Others don’t care to read docs, and directly ask for help, without even providing enough relevant details.
Honestly, while I enjoy helping the first kind, it is cumbersom to help the second kind.

May I suggest this fabulous, free, self-paced docker training to get a better understanding? https://container.training/intro-selfpaced.yml.html

2 Likes

This clearly says that it’s a permission issue. Please check document root “/data/www/” is owned by Nginx user. You can also change the ownership by entering container with below commands.

docker exec -it bash

Give this a try and post back with the errors you have identified and we shall try to resolve it.

The shity bot strikes again! @trogne: please, ignore lewish95