使用正在运行的nginx代理在docker中运行Teampass

时间:2016-10-24 17:08:05

标签: mysql nginx docker docker-compose

@Moderators:您能否将Tag teampass添加到标签列表中?

我希望将Teampass作为docker容器运行,并将nginx作为代理。

我不确定问题是,Teampass带来了自己的Apache并且对我的nginx起作用,或者如果我有其他完全错误的话。

我这样输入 enter image description here

问题是,它没有通过此页面,因为与mySQL端口的连接无法正常工作。

当我尝试安装它时,没有运行的nginx,一切都按预期工作。但是当我使用nginx时,它不再运行了

docker-compose file:

teampass:
container_name: teampass
image: teampass/teampass
ports:
- 127.0.0.1:8787:80
volumes:
- /opt/teampass:/teampass
links:
- teampass_mysql

teampass_mysql:
restart: always
image: mysql/mysql-server:5.5
ports:
- 127.0.0.1:13306:3306
environment:
- MYSQL_ROOT_PASSWORD=TEAMPASS_MYSQL_ROOT_PASSWORD
- MYSQL_DATABASE=TEAMPASS_MYSQL_DATABASE
- MYSQL_PASSWORD=TEAMPASS_MYSQL_PASSWORD
- MYSQL_USER=TEAMPASS_MYSQL_USER
volumes:
- /opt/dbteampass:/var/lib/mysql

nginx文件:

upstream teampass {
    server 127.0.0.1:8787;
}

upstream sqlteampass {
    server 127.0.0.1:13306;
}

server {
  listen 80;
  server_tokens off;
  server_name teampass.domain.tld;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl;
  server_tokens off;
  server_name teampass.domain.tld;

  ssl_certificate /path/fullchain.pem;
  ssl_certificate_key /path/privkey.pem;

  location / {
    proxy_set_header        Host $host:$server_port;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;
    proxy_pass              http://teampass;
  }
}



server {
  listen 80;
  server_tokens off;
  server_name sql.teampass.domain.tld;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl;
  server_tokens off;
  server_name sql.teampass.domain.tld;

  ssl_certificate /path/fullchain.pem;
  ssl_certificate_key /path/privkey.pem;

  location / {
    proxy_set_header        Host $host:$server_port;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;
    proxy_pass              http://sqlteampass;
  }
}

1 个答案:

答案 0 :(得分:1)

首先确保您的容器之间能够正常工作。

让我们从一个准系统撰写文件开始,请注意我现在要省略卷指令:

# docker-compose.yml

version: '2'
services:
  teampass:
      image: teampass/teampass
      ports:
        - "80:80"
      links:
          - db
  db:
      image: mysql:latest
      ports:
          - "3306:3306"
      environment:
          - MYSQL_DATABASE=teampass
          - MYSQL_PASSWORD=pass
          - MYSQL_ROOT_PASSWORD=rootpass
          - MYSQL_USER=user

如果您仍然运行旧的teampass容器,请确保通过docker-compose rm -v摆脱旧容器!

现在运行docker-compose up,一旦看到db和teampass容器正在运行,就可以验证docker容器是否可以看到彼此:

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
263d801cdf85        teampass/teampass   "/bin/sh -c /start.sh"   14 minutes ago      Up 14 minutes       0.0.0.0:80->80/tcp       dockerteampass_teampass_1
fcb750fffd4f        mysql:latest        "docker-entrypoint.sh"   14 minutes ago      Up 14 minutes       0.0.0.0:3306->3306/tcp   dockerteampass_db_1

记下您正在运行的teampass容器的名称。

$ docker exec -it dockerteampass_teampass_1 bash

现在你进入了teampass容器。要ping数据库容器,只需执行

$ ping db

这不应该超时!

现在转到您的浏览器并开始设置,确保您输入db作为主持人!

这应该删除您的上述错误。 一旦有了这个工作,您可以尝试通过nginx反向代理。

enter image description here

要了解有关泊坞网络的更多信息,请参阅documentation