Docker swarm with compose file does not recognize “links”

docker-compose.yml

version: '3.3'

services:

  hello:
    image: dockercloud/hello-world

  service_auth:
    image: beevelop/nginx-basic-auth
    ports:
      - 8080:80
    links:
      - hello:web
    environment:
      HTPASSWD: 'foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.'

docker --version

Docker version 17.09.0-ce, build afdb6d4

docker stack deploy -c docker-compose.yml auth

Ignoring unsupported options: links

Why is links not supported?

SO

it is deprecated.

so better not rely on this and instead prefer other solutions like same network or depends_on or secrets.

Do you know how I can make this work without links? I’ve been trying for some time now and just can’t get my two containers to connect. Afaik services can talk to each other in the default network just by using the service name. Here’s my updated docker-compose.yml (one of the many versions I’ve tried):

version: '3.4'

services:

  web:
    image: dockercloud/hello-world

  service_auth:
    image: beevelop/nginx-basic-auth
    ports:
      - 8080:80
    environment:
      HTPASSWD: 'foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.'
      FORWARD_PORT: 80
      FORWARD_HOST: web

http://localhost:8080 keeps prompting for a password, but does not serve the hello world page :frowning:

FORWARD_HOST and FORWARD_PORT shouldn’t be necessary as they default to web:80.

docker exec <nginx container id> cat /etc/nginx/conf.d/auth.conf shows the correct nginx configuration:

server {
 listen 80 default_server;

 location / {
     auth_basic              "Restricted";
     auth_basic_user_file    auth.htpasswd;

     proxy_pass                          http://web:80;
     proxy_read_timeout                  900;
 }
}

The nginx basic auth repo is here. Default credentials are: foo/bar.

I finally got it working. Here is the compose file:

version: '3.4'

services:

  web:
    image: dockercloud/hello-world

  service_auth:
    image: redmarker/nginx-basic-auth
    ports:
      - 8081:80
    depends_on:
      - web
    environment:
      HTPASSWD: 'foo:$$apr1$$odHl5EJN$$KbxMfo86Qdve2FH4owePn.'
      FORWARD_PORT: 80
      FORWARD_HOST: web

$ characters must be escaped with a second $ character in docker-compose.yml.

1 Like