0
version: '3.7'
services:
  shinyproxy:
    build: /home/administrator/shinyproxy
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.hostname==testnode
    user: root:root
    hostname: shinyproxy
    image: shinyproxy-example
    restart: always
    networks:
      - sp-example-net
    volumes:
      - type: bind
        source: /var/run/docker.sock
        target: /var/run/docker.sock
      - type: bind
        source: /home/administrator/shinyproxy/application.yml
        target: /opt/shinyproxy/application.yml
    ports:
      - 4000:4000
  mariadb:
    image: mariadb
    networks:
      - sp-example-net
    volumes:
      - type: bind
        source: /home/administrator/mariadbdata
        target: /var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: keycloak
      MYSQL_USER: keycloak
      MYSQL_PASSWORD: xyz
    deploy:
      placement:
        constraints:
          - node.hostname==testnode
  keycloak:
    image: jboss/keycloak
    networks:
      - sp-example-net
    volumes:
      - type: bind
        source: /home/administrator/compose/nginx/fullchain.pem
        target: /etc/x509/https/tls.crt
      - type: bind
        source: /home/administrator/compose/nginx/privkey.pem
        target: /etc/x509/https/tls.key
      - ./theme/:/opt/jboss/keycloak/themes/custom/
    environment:
      - PROXY_ADDRESS_FORWARDING=true
      - KEYCLOAK_USER=xyzasd
      - KEYCLOAK_PASSWORD=xyz
    ports:
      - 8443:8443
    deploy:
      placement:
        constraints:
          - node.hostname==testnode
    restart: "always"
  nginx_service:
    image: nginx_custom
    ports:
      - '80:80'
      - '443:443'
    build: ./nginx/
    networks:
      - sp-example-net


networks:
  sp-example-net:
    driver: overlay
    external: true
    attachable: true

这是我的compose file。keycloak 服务对 shinyproxy 用户进行身份验证。我docker-compose up --build -d用来让所有东西都运行起来,并且可以正常工作。有时我必须更改我的shinyproxy服务的一小部分并使用相同的命令更新所有内容:检测到更改并且输出如下所示:

compose_keycloak_1 is up-to-date
Recreating compose_shinyproxy_1 ... done

我正在结合运行这些服务nginx并收到以下错误:

nginx_service_1  | 2020/06/05 10:02:11 [error] 7#7: *54 connect() failed (113: No route to host) while connecting to upstream, client: 185.130.32.1, server: myserver.com, request: "GET / HTTP/1.1", upstream: "http://10.0.3.181:4000/", host: "myserver.com"

运行docker-compose down然后docker-compose up --build再次工作,但我不想仅仅为了更新一个服务而关闭我的所有服务。谁能告诉我为什么会发生这种情况以及如何解决?

编辑:我越来越确定这是一个 nginx 问题,而不是 docker 问题。可能是这样吗?

我的 nginx.conf 看起来像这样:

server {
  listen                443;
  server_name           server.com;

  ssl on;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
  ssl_prefer_server_ciphers on;
  ssl_session_cache shared:SSL:10m;

  ssl_certificate /etc/certs/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/certs/privkey.pem; # managed by Certbot


   location / {

    proxy_pass          http://shinyproxy:4000; ### Übernahme der servicenamen aus Docker-compose

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 600s;

    proxy_redirect    off;
    proxy_set_header  Host             $http_host;
    proxy_set_header  X-Real-IP        $remote_addr;
    proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Protocol $scheme;

    }
....

edit2:问题可能与此有关: https ://github.com/docker/compose/issues/2003

4

2 回答 2

0

实际上,您可以通过docker-compose down运行. 看看这个例子。docker-compose up --builddocker-compose up -d serviceName

-d代表守护程序/分离模式。

version: '3'
services:
  test:
    container_name: test
    image: 'busybox'
    command: 'sleep 5d'
  test1:
    container_name: test1
    image: 'busybox'
    command: 'sleep 4d'
$ docker-compose up -d
Creating network "proj_default" with the default driver
Creating test  ... done
Creating test1 ... done

$ docker-compose ps
Name    Command    State   Ports
--------------------------------
test    sleep 5d   Up           
test1   sleep 5d   Up 

$ docker-compose up -d test1 
Recreating test1 ... done


于 2020-06-05T10:23:27.873 回答
0

解决办法是重启nginx。似乎每次重新启动后容器都会获得一个新 IP,而 nginx 使用旧 IP 并且无法找到它。

更新上游服务器时重启 nginx 容器

docker exec <nginx_container_id> nginx -s reload
于 2020-06-05T12:21:24.963 回答