码头集装箱无法连接到其他集装箱- nginx在alpine到nginx在alpine

voj3qocg  于 2022-11-02  发布在  Nginx
关注(0)|答案(2)|浏览(167)

我不知道怎么从nginx alpine转机到nginx alpine
都使用Laravel 9
在主机上,我可以使用http://localhost:8080和http://localhost:5001进行访问
但当我在前端这样使用guzzle时

$response = $http->get('http://dashboard:5001');

结果是

cURL error 7: Failed to connect to dashboard_service port 5001 after 0 ms: 
Connection refused

我尝试从前端容器到 Jmeter 板容器进行curl,结果连接被拒绝。我可以ping它,但curl不起作用
这是我的docker-compose.yml

version: "3.8"

networks:
  networkname:

services:
  frontend:
    build:
      context: .
      dockerfile: ./file/Dockerfile
    container_name: frontend
    ports:
      - 8080:80
    volumes:
      - ./frontend:/code
      - ./.docker/php-fpm.conf:/etc/php8/php-fpm.conf
      - ./.docker/php.ini-production:/etc/php8/php.ini
      - ./.docker/nginx.conf:/etc/nginx/nginx.conf
      - ./.docker/nginx-laravel.conf:/etc/nginx/modules/nginx-laravel.conf
    networks:
      - networkname

  dashboard:
    build:
      context: .
      dockerfile: ./file/Dockerfile
    container_name: dashboard
    ports:
      - 5001:80
    volumes:
      - ./dashboard:/code
      - ./.docker/php-fpm.conf:/etc/php8/php-fpm.conf
      - ./.docker/php.ini-production:/etc/php8/php.ini
      - ./.docker/nginx.conf:/etc/nginx/nginx.conf
      - ./.docker/nginx-laravel.conf:/etc/nginx/modules/nginx-laravel.conf
    networks:
      - networkname

这是我dockerfile

FROM alpine:latest

WORKDIR /var/www/html/

# Essentials

RUN echo "UTC" > /etc/timezone
RUN apk add --no-cache zip unzip curl sqlite nginx supervisor

# Installing PHP

RUN apk add --no-cache php8 \
    php8-common \
    php8-fpm \

# Installing composer

RUN curl -sS https://getcomposer.org/installer -o composer-setup.php
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN rm -rf composer-setup.php

# Configure supervisor

RUN mkdir -p /etc/supervisor.d/
COPY .docker/supervisord.ini /etc/supervisor.d/supervisord.ini

# Configure PHP

RUN mkdir -p /run/php/
RUN mkdir -p /test
RUN touch /run/php/php8.0-fpm.pid

CMD ["supervisord", "-c", "/etc/supervisor.d/supervisord.ini"]

这是我nginx会议

server {
listen 80;
server_name localhost;
root /code/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index 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_pass localhost:9000;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    include fastcgi_params;
}

location ~ /\.(?!well-known).* {
    deny all;
}
}

我对在docker、nginx或alpine linux中设置它感到困惑

  • 谢谢-谢谢
b09cbbtk

b09cbbtk1#

你好,如果你尝试从容器的PHP里面,你不需要检查它与端口
在php中键入这样的内容:

$response = $http->get('http://dashboard');

但是,如果您从out container中检查此内容,则可能会输入类似ip:port的内容

$response = $http->get('http://127.0.0.1:5001');
p4tfgftt

p4tfgftt2#

如果要连接到同一网络中的Docker容器,请使用内部端口。否则,请使用外部端口。
在您的示例中,您尝试从networkname网络中连接到 Jmeter 板容器。

相关问题