主机无法访问 Wildfly 容器
Posted
技术标签:
【中文标题】主机无法访问 Wildfly 容器【英文标题】:Wildfly Container Not Reachable from Host 【发布时间】:2022-01-09 10:04:43 【问题描述】:我需要访问在容器内部署到 wildfly 的应用程序,但我无法这样做。我绝对确定应用程序正在容器内的端口 8443 上运行。 为了构建镜像,我使用这个命令,注意端口转发参数。
docker run -p 8443:8443 folio-authentication-local:latest
要运行图像,我使用以下命令:
docker run -p 8443:8443 folio-authentication-local:latest
容器启动时没有错误。另外,我可以在容器中打开一个 shell 并点击端点,我会看到返回的内容(见下面的屏幕截图)。
但是,在主机浏览器中,我收到一个找不到页面的错误(请参阅第二个屏幕截图)。
希望有人可以让我知道我缺少什么。
Dockerfile:
### BUILD image
FROM maven:3.5-jdk-8-alpine as builder
ARG BRANCH_NAME=local
ARG mongo_replicaset=localhost:27017,localhost:27017,localhost:27017
EXPOSE 8443
# Create app folder for sources
RUN mkdir -p /build
WORKDIR /build
COPY pom.xml /build
# Download all required dependencies into one layer
RUN mvn -B dependency:resolve dependency:resolve-plugins
# Copy source code
COPY src /build/src
# Build application
RUN mvn package
WORKDIR /
# Copy all configurations into the image from the host
RUN mkdir -p /WildflyConfiguration
COPY /WildflyConfiguration/* /WildflyConfiguration
# Copy all scripts into the image from the host
RUN mkdir -p /SetStandaloneXmlSettingsScripts
COPY /SetStandaloneXmlSettingsScripts/* /SetStandaloneXmlSettingsScripts
# Set permissions on the folder
RUN chmod -R 777 ./SetStandaloneXmlSettingsScripts
#Update the standalone.xml file
RUN if [ "$BRANCH_NAME" = "development" ]; then \
./SetStandaloneXmlSettingsScripts/setEKSDevStandaloneXmlSettings.sh; \
elif [ "$BRANCH_NAME" = "local" ]; then \
./SetStandaloneXmlSettingsScripts/setLocalStandaloneXmlSettings.sh; \
else \
echo "There was no branch name found that matches your standalon" && exit 1; \
fi
#Create the deployment
FROM jboss/wildfly:21.0.2.Final as Final
#Copy the artifact to the deployments folder
COPY --from=builder /build/target/Authentication.war /opt/jboss/wildfly/standalone/deployments/Authentication.war
#Copy the standalone configuration into wildfly
COPY --from=builder /WildflyConfiguration/standalone.xml /opt/jboss/wildfly/standalone/configuration/standalone.xml
ENTRYPOINT ["/opt/jboss/wildfly/bin/standalone.sh"]
【问题讨论】:
【参考方案1】:默认情况下,WildFly 配置为绑定到环回地址 (127.0.0.1),因此您无法从容器外部访问服务器。您可以通过将 -b
参数传递给 standalone.sh
来覆盖它。
例如,要绑定到所有可用接口,您可以将ENTRYPOINT
修改为以下内容。
ENTRYPOINT ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]
【讨论】:
以上是关于主机无法访问 Wildfly 容器的主要内容,如果未能解决你的问题,请参考以下文章