{"id":210545,"date":"2021-02-09T10:29:04","date_gmt":"2021-02-09T02:29:04","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=210545"},"modified":"2021-01-27T09:30:07","modified_gmt":"2021-01-27T01:30:07","slug":"docker-tomca-web","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/docker-tomca-web.html","title":{"rendered":"Docker\u5b89\u88c5Tomcat\u955c\u50cf\u5e76\u90e8\u7f72web\u9879\u76ee"},"content":{"rendered":"

\"\"<\/p>\n

\u4e00\u3001\u5b89\u88c5Tomcat<\/strong><\/div>\n
1\u3001\u67e5\u627eDocker Hub\u4e0a\u7684tomcat\u955c\u50cf<\/strong><\/span><\/div>\n
docker search tomcat<\/pre>\n

\"\"<\/p>\n

2\u3001\u62c9\u53d6\u5b98\u65b9\u7684\u955c\u50cf<\/strong><\/span><\/div>\n
docker pull tomcat<\/pre>\n

\"\"
\n\u7b49\u5f85\u4e0b\u8f7d\u5b8c\u6bd5\uff0c\u9700\u8981\u4e00\u4e9b\u65f6\u95f4\u3002<\/p>\n

3\u3001\u67e5\u770bdocker\u6240\u6709\u7684\u955c\u50cf<\/strong><\/span><\/div>\n
docker images<\/pre>\n

\"\"<\/p>\n

4\u3001\u542f\u52a8tomcat\u955c\u50cf<\/strong><\/span><\/div>\n

\u6ce8\uff1a\u524d\u8005\u662f\u5916\u56f4\u8bbf\u95ee\u7aef\u53e3\uff1a\u540e\u8005\u662f\u5bb9\u5668\u5185\u90e8\u7aef\u53e3<\/p>\n

docker run -d -p 8080:8080 tomcat<\/pre>\n

\"\"
\n\u6ce8\uff1a\u524d\u8005\u662f\u5916\u56f4\u8bbf\u95ee\u7aef\u53e3\uff1a\u540e\u8005\u662f\u5bb9\u5668\u5185\u90e8\u7aef\u53e3
\n\u5982\u4e0b\u547d\u4ee4\u53ef\u540e\u53f0\u542f\u52a8tomcat
\n-d: \u540e\u53f0\u8fd0\u884c\u5bb9\u5668\uff0c\u5e76\u8fd4\u56de\u5bb9\u5668ID\uff1b
\n-i: \u4ee5\u4ea4\u4e92\u6a21\u5f0f\u8fd0\u884c\u5bb9\u5668\uff0c\u901a\u5e38\u4e0e -t \u540c\u65f6\u4f7f\u7528\uff1b
\n-t: \u4e3a\u5bb9\u5668\u91cd\u65b0\u5206\u914d\u4e00\u4e2a\u4f2a\u8f93\u5165\u7ec8\u7aef\uff0c\u901a\u5e38\u4e0e -i \u540c\u65f6\u4f7f\u7528\uff1b<\/p>\n

docker run \u2013d -p 8080:8080 tomcat<\/pre>\n

\"\"
\n\u5982\u4e0b\u5219\u542f\u52a8\u6210\u529f\uff1a
\n\"\"<\/p>\n

5\u3001\u67e5\u770b\u6b63\u5728\u8fd0\u884c\u7684\u5bb9\u5668<\/strong><\/span><\/div>\n
docker ps<\/pre>\n

\"\"
\n\"\"<\/p>\n

\u4e8c\u3001\u5411Tomcat\u90e8\u7f72\u81ea\u5df1\u7684web\u9879\u76ee<\/strong><\/div>\n
1\u3001\u4e0a\u4f20war\u5305<\/strong><\/span><\/div>\n

\"\"<\/p>\n

2\u3001\u521b\u5efa\u5e76\u7f16\u8f91\u201dDockerfile\u201d\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/strong><\/span><\/div>\n
from tomcat #\u4f60\u7684 tomcat\u7684\u955c\u50cf\r\nMAINTAINER *********@163.com #\u4f5c\u8005\r\nRUN rm -rf \/usr\/local\/tomcat\/webapps\/*\r\nCOPY button.war \/usr\/local\/tomcat\/webapps #\u653e\u7f6e\u5230tomcat\u7684webapps\u76ee\u5f55\u4e0b\r\nENV TZ=Asia\/Shanghai\r\nRUN ln -snf \/usr\/share\/zoneinfo\/$TZ \/etc\/localtime && echo $TZ > \/etc\/timezone\r\n<\/pre>\n
3\u3001\u751f\u6210\u65b0\u7684\u955c\u50cf<\/strong><\/span><\/div>\n
docker build -t button:v1 .<\/pre>\n

\"\"<\/p>\n

4\u3001\u542f\u52a8\u65b0\u7684\u955c\u50cf<\/strong><\/span><\/div>\n
docker run -d -p 8080:8080 button:v1<\/pre>\n

\"\"<\/p>\n

5\u3001\u67e5\u770b\u5df2\u542f\u52a8\u955c\u50cf<\/strong><\/span><\/div>\n

\u53ef\u4ee5\u52a0\u4e0a\u53c2\u6570-itd\u540e\u53f0\u542f\u52a8tomcat\uff0c\u7528\u4ee5\u4e0b\u65b9\u5f0f\u67e5\u770b\u5df2\u542f\u52a8\u7684\u955c\u50cf<\/p>\n

docker ps<\/pre>\n

\"\"<\/p>\n

6\u3001\u67e5\u770btomcat\u4e2d\u7684\u9879\u76ee<\/strong><\/span><\/div>\n

\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u8fdb\u5165tomcat\u955c\u50cf\uff1a<\/p>\n

docker exec -it ******* \/bin\/bash #******\u662f\u5bb9\u5668id\uff08CONTAINER_ID\uff09<\/pre>\n

\"\"
\n\u5f53\u6211\u4eec\u8fdb\u5165\u955c\u50cf\u540e\uff0c\u60f3\u5bf9\u67d0\u4e9b\u53c2\u6570\u8fdb\u884c\u4fee\u6539\u65f6\uff0c\u4e00\u822c\u9700\u8981\u5b89\u88c5\u6587\u672c\u7f16\u8f91\u5668\uff0c\u4ee5vim\u4e3a\u4f8b\uff1a
\n\u7531\u4e8e\u4e0b\u8f7d\u5730\u5740\u662f\u6d77\u5916\u5730\u5740\uff0c\u4e0b\u8f7d\u901f\u5ea6\u975e\u5e38\u6162\u800c\u4e14\u53ef\u80fd\u51fa\u73b0\u4e2d\u65ad\uff0c\u6240\u4ee5\u505a\u5982\u4e0b\u914d\u7f6e\uff1a<\/p>\n

mv \/etc\/apt\/sources.list \/etc\/apt\/sources.list.bak\r\necho \"deb http:\/\/mirrors.163.com\/debian\/ jessie main non-free contrib\" >\/etc\/apt\/sources.list\r\necho \"deb http:\/\/mirrors.163.com\/debian\/ jessie-proposed-updates main non-free contrib\" >>\/etc\/apt\/sources.list\r\necho \"deb-src http:\/\/mirrors.163.com\/debian\/ jessie main non-free contrib\" >>\/etc\/apt\/sources.list\r\necho \"deb-src http:\/\/mirrors.163.com\/debian\/ jessie-proposed-updates main non-free contrib\" >>\/etc\/apt\/sources.list\r\n<\/pre>\n

\u7136\u540e\u66f4\u65b0<\/p>\n

apt update<\/pre>\n

\u73b0\u5728\u5c31\u53ef\u4ee5\u5b89\u88c5\u6211\u4eec\u9700\u8981\u7684\u8f6f\u4ef6\u4e86\uff0c\u4f8b\u5982vim<\/p>\n

apt install vim<\/pre>\n
7\u3001\u8f93\u5165ip\u548c\u7aef\u53e3\u8fdb\u884c\u67e5\u770b<\/strong><\/span><\/div>\n

\"\"<\/p>\n

8\u3001\u53ef\u4ee5\u67e5\u770b\u6307\u5b9a\u5bb9\u5668\u7684log<\/strong><\/span><\/div>\n
docker logs -f \u5bb9\u5668id<\/pre>\n

\"\"<\/p>\n

9\u3001\u90e8\u7f72web\u9879\u76ee\u540e\u4e5f\u8bb8\u4f1a\u51fa\u73b0docker\u5bb9\u5668\u4e0e\u5bbf\u4e3b\u3001docker \u5bb9\u5668\u4e0etomcat \u5e94\u7528\u6253\u5370\u65e5\u5fd7\u65f6\u95f4\u548c\u6211\u4eec\u5f53\u524d\u65f6\u95f4\u76f8\u5dee8\u4e2a\u5c0f\u65f6\uff0c\u53ef\u4ee5\u6dfb\u52a0\u5982\u4e0b\u914d\u7f6e\uff1a<\/strong><\/span><\/div>\n

\u2460\u542f\u52a8\u5bb9\u5668\u65f6\uff0c\u5c06\u7cfb\u7edf\u65f6\u95f4\u6302\u8f7d\u5230\u5bb9\u5668\u5185\uff0c\u53ef\u4ee5\u89e3\u51b3docker\u5bb9\u5668\u4e0e\u5bbf\u4e3b\u65f6\u95f4\u4e0d\u4e00\u81f4\u95ee\u9898\uff0c\u5982\u4e0b\u6240\u793a\uff1a
\n\u6dfb\u52a0\u53c2\u6570<\/p>\n

-v \/etc\/localtime:\/etc\/localtime:ro<\/pre>\n

\u5b8c\u6574\u547d\u4ee4\u5982\u4e0b\u793a\u4f8b\uff1a<\/p>\n

sudo docker run -d --name button-api -p 8080:8080 -v \/etc\/localtime:\/etc\/localtime:ro button-api:v1<\/pre>\n

\u2461docker \u5bb9\u5668\u4e0etomcat \u5e94\u7528\u6253\u5370\u65e5\u5fd7\u65f6\u95f4\u4e0d\u4e00\u81f4
\n\u542f\u52a8tomcat\u5bb9\u5668\u540e\u8fdb\u5165tomcat\u7684\u201dbin\u201d\u76ee\u5f55\uff0c\u4fee\u6539catalina.sh\u6587\u4ef6
\n\u5728\u6ce8\u91ca\u7ed3\u675f\u7684\u7b2c\u4e00\u884c\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n

JAVA_OPTS=\"$JAVA_OPTS -Dfile.encoding=UTF8 -Duser.timezone=GMT+08\"<\/pre>\n

\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n

\"\"
\n\u4fee\u6539\u4fdd\u5b58\u540e\u91cd\u542fdocker\u5bb9\u5668\u5c31\u53ef\u4ee5\u4e86\u3002
\n\u91cd\u542f\u65b9\u6cd5\uff1a
\n\u201cdocker ps\u201d\u67e5\u8be2\u5bb9\u5668id\uff0c\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u91cd\u542f\uff1a<\/p>\n

docker restart \u5bb9\u5668id<\/pre>\n

\u5230\u6b64\u5373\u53ef\u89e3\u51b3\u8be5\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

docker search tomcat docker pull tomcat \u7b49\u5f85\u4e0b\u8f7d\u5b8c\u6bd5\uff0c\u9700\u8981\u4e00\u4e9b\u65f6\u95f4\u3002 […]<\/p>\n","protected":false},"author":1469,"featured_media":210566,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-210545","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/210545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1469"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=210545"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/210545\/revisions"}],"predecessor-version":[{"id":210567,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/210545\/revisions\/210567"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/210566"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=210545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=210545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=210545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}