简体   繁体   English

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

[英]Application running in docker container not reachable in docker host

I have Ubuntu 18.04 virtual machine in the Windows Operating system. 我在Windows操作系统中具有Ubuntu 18.04虚拟机。 In the virtual machine, docker is installed and it is the docker host. 在虚拟机中,安装了docker,它是docker主机。 Created an image using Oracle Linux7 to install Weblogic 12 and started the application manually logging to the container. 使用Oracle Linux7创建映像以安装Weblogic 12,并手动将应用程序登录到容器中。 The ports are mapped successfully and Weblogic is running inside the container but it is not accessible in the docker host and outside the docker host. 端口已成功映射,并且Weblogic在容器内部运行,但是在Docker主机和Docker主机外部无法访问。 I would like to know if I am missing any configuration and would like to know how to troubleshoot the docker networking to fix this issue. 我想知道我是否缺少任何配置,并且想知道如何对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

Created the image like below 创建如下图像

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

Started the container like below 如下启动容器

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

Started the Weblogic like below 如下所示启动Weblogic

docker exec -it <container id> bash

Manually logged in to the container and executed ./startWeblogic.sh 手动登录到容器并执行./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

Tested the URL like below. 如下测试URL。

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

Weblogic started and running inside the container. 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 address of the container and interface details. 容器的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

The return status, the host is not reachable. 返回状态,主机不可访问。 The IP is the container IP and trying to hit the URL from the docker host. IP是容器IP,并尝试从docker主机访问URL。 I am connected using a bridged network. 我使用桥接网络连接。

The URL is accessble inside the container but not in the docker host. 该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

Please help me how to debug the docker networking, root cause for this issue. 请帮助我如何调试Docker网络,这是导致此问题的根本原因。 I did google and it says that I have to use -p 0.0.0.0:7001:7001 or just -p 7001:7001 to expose the port. 我做了谷歌,它说我必须使用-p 0.0.0.0:7001:7001或只是-p 7001:7001来显示端口。

Weblogic is configured to listen only on localhost , which means that it is accessible only within a container: 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.>

You need to change Weblogic's configuration to be bound on 0.0.0.0 . 您需要更改Weblogic的配置以绑定到0.0.0.0 After that your solution should work properly. 之后,您的解决方案应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Docker容器中运行Rails应用程序 - Running Rails application in docker container 在Docker容器中作为主机用户运行 - Running as a host user within a Docker container "如何将主机目录挂载到正在运行的 docker 容器中" - How to mount a host directory into a running docker container 如何在运行 docker 多容器应用程序的主机上使用 kubeadm 安装 kubernetes - How to install kubernetes using kubeadm on a host walready running docker multi container application 将文件从主机复制到容器中正在运行的docker容器中? - Copy a file from host to a running docker container from within the container? 在 Ubuntu 上运行 docker:安装的主机卷不可从容器写入 - Running docker on Ubuntu: mounted host volume is not writable from container 在 Docker 容器内运行的进程的主机中的 PID 是什么? - What is the PID in the host, of a process running inside a Docker container? --add-host在播放应用程序泊坞窗容器中失败 - --add-host failed within play application docker container 无法从 docker 容器内部访问主机上的 quarkus 应用程序 - Cannot reach quarkus application on host from inside docker container 在Docker容器中运行审核 - running auditd in docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM