我使用docker-compose通过以下app.yml设置我的应用程序:
version: '2'
services:
hdback-app:
image: xxxx:0.0.3
environment:
- SPRING_PROFILES_ACTIVE=prod,swagger
- SPRING_DATASOURCE_URL=jdbc:mysql://db:3306/sample?useUnicode=true&characterEncoding=utf8&useSSL=false
- JHIPSTER_SLEEP=10 # gives time for the database to boot before the application
- SPRING_DATA_ELASTICSEARCH_CLUSTER_NODES=sample-elasticsearch:9300
ports:
- 8080:8080
db:
extends:
file: mysql.yml
service: db
nginx:
extends:
file: nginx.yml
service: nginx
hdback-elasticsearch:
extends:
file: elasticsearch.yml
service: hdback-elasticsearch
phpmyadmin:
image: phpmyadmin/phpmyadmin
depends_on:
- db
ports:
- 8081:8081
该应用程序已安装在Centos 7上,nginx.yml如下:
services:
nginx:
image: nginx:1.14.0
volumes:
- ./../www:/usr/share/nginx/html
- ./nginx/site.conf:/etc/nginx/conf.d/default.conf
ports:
- "80:80"
site.conf如下:
server {
listen 80;
index index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
location / {
root /usr/share/nginx/html;
}
location /api {
proxy_pass http://www.sample.com:8080/api;
}
location /management {
proxy_pass http://www.sample.com:8080/management;
}
location /v2 {
proxy_pass http://www.sample.com:8080/v2;
}
location /swagger-ui {
proxy_pass http://www.sample.com:8080/swagger-ui;
}
location /swagger-resources {
proxy_pass http://www.sample.com:8080/swagger-resources;
}
}
当我启动该应用程序时,www.sample.com起作用,即端口80起作用,但是,当我想访问phpmyadmin时,浏览器说:
sample.com refused to connect
我禁用防火墙,并确保端口8081正在侦听,以下是我发出的时间:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5a18390de5e1 phpmyadmin/phpmyadmin "/run.sh supervisord…" 24 hours ago Up 24 hours 80/tcp, 9000/tcp, 0.0.0.0:8081->8081/tcp docker_phpmyadmin_1
1de715bb735d nginx:1.14.0 "nginx -g 'daemon of…" 24 hours ago Up 24 hours 0.0.0.0:80->80/tcp docker_nginx_1
6b748cb592ec elasticsearch:2.4.6 "/docker-entrypoint.…" 24 hours ago Up 24 hours 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp docker_hdback-elasticsearch_1
dd3de12c3ff4 mysql:5.7.20 "docker-entrypoint.s…" 24 hours ago Up 24 hours 0.0.0.0:3306->3306/tcp docker_db_1
c0ad30aabd3c xxxx:0.0.3 "/bin/sh -c 'echo \"T…" 24 hours ago Up 24 hours 0.0.0.0:8080->8080/tcp docker_hdback-app_1
我花了将近半天的时间来寻找解决方案,但是没有运气,这是怎么回事?
答案 0 :(得分:2)
它拒绝连接,因为您从主机的端口8081连接到容器的端口8081,而phpmyadmin在端口80上运行,如您所见here
所以用这种方式映射它:
phpmyadmin:
image: phpmyadmin/phpmyadmin
depends_on:
- db
ports:
- 8081:80
它应该可以工作