【问题标题】:Docker Swarm - communicate between two containers?Docker Swarm - 两个容器之间的通信?
【发布时间】:2020-01-11 23:04:06
【问题描述】:

我创建了 docker-compose.yml,它可以在我的计算机(本地)上运行,但不能在服务器(docker swarm、portainer)上运行。容器 nginx 看不到 php-fpm。

docker-compose.yml:

version: "3"

services:
  nginx:
    image: nginx-php-test:8
    ports:
    - "8888:80"
    restart: always
    environment:
    - ROLE=nginx #run nginx

  fpm:
    image: nginx-php-test:8
    environment:
    - ROLE=fpm #run php
    restart: always

在 /etc/nginx/conf.d/default:

...
fastcgi_pass fpm:9000;
...

和 nginx-php-test 的 entrypoint.sh:

#!/bin/bash

if [ "$ROLE" == "nginx" ]; then
    exec /usr/sbin/nginx
elif [ "$ROLE" == "fpm" ]; then
    exec /usr/sbin/php-fpm7.4 -F
fi

如何连接到 fpm 容器?

【问题讨论】:

  • 我认为这不可能。
  • @RobertMoskal 看看我的回答 ;)

标签: docker docker-compose swarm portainer


【解决方案1】:

我找到了解决办法:

version: "3"

services:
  nginx:
    image: nginx-php-test:8
    ports:
    - "8888:80"
    restart: always
    environment:
    - ROLE=nginx #run nginx

  fpm:
    image: nginx-php-test:8
    environment:
    - ROLE=fpm #run php
    restart: always
networks:
    nginx-php:
      driver: overlay

【讨论】:

  • 这真的是两个容器之间的通信吗?
  • 是的,我查过了。你也可以这样:networks: nginx-php:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-17
  • 1970-01-01
  • 2018-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多