gpt4 book ai didi

docker - Varnish docker 容器无响应

转载 作者:行者123 更新时间:2023-12-02 19:22:44 27 4
gpt4 key购买 nike

我想在Laradock上运行 Varnish 。
我从docker hub进行了 Varnish 配置。

问题在于,甚至没有503错误,并且 Varnish 日志中也没有日志。
80端口仅用于 Varnish (nginx容器已脱胶进行测试)。
如果在端口80上激活了nginx容器,那么我可以毫无问题地访问网站。

有谁知道为什么根本无法到达 Varnish 容器?在那里进行研究的下一步是什么?

Dockerfile:

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

容器已启动并正在运行:
container log
Docker ps输出:
docker ps

最佳答案

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

关于docker - Varnish docker 容器无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58589793/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com