- pull tomcat镜像
sixdog@192 Docker % docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
bb7d5a84853b: Pull complete
f02b617c6a8c: Pull complete
d32e17419b7e: Pull complete
c9d2d81226a4: Pull complete
fab4960f9cd2: Pull complete
da1c1e7baf6d: Pull complete
1d2ade66c57e: Pull complete
ea2ad3f7cb7c: Pull complete
d75cb8d0a5ae: Pull complete
76c37a4fffe6: Pull complete
Digest: sha256:509cf786b26a8bd43e58a90beba60bdfd6927d2ce9c7902cfa675d3ea9f4c631
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
- 下载的镜像确认
sixdog@192 Docker % docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest b0e0b0a92cf9 2 weeks ago 680MB
- 创建容器
3.1. 容器名字:tomcat1 3.2. 容器端口映射:8080 3.3. 容器配置文件挂载 3.4. 进入容器看一看
sixdog@192 Docker % docker run --name tomcat1 -p 8080:8080 -v $PWD/tomcat/webapps:/usr/local/tomcat/webapps/test -v $PWD/tomcat/conf:/usr/local/tomcat/conf -d tomcat
596aaed00804ba4792f5c621341c17fa847c9854be433ab897f19e9f517f2637
自动创建目录 进入容器,这时才发现因为挂载了PC上的目录,目录是空的,导致容器里tomcat的配置文件等被同步为空,所以tomcat已经启动不了了
sixdog@192 Docker % docker start tomcat1
tomcat1
sixdog@192 Docker % docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
596aaed00804 tomcat "catalina.sh run" 13 minutes ago Exited (1) 3 seconds ago tomcat1
所以删掉容器
sixdog@192 Docker % docker rm tomcat1
tomcat1
sixdog@192 Docker % docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
先创建一个临时容器,拷贝他的配置文件等到PC目录下,留作之后挂载用
sixdog@192 Docker % docker run --name tomcat -p 8080:8080 -d tomcat
35b040b9bf196e5b339d6c6481dd484f40fc8d576235e9ade3247982d7136ead
sixdog@192 Docker % docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
35b040b9bf19 tomcat "catalina.sh run" 6 seconds ago Up 6 seconds 0.0.0.0:8080->8080/tcp tomcat
进入容器,可以看到三个目标文件夹conf,logs,webapps
sixdog@192 Docker % docker exec -it 35b040b9bf19 bash
root@35b040b9bf19:/usr/local/tomcat
root@35b040b9bf19:/usr/local/tomcat
total 160
drwxrwxrwx 1 root root 4096 Nov 11 13:58 logs
drwxr-xr-x 1 root root 4096 Nov 11 13:58 conf
drwxr-xr-x 2 root root 4096 Oct 22 00:23 bin
drwxr-xr-x 2 root root 4096 Oct 22 00:23 native-jni-lib
drwxr-xr-x 2 root root 4096 Oct 22 00:22 lib
drwxrwxrwx 2 root root 4096 Oct 22 00:22 temp
drwxr-xr-x 2 root root 4096 Oct 22 00:22 webapps
-rw-r--r-- 1 root root 18994 Sep 28 13:34 BUILDING.txt
-rw-r--r-- 1 root root 6210 Sep 28 13:34 CONTRIBUTING.md
-rw-r--r-- 1 root root 60269 Sep 28 13:34 LICENSE
-rw-r--r-- 1 root root 2333 Sep 28 13:34 NOTICE
-rw-r--r-- 1 root root 3372 Sep 28 13:34 README.md
-rw-r--r-- 1 root root 6905 Sep 28 13:34 RELEASE-NOTES
-rw-r--r-- 1 root root 16517 Sep 28 13:34 RUNNING.txt
drwxr-xr-x 7 root root 4096 Sep 28 13:34 webapps.dist
drwxrwxrwx 2 root root 4096 Sep 28 13:34 work
root@35b040b9bf19:/usr/local/tomcat
拷贝容器内文件夹到PC上
sixdog@192 Docker % docker cp tomcat:/usr/local/tomcat/webapps $PWD/tomcat
sixdog@192 Docker % docker cp tomcat:/usr/local/tomcat/conf $PWD/tomcat
sixdog@192 Docker % docker cp tomcat:/usr/local/tomcat/logs $PWD/tomcat
sixdog@192 Docker %
目录确认 删除镜像
sixdog@192 Docker % docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
35b040b9bf19 tomcat "catalina.sh run" 17 minutes ago Exited (143) 15 seconds ago tomcat
sixdog@192 Docker % docker rm 35b040b9bf19
35b040b9bf19
sixdog@192 Docker % docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
sixdog@192 Docker %
再次创建镜像并挂载
sixdog@192 Docker %
sixdog@192 Docker % docker run --name tomcat1 -p 8080:8080 -v $PWD/tomcat/webapps:/usr/local/tomcat/webapps/sixdog -v $PWD/tomcat/conf:/usr/local/tomcat/conf -v $PWD/tomcat/logs:/usr/local/tomcat/logs/ -d tomcat
677f514040a97ff102eb361e7bc71c861a5cc31e4e0425a19caa95b8e043a890
sixdog@192 Docker % docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
677f514040a9 tomcat "catalina.sh run" 7 seconds ago Up 7 seconds 0.0.0.0:8080->8080/tcp tomcat1
sixdog@192 Docker %
进入镜像
sixdog@192 Docker % docker exec -it 677 bash
root@677f514040a9:/usr/local/tomcat
total 152
drwxrwxrwx 1 root root 4096 Nov 11 14:19 work
drwxr-xr-x 1 root root 4096 Nov 11 14:19 webapps
drwxr-xr-x 13 root root 416 Nov 11 13:58 conf
drwxrwxrwx 4 root root 128 Nov 11 13:58 logs
drwxr-xr-x 2 root root 4096 Oct 22 00:23 bin
drwxr-xr-x 2 root root 4096 Oct 22 00:23 native-jni-lib
drwxr-xr-x 2 root root 4096 Oct 22 00:22 lib
drwxrwxrwx 2 root root 4096 Oct 22 00:22 temp
-rw-r--r-- 1 root root 18994 Sep 28 13:34 BUILDING.txt
-rw-r--r-- 1 root root 6210 Sep 28 13:34 CONTRIBUTING.md
-rw-r--r-- 1 root root 60269 Sep 28 13:34 LICENSE
-rw-r--r-- 1 root root 2333 Sep 28 13:34 NOTICE
-rw-r--r-- 1 root root 3372 Sep 28 13:34 README.md
-rw-r--r-- 1 root root 6905 Sep 28 13:34 RELEASE-NOTES
-rw-r--r-- 1 root root 16517 Sep 28 13:34 RUNNING.txt
drwxr-xr-x 7 root root 4096 Sep 28 13:34 webapps.dist
root@677f514040a9:/usr/local/tomcat
修改PC上文件,容器内确认是否同步更改 创建文件index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
hello world!!!
</body>
</html>
将index.html放入webapps目录下
sixdog@192 tomcat % ls
conf index.html logs webapps
sixdog@192 tomcat % mv index.html ./webapps/index.html
sixdog@192 tomcat % ls
conf logs webapps
sixdog@192 tomcat % ls webapps
index.html
sixdog@192 tomcat %
容器内确认
sixdog@192 tomcat % docker exec -it 677 bash
root@677f514040a9:/usr/local/tomcat
total 152
drwxrwxrwx 1 root root 4096 Nov 11 14:19 work
drwxr-xr-x 1 root root 4096 Nov 11 14:19 webapps
drwxr-xr-x 13 root root 416 Nov 11 13:58 conf
drwxrwxrwx 4 root root 128 Nov 11 13:58 logs
drwxr-xr-x 2 root root 4096 Oct 22 00:23 bin
drwxr-xr-x 2 root root 4096 Oct 22 00:23 native-jni-lib
drwxr-xr-x 2 root root 4096 Oct 22 00:22 lib
drwxrwxrwx 2 root root 4096 Oct 22 00:22 temp
-rw-r--r-- 1 root root 18994 Sep 28 13:34 BUILDING.txt
-rw-r--r-- 1 root root 6210 Sep 28 13:34 CONTRIBUTING.md
-rw-r--r-- 1 root root 60269 Sep 28 13:34 LICENSE
-rw-r--r-- 1 root root 2333 Sep 28 13:34 NOTICE
-rw-r--r-- 1 root root 3372 Sep 28 13:34 README.md
-rw-r--r-- 1 root root 6905 Sep 28 13:34 RELEASE-NOTES
-rw-r--r-- 1 root root 16517 Sep 28 13:34 RUNNING.txt
drwxr-xr-x 7 root root 4096 Sep 28 13:34 webapps.dist
root@677f514040a9:/usr/local/tomcat
index.html
root@677f514040a9:/usr/local/tomcat
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
hello world!!!
</body>
</html>
- 浏览器输入http://192.168.0.102:8080/确认结果
原因是容器里webapps目录里没有相关文件,发现在webapps.dist文件夹里有相关文件,拷贝过来
root@677f514040a9:/usr/local/tomcat
root@677f514040a9:/usr/local/tomcat
ROOT docs examples host-manager manager sixdog
再次访问http://192.168.0.102:8080/ 已经可以访问 http://192.168.0.102:8080/sixdog/index.html
5.修改配置文件,新建文件夹,文件等 修改web.xml
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>executable</param-name>
<param-value>perl</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<init-param>
<param-name>passShellEnvironment</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>*.cgi</url-pattern>
</servlet-mapping>
context.xml加privileged=“true”
<Context privileged="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
</Context>
目录结构 访问cgi http://192.168.0.102:8080/sixdog/test.cgi
访问index.html http://192.168.0.102:8080/sixdog/html/index.html
|