1

I am new to docker swarm and docker compose.

I built an application that uses a nginx and flask docker containers. nginx acts as a reverse proxy.

when I am building this entire application using docker compose everything works fine

my docker-compose.yml file

version: '2'

services:
  web:
    restart: always
    build: ./web
    image: shivanand3939/web
    expose:
      - "8000"
    volumes:
      - ./output:/usr/src/app/static
    command: /usr/local/bin/gunicorn -w 2 -b :8000 --access-logfile - classifierv2RestEndPoint_ridge_NB:create_app()

  nginx:
    build: ./nginx/
    image: shivanand3939/nginx
    ports:
      - "80:80"
    volumes:
      - /www/static
    volumes_from:
      - web
    links:
      - web:web

  viz:
    image: dockersamples/visualizer
    ports:
      - 8080:8080/tcp
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - "constraint=node.role==manager"

Below is my output:

enter image description here

however, now I want to take it to the next level by deploying it in 3 AWS instances

here is my docker-stack.yml file

version: '3'

networks:
  mybridge:

services:
  web:
    restart: always
    build: ./web
    image: shivanand3939/web
    expose:
      - "8000"
    volumes:
      - ./output:/usr/src/app/static
    command: /usr/local/bin/gunicorn -w 2 -b :8000 --access-logfile - classifierv2RestEndPoint_ridge_NB:create_app()   
    networks:
      mybridge:
        aliases:
          - web
    deploy:
      replicas: 2
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure

  nginx:
    restart: always
    build: ./nginx/
    image: shivanand3939/nginx
    ports:
      - "80:80"
    volumes:
      - /www/static
    networks:
      - mybridge
    deploy:
      replicas: 1
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure

  viz:
    image: dockersamples/visualizer
    ports:
      - 8080:8080/tcp
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    deploy:
      placement:
        constraints: [node.role == manager]

But now when I deploy this application and check the URL I am getting this

[incorrect home page]

enter image description here

I am not understanding why in the first case there was communication between web and nginx containers but in the second case this communication is stopped.

Can anyone please guide me on this

UPDATE 1:

Upon looking at the nginx service logs I see,

