清漆 docker 容器没有响应

No response from varnish docker container

我要在 Laradock 上涂 运行 清漆。 我从 docker hub.

获取清漆配置

问题是连503错误都没有,清漆日志里也没有记录。 80 端口仅用于清漆(nginx 容器已停用以进行测试)。 如果 nginx 容器在端口 80 上激活,那么我可以毫无问题地访问网站。

有人知道为什么清漆容器根本无法访问吗?在那里进行研究的下一步是什么?

Docker文件:

FROM varnish:6.3

# Set Environment Variables
ENV DEBIAN_FRONTEND noninteractive

# Install Dependencies
#RUN apt-get update && apt-get install -y apt-utils && apt-get upgrade -y
#RUN mkdir /home/site && mkdir /home/site/cache
#RUN apt-get install -y varnish
#RUN rm -rf /var/lib/apt/lists/*

# Setting Configurations
ENV VARNISH_CONFIG  /etc/varnish/default.vcl
ENV CACHE_SIZE      128m
ENV VARNISHD_PARAMS -p default_ttl=3600 -p default_grace=3600
ENV VARNISH_PORT    6081
ENV BACKEND_HOST    localhost
ENV BACKEND_PORT    80

COPY default.vcl /etc/varnish/default.vcl
COPY start.sh /etc/varnish/start.sh

RUN chmod +x /etc/varnish/start.sh

CMD ["/etc/varnish/start.sh"]

EXPOSE 8080

default.vcl:

vcl 4.1;

backend default {
  .host = "8080";
  .port = "localhost"; // tried 127.0.0.1, workspace, server IP.
}

start.sh:

 #!/usr/bin/env bash
set -e

for name in BACKEND_PORT BACKEND_HOST VARNISH_SERVER
do
    eval value=$$name
    sed -i "s|${${name}}|${value}|g" /etc/varnish/default.vcl
done

echo "exec varnishd \
    -a :$VARNISH_PORT \
    -T 127.0.0.1:6082 \
    -F \
    -f $VARNISH_CONFIG \
    -s malloc,$CACHE_SIZE \
    $VARNISHD_PARAMS"

exec bash -c \
    "exec varnishd \
    -a :$VARNISH_PORT \
    -T 127.0.0.1:6082 \
    -F \
    -f $VARNISH_CONFIG \
    -s malloc,$CACHE_SIZE \
    $VARNISHD_PARAMS"

docker-compose.yml:

version: '3'

networks:
  frontend:
    driver: bridge
  backend:
    driver: bridge

volumes:
  percona:
    driver: local

services:

  ### Workspace Utilities ##################################
  workspace:
    container_name: workspace
    build:
      context: ./workspace
      args:
        - LARADOCK_PHP_VERSION=7.2
        - http_proxy
        - https_proxy
        - no_proxy
    volumes:
      - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
    extra_hosts:
      - "dockerhost:${DOCKER_HOST_IP}"
    ports:
      - "2222:22"
    tty: true
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG}
      - DOCKER_HOST=tcp://docker-in-docker:2375
    networks:
      - frontend
      - backend
    links:
      - docker-in-docker

  ### NGINX Server #########################################
  nginx:
    container_name: Nginx
    build:
      context: ./nginx
      args:
        - PHP_UPSTREAM_CONTAINER=${NGINX_PHP_UPSTREAM_CONTAINER}
        - VARNISH_UPSTREAM_CONTAINER=${VARNISH_PROXY1_BACKEND_HOST}
        - PHP_UPSTREAM_PORT=${NGINX_PHP_UPSTREAM_PORT}
        - VARNISH_UPSTREAM_PORT=80
        - CHANGE_SOURCE=${CHANGE_SOURCE}
        - http_proxy
        - https_proxy
        - no_proxy
    volumes:
      - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
      - ${NGINX_HOST_LOG_PATH}:/var/log/nginx
      - ${NGINX_SITES_PATH}:/etc/nginx/sites-available
      - ${NGINX_SSL_PATH}:/etc/nginx/ssl
    ports:
      - "${NGINX_HOST_HTTP_PORT}:80"
      - "${NGINX_HOST_HTTPS_PORT}:443"
    depends_on:
      - php-fpm
    networks:
      - frontend
      - backend

  ### Varnish ##########################################
  proxy:
    container_name: proxy
    build: ./varnish
    expose:
      - 80
    environment:
      - VARNISH_CONFIG="/etc/varnish/default.vcl"
      - CACHE_SIZE=128m
      - VARNISHD_PARAMS="-p default_ttl=3600 -p default_grace=3600"
      - VARNISH_PORT=80
      - BACKEND_HOST=workspace
      - BACKEND_PORT=8888
      - VARNISH_SERVER=SERVER1
    links:
      - workspace
    networks:
      - frontend

  ### Docker-in-Docker ################################################
  docker-in-docker:
    container_name: docker-in-docker
    image: docker:dind
    privileged: true
    volumes:
      - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}
    expose:
      - 2375
    networks:
      - backend

容器已启动并且 运行正在: Docker ps 输出:

这是因为您实际上是为您的 nginx 发布端口,而不是为您的 varnish 服务发布端口。如果你想从主机访问 proxy 服务,你还应该发布端口。 expose 不发布端口 - 仅用于文档目的。