在 docker 主机中无法访问 docker 容器中的应用程序 运行

Application running in docker container not reachable in docker host

我在 Windows 操作系统中有 Ubuntu 18.04 虚拟机。在虚拟机中,安装了docker,是docker主机。使用 Oracle Linux7 创建映像以安装 Weblogic 12 并启动应用程序手动记录到容器。端口映射成功,Weblogic 在容器内 运行 但在 docker 主机和 docker 主机外无法访问。 我想知道我是否缺少任何配置,并且想知道如何对 docker 网络进行故障排除以解决此问题。

FROM oraclebase:v2  # Have the base image created where I have installed Java
#prerequisite create_basedomain.py, verdomain.properties,fmw_12.2.1.0.0_wls_Disk1_1of1.zip

USER root

ENV JAVA_HOME /opt/jdk/jdk1.8.0_131
ENV WLS_PKG fmw_12.2.1.0.0_wls_Disk1_1of1.zip
ENV WLS_JAR fmw_12.2.1.0.0_wls.jar
ENV CREATE_DOMAIN_SCRIPT create_basedomain.py
#This properties file should be passed as a template file. not env specific.
ENV DOMAIN_PROPERTIES verdomain.properties

# Prerequisites
# any prerequisite packages for Weblogic

# Create Oracle base directories
RUN mkdir -p /u01/app/oracle/product/wls122100 && \
    mkdir -p /u01/app/oracle/config/domains && \
    mkdir -p /u01/app/oracle/config/applications

COPY $WLS_PKG wls.rsp oraInst.loc /u01/app/oracle/
COPY $CREATE_DOMAIN_SCRIPT /u01/app/oracle
COPY $DOMAIN_PROPERTIES /u01/app/oracle

# Create functional useraccount
RUN chmod a+xr /u01 && useradd -b /u01 -m -s /bin/bash oracle
WORKDIR /u01/app/oracle/
RUN chown oracle:oracle -R /u01
USER oracle

# Adjust paths as required.
ENV CONFIG_JVM_ARGS="-Djava.security.egd=file:/dev/./urandom"
ENV ORACLE_BASE /u01/app/oracle
ENV ORACLE_HOME $ORACLE_BASE/product/wls122100
ENV MW_HOME $ORACLE_HOME
ENV WLS_HOME $MW_HOME/wlserver
ENV WL_HOME $WLS_HOME
ENV DOMAIN_BASE $ORACLE_BASE/config/domains
ENV DOMAIN_HOME $DOMAIN_BASE/mydomain
ENV PATH="${WLS_HOME}/server/bin:${PATH}"
ENV CLASSPATH=${CLASSPATH}:${WLS_HOME}/server/lib/weblogic.jar:.

RUN echo "export ORACLE_BASE=/u01/app/oracle" >> /u01/oracle/.bash_profile
RUN echo "export ORACLE_HOME=$ORACLE_BASE/product/wls122100" >> /u01/oracle/.bash_profile
RUN echo "export MW_HOME=$ORACLE_HOME" >> /u01/oracle/.bash_profile
RUN echo "export WLS_HOME=$MW_HOME/wlserver" >> /u01/oracle/.bash_profile
RUN echo "export WL_HOME=$WLS_HOME" >> /u01/oracle/.bash_profile
RUN echo "export DOMAIN_BASE=$ORACLE_BASE/config/domains" >> /u01/oracle/.bash_profile
RUN echo "export DOMAIN_HOME=$DOMAIN_BASE/mydomain" >> /u01/oracle/.bash_profile
RUN echo "PATH=$PATH:$WL_HOME/server/bin" >> /u01/oracle/.bash_profile
RUN echo "export CLASSPATH=${CLASSPATH}:${WLS_HOME}/server/lib/weblogic.jar:." >> /u01/oracle/.bash_profile
RUN echo ". $WL_HOME/server/bin/setWLSEnv.sh" >> /u01/oracle/.bash_profile

RUN unzip $WLS_PKG 
RUN $JAVA_HOME/bin/java -Xmx1024m -jar /u01/app/oracle/$WLS_JAR -silent -responseFile /u01/app/oracle/wls.rsp -invPtrLoc /u01/app/oracle/oraInst.loc > install.log
RUN rm -f $WLS_PKG

