无法访问apache docker服务器

问题描述 投票:0回答:1

在我的docker镜像中,我需要运行Apache Server来部署我的网站,一个用于部署相应后端的glassfish服务器和后端连接的MongoDB。

我的dockerfile如下所示:

FROM httpd:2.4
FROM glassfish:latest
FROM mongo:3.6


COPY /backend_war_exploded /usr/local/glassfish4/glassfish/domains/domain1/autodeploy/backend_war_exploded
COPY /backend_war_exploded /usr/local/glassfish4/bin/backend_war_exploded
COPY /dist /usr/local/apache2/htdocs/

构建映像后,我运行并启动它:

docker run -dit --name application -p 80:80 -p 8080:8080 -p 27017:27017 applicationimg
docker start application 

当我尝试通过http://localhost:80访问时,它提供了代码:ERR_EMPTY_RESPONSE。后端相同,但我可以访问mongodb端口上的27017。当我在我的FROM中评论dockerfile标签并分别运行时,它工作正常。有人看到了这个错误吗?提前致谢。

更新我按照你的建议创建了重写了Dockerfile:

FROM ubuntu:16.04

COPY /dist /var/www/html/
COPY /backend_war_exploded /glassfish4/glassfish/domains/domain1/autodeploy/backend_war_exploded

RUN apt-get update && apt-get install -y apache2

RUN apt-get install -y openjdk-8-jdk
RUN apt-get install -y wget && apt-get install -y unzip
RUN wget http://download.java.net/glassfish/4.1.2/release/glassfish-4.1.2.zip

RUN unzip glassfish-4.1.2.zip

RUN cd /glassfish4/bin/ && ./asadmin start-domain domain1




EXPOSE 80
EXPOSE 8080

Web服务器启动并可通过localhost:80访问,但glassfish服务器在构建映像时启动,但在运行docker映像时,它不再启动。当我通过docker exec访问容器时,我可以导航到glassfish并手动启动它。有什么问题?

mongodb apache docker glassfish
1个回答
0
投票

您需要仅依靠FROM并通过RUN步骤添加其他工具。或者为每个应用程序使用单个图像,并通过docker network或通过创建更容易的docker-compose.yml将它们连接在一起,您可以通过here进行检查。使用多个FROM并不意味着你将拥有所有3合1。

有关如何创建Dockerfile以及如何使用多个容器部署应用程序的更多信息,可以查看Docker的get started教程

为了在一个容器内运行多个服务,您需要使用像Supervisor这样的服务管理器。请查看以下链接以获取更多详细信息:Multi-Service Container

© www.soinside.com 2019 - 2024. All rights reserved.