运行tomcat的Docker容器无法使用主机IP地址访问服务器 [英] Docker container running tomcat - could not access the server using the host IP address

查看:2195
本文介绍了运行tomcat的Docker容器无法使用主机IP地址访问服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从docker文件中构建一个运行tomcat的docker容器。请在下面找到Dockerfile内容:

I am trying to build a docker container running tomcat from a docker file. Please find below the Dockerfile content:

FROM ubuntu:trusty
MAINTAINER karthik.jayaraman
VOLUME ["/tomcat/files"]
ADD /files/tar/apache-tomcat-7.0.47.tar.gz /usr/local/tomcat
ADD /files/scripts/. /tmp/tomcat_temp
RUN ls /tmp/tomcat_temp
RUN cp  -a /tmp/tomcat_temp/. /etc/init.d
RUN chmod 755 /etc/init.d/tomcat
RUN chkconfig --add tomcat && chkconfig --level 234 tomcat on
ADD /files/config   /usr/local/tomcat/apache-tomcat-7.0.47/conf/
ADD /files/lib  /usr/local/tomcat/apache-tomcat-7.0.47/lib/
ENV CATALINA_HOME /usr/local/tomcat/apache-tomcat-7.0.47
ENV PATH $PATH:$CATALINA_HOME/bin
EXPOSE 8080
CMD ["service","tomcat","start"]

当我创建图像并在容器中运行bash,使用命令Service tomcat start启动服务器。我检查了catalina.out文件并确保其运行。但是当我尝试安装Docker的主机IP并使用端口号8080访问端口时,我可以连接到tomcat页面。但是当我指定容器的内部IP地址 - 172.24.0.7:8080时,我可以查看tomcat页面。我猜端口转发不正确。有人可以告诉我我在这里做的错误。

When i create the image and run a bash in the container, with the command "Service tomcat start", the server is started. I checked the catalina.out file and ensured that its running. But when i try the host IP on which docker is installed and access the port using the port number 8080, i could connect to tomcat page. But when i specify the internal IP address of the container - 172.24.0.7:8080, i could view the tomcat page. I guess the port forwarding is not properly. Can someone tell me the error i am making here.

推荐答案

只要最后一个命令没有完成,您的docker容器就会运行。你正在启动你的tomcat作为守护进程。这使得docker一旦tomcat启动就停止运行容器。

Your docker container is running as long as last command is not done. You are booting up your tomcat as a daemon. This makes docker to stop running container as soon as tomcat is started.

您可以将最后一行更改为:

You can changed your last line to:

CMD service tomcat start && tail -f /var/lib/tomcat/logs/catalina.out

或者只是尝试使用其中一个Docker Hub预处理的tomcat容器: https://registry.hub.docker.com/search?q = tomcat& s = downloads

Or just try using one of precreated tomcat containers from Docker Hub: https://registry.hub.docker.com/search?q=tomcat&s=downloads

这篇关于运行tomcat的Docker容器无法使用主机IP地址访问服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