【发布时间】:2019-02-14 04:58:03
【问题描述】:
我对 docker 很陌生。我创建了一个 docker-compose,它有 1 个主应用程序(laravel)站点和 2 个 api。
我正在尝试从 laravel 站点访问 api,但不断得到:
cURL error 7: Failed to connect to 0.0.0.0 port 8082: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
我的 docker-compose.yml 是:
version: '3'
services:
web:
image: nginx:1.10
volumes:
- ./vhost.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"
depends_on:
- app
restart: always
app:
build: . #run the dockerfile to install whatever
env_file: .env
volumes:
- ./:/var/www
depends_on:
- database
web-api2:
image: nginx:1.10
volumes:
- ../api/api2/vhost.conf:/etc/nginx/conf.d/default.conf
ports:
- "8081:81"
depends_on:
- app-api2
app-api2:
build: . #run the dockerfile to install whatever
env_file: .env
volumes:
- ../api/api2:/var/www
depends_on:
- database
web-api1:
image: nginx:1.10
volumes:
- ../api/api1/vhost.conf:/etc/nginx/conf.d/default.conf
ports:
- "8082:82"
depends_on:
- app-api1
app-api1:
build: . #run the dockerfile to install whatever
env_file: ../api/api1/.env
volumes:
- ../api/api1:/var/www
depends_on:
- database
database:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=IAmSoSecure"
- "MYSQL_DATABASE=my_app"
ports:
- "33061:3306"
volumes:
- my_app:/var/lib/mysql
restart: always
volumes:
wildfire:
我研究了 docker 网络,但我的尝试失败了。我有一个网络设置,并尝试使用子网,但它没有成功:
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
我也尝试过访问我启用的端口:
"Ports": {
"443/tcp": null,
"80/tcp": null,
"82/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8082"
}
]
},
我像往常一样通过 Guzzle 请求通话:
$client = new Client();
$res = $client->get('127.0.0.1:8082/accounts');
dd($res->getBody()->getContents());
我尝试了不同的 IP,但找不到要使用的正确 IP。
我当前的 vhost.conf 是:
server {
listen 80;
index index.php server.php;
root /var/www/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html server.php index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
include /etc/nginx/mime.types;
}
location ~ /\.(?!well-known).* {
deny all;
}
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
}
【问题讨论】:
-
您是否尝试过运行
docker-compose down,然后再次运行docker-compose up? -
不幸的是,将其关闭并再次打开似乎并没有奏效。大声笑...
-
由于您使用的是 8082 端口,我假设您有一个容器试图联系
app-api2。尝试将127.0.0.1替换为app-api2。
标签: laravel api docker docker-compose lumen