RUN . $WLS_HOME/server/bin/setWLSEnv.sh && java weblogic.version
RUN java weblogic.WLST -skipWLSModuleScanning create_basedomain.py

#end of file

创建了如下图

docker build -f Dockerfile-weblogic12c.2 --tag="weblogic12c:v2" /var/docker-projects

像下面这样启动容器

docker run -d -p 0.0.0.0:7001:7001 -it weblogic12c:v2 bash

像下面这样启动Weblogic

docker exec -it <container id> bash

手动登录容器执行./startWeblogic.sh

root@osboxes:/var/docker-projects# docker ps -a
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS                  PORTS                    NAMES
20f249affaa9        weblogic12c:v2   "/bin/bash"              4 hours ago         Up 14 minutes           0.0.0.0:7001->7001/tcp   infallible_poincare

测试了如下 URL。

root@osboxes:/var/docker-projects# curl -Is http://172.17.0.2:7001/
root@osboxes:/var/docker-projects# echo $?
7

Weblogic 已启动并 运行 在容器内。

<Apr 1, 2019 6:15:59 PM UTC> <Notice> <Security> <BEA-090947> <Security post-initializing using security realm: myrealm>  <Apr 1, 2019 6:16:07 PM UTC> <Notice> <Security> <BEA-090082> <Security initialized using administrative security realm: myrealm>  <Apr 1, 2019 6:16:22 PM UTC> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STANDBY.>  <Apr 1, 2019 6:16:22 PM UTC> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING.>  <Apr 1, 2019 6:16:23 PM UTC> <Notice> <Log Management> <BEA-170036> <The Logging monitoring service timer has started to check for logged message counts every 30 seconds.>  <Apr 1, 2019 6:16:26 PM UTC> <Notice> <Log Management> <BEA-170027> <The server has successfully established a connection with the Domain level Diagnostic Service.>  <Apr 1, 2019 6:16:27 PM UTC> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to ADMIN.>  <Apr 1, 2019 6:16:27 PM UTC> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RESUMING.>  <Apr 1, 2019 6:16:28 PM UTC> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 127.0.0.1:7001 for protocols iiop, t3, ldap, snmp, http.>  <Apr 1, 2019 6:16:28 PM UTC> <Notice> <WebLogicServer> <BEA-000331> <Started the WebLogic Server Administration Server "adminserver" for domain "verdomain" running in development mode.>  <Apr 1, 2019 6:16:28 PM UTC> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 127.0.0.1:7001 for protocols iiop, t3, ldap, snmp, http.>  <Apr 1, 2019 6:16:28 PM UTC> <Notice> <WebLogicServer> <BEA-000360> <The server started in RUNNING mode.>  <Apr 1, 2019 6:16:28 PM UTC> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING.>

容器的 IP 地址和接口详细信息。

[oracle@20f249affaa9 oracle]$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
4: eth0@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever

return状态,主机不可访问。 IP 是容器 IP,并试图从 docker 主机访问 URL。我使用桥接网络连接。

URL 可以在容器内访问,但不能在 docker 主机中访问。

[oracle@20f249affaa9 oracle]$ curl -Is http://localhost:7001/console
HTTP/1.1 200 OK
Connection: close
Date: Mon, 01 Apr 2019 18:49:19 GMT
Content-Length: 416

root@osboxes:/var/docker-projects# curl -Is http://localhost:7001/console
root@osboxes:/var/docker-projects# echo $?
52

请帮助我如何调试 docker 网络,这是此问题的根本原因。我做了 google,它说我必须使用 -p 0.0.0.0:7001:7001 或只使用 -p 7001:7001 来公开端口。

Weblogic 配置为仅在 localhost 上侦听,这意味着它只能在容器内访问:

<Apr 1, 2019 6:16:28 PM UTC> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 127.0.0.1:7001 for protocols iiop, t3, ldap, snmp, http.>

您需要更改 Weblogic 的配置以绑定到 0.0.0.0。之后您的解决方案应该可以正常工作。