classifierbot_nginx.1.qhi4b9c1yc3n@ip-172-31-16-132    | 2017/09/11 06:49:50 [error] 5#5: *10 "/usr/share/nginx/html/phpmyadmin2013/index.html" is not found (2: No such file or directory), client: 10.255.0.2, server: localhost, request: "HEAD http://35.154.66.136:80/phpmyadmin2013/ HTTP/1.1", host: "35.154.66.136"
classifierbot_nginx.1.qhi4b9c1yc3n@ip-172-31-16-132    | 10.255.0.2 - - [11/Sep/2017:06:49:50 +0000] "HEAD http://35.154.66.136:80/phpmyadmin2014/ HTTP/1.1" 404 0 "-" "Mozilla/5.0 Jorgee" "-"
classifierbot_nginx.1.qhi4b9c1yc3n@ip-172-31-16-132    | 2017/09/11 06:49:50 [error] 5#5: *10 "/usr/share/nginx/html/phpmyadmin2014/index.html" is not found (2: No such file or directory), client: 10.255.0.2, server: localhost, request: "HEAD http://35.154.66.136:80/phpmyadmin2014/ HTTP/1.1", host: "35.154.66.136"
classifierbot_nginx.1.qhi4b9c1yc3n@ip-172-31-16-132    | 10.255.0.2 - - [11/Sep/2017:06:49:51 +0000] "HEAD http://35.154.66.136:80/phpmyadmin2016/ HTTP/1.1" 404 0 "-" "Mozilla/5.0 Jorgee" "-"
classifierbot_nginx.1.qhi4b9c1yc3n@ip-172-31-16-132    | 2017/09/11 06:49:51 [error] 5#5: *16 "/usr/share/nginx/html/phpmyadmin2016/index.html" is not found (2: No such file or directory), client: 10.255.0.2, server: localhost, request: "HEAD http://35.154.66.136:80/phpmyadmin2016/ HTTP/1.1", host: "35.154.66.136"
classifierbot_nginx.1.qhi4b9c1yc3n@ip-172-31-16-132    | 2017/09/11 06:49:52 [error] 5#5: *17 "/usr/share/nginx/html/phpmyadmin2017/index.html" is not found (2: No such file or directory), client: 10.255.0.2, server: localhost, request: "HEAD http://35.154.66.136:80/phpmyadmin2017/ HTTP/1.1", host: "35.154.66.136"
classifierbot_nginx.1.qhi4b9c1yc3n@ip-172-31-16-132    | 10.255.0.2 - - [11/Sep/2017:06:49:52 +0000] "HEAD http://35.154.66.136:80/phpmyadmin2017/ HTTP/1.1" 404 0 "-" "Mozilla/5.0 Jorgee" "-"
classifierbot_nginx.1.qhi4b9c1yc3n@ip-172-31-16-132    | 10.255.0.2 - - [11/Sep/2017:06:49:55 +0000] "HEAD http://35.154.66.136:80/phpmyadmin2018/ HTTP/1.1" 404 0 "-" "Mozilla/5.0 Jorgee" "-"
classifierbot_nginx.1.qhi4b9c1yc3n@ip-172-31-16-132    | 2017/09/11 06:49:55 [error] 5#5: *18 "/usr/share/nginx/html/phpmyadmin2018/index.html" is not found (2: No such file or directory), client: 10.255.0.2, server: localhost, request: "HEAD http://35.154.66.136:80/phpmyadmin2018/ HTTP/1.1", host: "35.154.66.136"
classifierbot_nginx.1.qhi4b9c1yc3n@ip-172-31-16-132    | 10.255.0.2 - - [11/Sep/2017:06:49:57 +0000] "HEAD http://35.154.66.136:80/phpmanager/ HTTP/1.1" 404 0 "-" "Mozilla/5.0 Jorgee" "-"
classifierbot_nginx.1.qhi4b9c1yc3n@ip-172-31-16-132    | 2017/09/11 06:49:57 [error] 5#5: *19 "/usr/share/nginx/html/phpmanager/index.html" is not found (2: No such file or directory), client: 10.255.0.2, server: localhost, request: "HEAD http://35.154.66.136:80/phpmanager/ HTTP/1.1", host: "35.154.66.136"
  • Add the output of `docker service logs `. Also i have when you use volume `- ./output:/usr/src/app/static`, that will not send the content from your main machine to all nodes. It will just map your current folder path `$PWD/static` in every node and the folder needs to have data on everynode – Tarun Lalwani Sep 11 '17 at 06:25
  • @tarun Did you mean " map you current folder path $PWD/static in every node " as " map you current folder path $PWD/output in every node " ??. I didnt understand this point very clearly, could you please explain. I have added the log information – Shivanand THANGALAPALLI Sep 11 '17 at 07:28
  • So if your `docker-compose.yml` is in `/home/tarun/app/` then docker stack will map `/home/tarun/app/static` on every single node and that folder needs to be present in each node where the container gets deployed. If the the files are missing then things wont work – Tarun Lalwani Sep 11 '17 at 07:32
  • ok, what should be present in /home/tarun/app/static, currently my directory is like this /home/shiv/- /nginx/ - /web/ - /output/ - /input/ docker-compose.yml docker-stack.yml If I add a /static/ folder as well what should be present in it?? – Shivanand THANGALAPALLI Sep 11 '17 at 08:13
  • That you should know, you are sharing `output` folder from your current folder in compose to `/usr/src/app/static`, so you should know why you are sharing it and what you are sharing. Make sure your static files required by nginx are part of the build image itself – Tarun Lalwani Sep 11 '17 at 09:06
  • Ohhk, I get it now...but I am sure the problem is not here, everything works fine in docker compose but in stack its not working. For example after I run docker stack deploy command. I logged into nginx container and pinged web container. it was working fine. Next I tried curl command to http://web:8000, even that was working fine. But I am missing some piece to make this connection happen in docker stack deploy – Shivanand THANGALAPALLI Sep 11 '17 at 09:14
  • Deploy stack locally on machine instead of AWS, check stack on local first – Tarun Lalwani Sep 11 '17 at 09:15
  • I am getting the same problem. docker-compose is working properly, docker stack deploy -c docker-stack.yml classifierbot is not working properly – Shivanand THANGALAPALLI Sep 11 '17 at 09:50
  • Can you check your nginx (default.conf) and see what the upstream server {} contains. Does it contain any IP's of Docker containers. You have to do docker exec -it bash. When I was doing nginx then the Upstream server was empty. If its the same issue , I can help you probably. – Abhishek Galoda Sep 11 '17 at 14:03

0 Answers0