嗯那 發表於 2020-2-29 11:47:00

Docker入门 安装Tomcat以及报404解决方案

<h1 class="ssy-detail-title">记录简单的在Docker 上安装Tomcat</h1>
<div id="article_content" class="article_content clearfix">
<div id="content_views" class="htmledit_views">
<p>首先我是在云服务器上(Centos系统)安装的Docker,我们需要在https://hub.docker.com/&nbsp;上查找Tomcat镜像</p>
<pre class="has"><code class="language-bash"># docker pull tomcat</code></pre>
<p><br>
拉取完官方的Tomcat的镜像后,我们可以在本地镜像列表里查到 REPOSITORY 为 tomcat 的镜像,</p>
<pre class="has"><code># docker images|grep tomcat
tomcat            latest            ed94f55483b8      2 weeks ago         507MB
</code></pre>
<p>&nbsp;</p>
<p>接下来,运行容器</p>
<pre class="has"><code class="language-bash"># docker run -d --name tomcat -p 8080:8080 tomcat:latest
0be1774e1e5e1388663e65b4a5e59d58597072a960684fff3eca009c3e89d054
</code></pre>
<p>说明一下:<strong>-p 8080:8080:</strong>将容器的 8080 端口映射到主机的 8080 端口。</p>
<p>这时候查看docker 正在运行的容器:</p>
<pre class="has"><code class="language-bash"># docker ps
CONTAINER ID      IMAGE               COMMAND             CREATED            STATUS            PORTS                  NAMES
0be1774e1e5e      tomcat:latest       "catalina.sh run"   About a minute ago   Up About a minute   0.0.0.0:8080-&gt;8080/tcp   tomcat
</code></pre>
<p>&nbsp;</p>
<p>这时候已经在运行了,接下来,我们用浏览器访问,</p>
<p><img src="https://img-blog.csdnimg.cn/20200118170445437.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L040c3RhcnQ=,size_16,color_FFFFFF,t_70" alt="" width="1200" height="690" class="has"></p>
<p>&nbsp;这时候,很奇怪哦,404错误?我这里检查完服务器端口8080已经开放了,接下来,我们进入tomcat的目录:</p>
<pre class="has"><code class="language-bash"># docker ps
CONTAINER ID      IMAGE               COMMAND             CREATED             STATUS            PORTS                  NAMES
0be1774e1e5e      tomcat:latest       "catalina.sh run"   7 minutes ago       Up 7 minutes      0.0.0.0:8080-&gt;8080/tcp   tomcat
# docker exec -it 0be1774e1e5e /bin/bash
root@0be1774e1e5e:/usr/local/tomcat# ^C
root@0be1774e1e5e:/usr/local/tomcat# ls -l
total 156
-rw-r--r-- 1 root root19318 Dec7 19:23 BUILDING.txt
-rw-r--r-- 1 root root   5408 Dec7 19:23 CONTRIBUTING.md
-rw-r--r-- 1 root root57011 Dec7 19:23 LICENSE
-rw-r--r-- 1 root root   1726 Dec7 19:23 NOTICE
-rw-r--r-- 1 root root   3255 Dec7 19:23 README.md
-rw-r--r-- 1 root root   7136 Dec7 19:23 RELEASE-NOTES
-rw-r--r-- 1 root root16262 Dec7 19:23 RUNNING.txt
drwxr-xr-x 2 root root   4096 Jan4 05:07 bin
drwxr-sr-x 1 root root   4096 Jan 18 08:59 conf
drwxr-sr-x 2 root staff4096 Jan4 05:07 include
drwxr-xr-x 2 root root   4096 Jan4 05:06 lib
drwxrwxrwx 1 root root   4096 Jan 18 08:59 logs
drwxr-sr-x 3 root staff4096 Jan4 05:07 native-jni-lib
drwxrwxrwx 2 root root   4096 Jan4 05:06 temp
drwxr-sr-x 2 root staff4096 Jan4 05:06 webapps
drwxr-xr-x 7 root root   4096 Dec7 19:21 webapps.dist
drwxrwxrwx 2 root root   4096 Dec7 19:19 work
</code></pre>
<p>然后查看到里面发现有webapps和webapps.dist两个文件,而wenapps里面没有东西,webapps.dist才是我们要的东西</p>
<pre class="has"><code class="language-bash">root@0be1774e1e5e:/usr/local/tomcat# cd ./webapps
root@0be1774e1e5e:/usr/local/tomcat/webapps# ls -l
total 0
</code></pre>
<p>所以这里把webapps删掉,把webapps.dist改名为webapps</p>
<pre class="has"><code class="language-bash">root@0be1774e1e5e:/usr/local/tomcat# rm -rf webapps
root@0be1774e1e5e:/usr/local/tomcat# mv webapps.dist webapps
</code></pre>
<p>改完之后,我们再重新访问:</p>
<p><img src="https://img-blog.csdnimg.cn/2020011817144366.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L040c3RhcnQ=,size_16,color_FFFFFF,t_70" alt="" width="1200" height="698" class="has"></p>
<p>&nbsp;这时候已经可以访问了。</p>
</div>
</div><br><br>
来源:https://www.cnblogs.com/xiaozhang666/p/12382114.html
頁: [1]
查看完整版本: Docker入门 安装Tomcat以及报404解决方案