
{"id":2927,"date":"2021-01-12T14:33:08","date_gmt":"2021-01-12T06:33:08","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2927"},"modified":"2021-02-24T09:38:05","modified_gmt":"2021-02-24T01:38:05","slug":"2020java%e5%be%ae%e6%9c%8d%e5%8a%a1%e6%9e%b6%e6%9e%84%e4%ba%8c%e4%b9%8bdocker%e5%ae%b9%e5%99%a8%e5%8c%96%e6%8a%80%e6%9c%af","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2927","title":{"rendered":"2020java\u5fae\u670d\u52a1\u67b6\u6784\u4e8c\u4e4bDocker\u5bb9\u5668\u5316\u6280\u672f"},"content":{"rendered":"<h2>2020java\u5fae\u670d\u52a1\u67b6\u6784\u4e8c\u4e4bDocker\u5bb9\u5668\u5316\u6280\u672f<\/h2>\n<h3>Docker\u7684\u601d\u60f3<\/h3>\n<p>1.\u96c6\u88c5\u7bb1\uff1a<br \/>\n\u4f1a\u5c06\u6240\u6709\u9700\u8981\u7684\u5185\u5bb9\u653e\u5230\u4e0d\u540c\u7684\u96c6\u88c5\u7bb1\u4e2d\uff0c\u8c01\u9700\u8981\u8fd9\u4e9b\u73af\u5883\u5c31\u76f4\u63a5\u62ff\u5230\u8fd9\u4e2a\u96c6\u88c5\u7bb1\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>2.\u6807\u51c6\u5316\uff1a<br \/>\na.\u8fd0\u8f93\u7684\u6807\u51c6\u5316\uff1adocker\u6709\u4e00\u4e2a\u7801\u5934\uff0c\u6240\u6709\u4e0a\u4f20\u7684\u96c6\u88c5\u7bb1\u90fd\u653e\u5728\u4e86\u8fd9\u4e2a\u7801\u5934\u4e0a\uff0c\u5f53\u8c01\u9700\u8981\u67d0\u4e00\u4e2a\u73af\u5883\uff0c\u5c31\u76f4\u63a5\u6d3e\u5927\u6d77\u8c5a\u53bb\u642c\u8fd0\u8fd9\u4e2a\u96c6\u88c5\u7bb1\u5c31\u53ef\u4ee5\u4e86\u3002<br \/>\nb.\u547d\u4ee4\u7684\u6807\u51c6\u5316\uff1adocker\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5217\u7684\u547d\u4ee4\uff0c\u5e2e\u52a9\u6211\u4eec\u53bb\u83b7\u53d6\u96c6\u88c5\u7bb1\u7b49\u64cd\u4f5c\u3002<br \/>\nc.\u63d0\u4f9bREST\u7684API\uff1a\u884d\u751f\u51fa\u4e86\u5f88\u591a\u7684\u56fe\u5f62\u5316\u754c\u9762\uff0cRancher<!--more--><\/p>\n<p>3.\u9694\u79bb\u6027\uff1a<br \/>\ndocker\u5728\u8fd0\u884c\u96c6\u88c5\u7bb1\u5185\u7684\u5185\u5bb9\u65f6\uff0c\u4f1a\u5728Linux\u5185\u6838\u4e2d\uff0c\u5355\u72ec\u7684\u5f00\u8f9f\u4e00\u7247\u7a7a\u95f4\uff0c\u8fd9\u7247\u7a7a\u95f4\u4e0d\u4f1a\u5f71\u54cd\u5230\u5176\u4ed6\u7a0b\u5e8f\u3002<\/p>\n<p>\u6ce8\u518c\u4e2d\u5fc3\uff1a\u8d85\u7ea7\u7801\u5934\uff0c\u4e0a\u9762\u653e\u7684\u5c31\u662f\u96c6\u88c5\u7bb1<br \/>\n\u955c\u50cf\uff1a\u96c6\u88c5\u7bb1<br \/>\n\u5bb9\u5668\uff1a\u8fd0\u884c\u8d77\u6765\u7684\u955c\u50cf<\/p>\n<hr \/>\n<h3>Docker\u7684\u57fa\u672c\u64cd\u4f5c<\/h3>\n<p><strong>A.\u5b89\u88c5Docker<\/strong><\/p>\n<p>1.\u4e0b\u8f7d\u5173\u4e8eDcoker\u7684\u4f9d\u8d56\u73af\u5883<br \/>\nyum -y install yum-utils device-mapper-persistent-data lvm2<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/08\/12.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>2.\u8bbe\u7f6e\u4e0b\u8f7ddocker\u955c\u50cf\u6e90<br \/>\nyum-config-manager &#8211;add-repo http:\/\/mirrors.aliyun.com\/docker-ce\/linux\/centos\/docker-ce.repo<\/p>\n<p>3.\u5b89\u88c5Docker<br \/>\nyum makacache fast<br \/>\nyum -y install docker-ce<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/08\/13.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>4.\u542f\u52a8Docker\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\u52a8<br \/>\nsystemctl start docker<br \/>\nsystemctl enable docker<\/p>\n<p>\u6d4b\u8bd5\uff1adocker run hello-world<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/08\/14.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>B.Docker\u7684\u4e2d\u592e\u4ed3\u5e93<\/strong><\/p>\n<p>1.<a href=\"http:\/\/hub.docker.com\" target=\"_blank\" rel=\"noopener noreferrer\">Docker\u5b98\u65b9\u7684\u4e2d\u592e\u4ed3\u5e93<\/a>\uff1a\u955c\u50cf\u6700\u5168\u4f46\u901f\u5ea6\u8f83\u6162<br \/>\n2.\u56fd\u5185\u955c\u50cf\u7f51\u7ad9\uff1a<a href=\"http:\/\/c.163yun.com\/hub\" target=\"_blank\" rel=\"noopener noreferrer\">\u7f51\u6613\u8702\u5de2<\/a>\u3001<a href=\"http:\/\/hub.daoCloud.io\" target=\"_blank\" rel=\"noopener noreferrer\">daoCloud<\/a><br \/>\n3.\u5728\u516c\u53f8\u5185\u90e8\u4f1a\u91c7\u7528\u79c1\u670d\u7684\u65b9\u5f0f\u62c9\u53d6\u955c\u50cf(\u6dfb\u52a0\u914d\u7f6e)<\/p>\n<p>\u521b\u5efa\u6216\u4fee\u6539 \/etc\/docker\/daemon.json \u6587\u4ef6<\/p>\n<pre># vi \/etc\/docker\/daemon.json\r\n{\r\n    \"registry-mirrors\": [\"https:\/\/registry.docker-cn.com\"],\r\n    \"insecure-registries\":[\"ip:port\"]\r\n}<\/pre>\n<p>\u91cd\u542f\u4e24\u4e2a\u670d\u52a1\uff1a<br \/>\nsystemctl daemon-reload<br \/>\nsystemctl restart docker<\/p>\n<p><strong>C.\u955c\u50cf\u7684\u64cd\u4f5c<\/strong><\/p>\n<p>\u62c9\u53d6\u955c\u50cf\u5230\u672c\u5730<br \/>\ndocker pull \u955c\u50cf\u540d\u79f0<br \/>\ndocker pull daocloud.io\/library\/tomcat:8.5.15-jre8-alpine<\/p>\n<p>\u67e5\u770b\u5168\u90e8\u672c\u5730\u955c\u50cf<br \/>\ndocker images<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/1.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u5220\u9664\u672c\u5730\u955c\u50cf<br \/>\ndocker rmi \u955c\u50cf\u7684\u6807\u8bc6<\/p>\n<p>\u955c\u50cf\u5bfc\u5165\u5bfc\u51fa<br \/>\n\u955c\u50cf\u5bfc\u51fa\uff1adocker save -o \u5bfc\u51fa\u7684\u8def\u5f84\u548c\u6587\u4ef6\u540d \u955c\u50cfid<br \/>\ndocker save -o .\/tomcat.image ff<br \/>\n\u52a0\u8f7d\u672c\u5730\u955c\u50cf\uff1adocker load -i \u955c\u50cf\u6587\u4ef6<br \/>\n\u4fee\u6539\u955c\u50cf\u540d\u79f0\uff1adocker tag \u955c\u50cfid \u65b0\u955c\u50cf\u540d\u79f0:\u7248\u672c<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/2.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>D.\u5bb9\u5668\u7684\u64cd\u4f5c<\/strong><\/p>\n<p>1.\u8fd0\u884c\u5bb9\u5668<br \/>\n\u7b80\u5355\u64cd\u4f5c\uff1a<br \/>\ndocker run \u955c\u50cf\u7684\u6807\u8bc6|\u955c\u50cf\u7684\u540d\u79f0[:tag]<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/3.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u5e38\u7528\u7684\u53c2\u6570\uff1a<br \/>\ndocker run -d -p \u5bbf\u4e3b\u673a\u7aef\u53e3:\u5bb9\u5668\u7aef\u53e3<span style=\"color: #ff0000;\"> &#8211;name<\/span> \u5bb9\u5668\u540d\u79f0 \u955c\u50cf\u7684\u6807\u8bc6|\u955c\u50cf\u7684\u540d\u79f0[:tag]<br \/>\n-d\uff1a\u4ee3\u8868\u540e\u53f0\u8fd0\u884c\u5bb9\u5668<br \/>\n-p\uff1a\u5bbf\u4e3b\u673a\u7aef\u53e3:\u5bb9\u5668\u7aef\u53e3\uff1a\u4e3a\u4e86\u6620\u5c04\u5f53\u524dLinux\u7684\u7aef\u53e3\u548c\u5bb9\u5668\u7684\u7aef\u53e3<br \/>\n&#8211;name\uff1a\u5bb9\u5668\u540d\u79f0\uff1a\u6307\u5b9a\u5bb9\u5668\u7684\u540d\u79f0<br \/>\ndocker run -d -p 8081:8080 &#8211;name tomcat b8<\/p>\n<p>2.\u67e5\u770b\u6b63\u5728\u8fd0\u884c\u7684\u5bb9\u5668<br \/>\ndocker ps [-qa]<br \/>\n-q\uff1a\u53ea\u67e5\u770b\u5bb9\u5668\u7684\u6807\u8bc6<br \/>\n-a\uff1a\u67e5\u770b\u5168\u90e8\u7684\u5bb9\u5668\uff0c\u5305\u62ec\u6ca1\u6709\u8fd0\u884c<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/4.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>3.\u67e5\u770b\u5bb9\u5668\u7684\u65e5\u5fd7<br \/>\ndocker logs -f \u5bb9\u5668id<br \/>\n-f\uff1a\u53ef\u4ee5\u6eda\u52a8\u67e5\u770b\u65e5\u5fd7\u7684\u6700\u540e\u51e0\u884c<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/5.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>4.\u8fdb\u5165\u5230\u5bb9\u5668\u5185\u90e8<br \/>\n<span style=\"color: #ff0000;\"><strong>\u4e0d\u80fd\u5728\u5bb9\u5668\u5185\u90e8\u505c\u6b62\u670d\u52a1<\/strong><\/span><br \/>\ndocker exec -it \u5bb9\u5668id bash<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/6.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>5.\u5220\u9664\u5bb9\u5668<br \/>\n\u5220\u9664\u5bb9\u5668\u4e4b\u524d\uff0c\u9700\u8981\u505c\u6b62\u5bb9\u5668<br \/>\n\u505c\u6b62\u6307\u5b9a\u5bb9\u5668<br \/>\ndocker stop \u5bb9\u5668id<br \/>\n\u505c\u6b62\u5168\u90e8\u5bb9\u5668<br \/>\ndocker stop $(docker ps -qa)<br \/>\n\u5220\u9664\u6307\u5b9a\u5bb9\u5668id<br \/>\ndocker rm \u5bb9\u5668id<br \/>\n\u5220\u9664\u5168\u90e8\u5bb9\u5668<br \/>\ndocker rm $(docker ps -qa)<\/p>\n<p>6.\u542f\u52a8\u5bb9\u5668<br \/>\ndocker start \u5bb9\u5668id<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/7.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/8.png\" alt=\"\" width=\"680\" \/><\/p>\n<hr \/>\n<h3>Docker\u7684\u5e94\u7528<\/h3>\n<p><strong>1.\u51c6\u5907\u9879\u76ee\u5de5\u7a0b<\/strong><br \/>\n\u5c06idea\u9879\u76ee\u6253\u5305war<br \/>\nLinux:<br \/>\n\u505c\u6b62Tomcat\u4ee5\u53camysql<br \/>\n\u505c\u6b62Tomcat\uff1a<br \/>\ncd \/usr\/local\/apache-tomcat-8.5.53\/bin<br \/>\n.\/shutdown.sh<br \/>\n\u505c\u6b62mysql\uff1a<br \/>\nsystemctl stop mysqld<br \/>\nsystemctl disable mysqld<\/p>\n<p><strong>2.\u51c6\u5907mysql\u5bb9\u5668<\/strong><br \/>\n\u5982\u679c\u5bb9\u5668\u4e0d\u5b58\u5728\u5219\u81ea\u52a8\u62c9\u53d6\u955c\u50cf\uff0c\u7136\u540e\u8fd0\u884c<br \/>\ndocker run -d -p 3306:3306 &#8211;name mysql -e MYSQL_ROOT_PASSWORD=root daocloud.io\/library\/mysql:5.7.4<\/p>\n<p><strong>3.\u51c6\u5907Tomcat\u5bb9\u5668<\/strong><br \/>\n\u5c06\u9879\u76ee\u7684war\u5305\u90e8\u7f72\u5230Tomcat\u5bb9\u5668\u5185\u90e8\u5373\u53ef<br \/>\n\u53ef\u901a\u8fc7\u547d\u4ee4\u5c06\u5bbf\u4e3b\u4e3b\u673a\u7684\u5185\u5bb9\u670d\u52a1\u5230\u5bb9\u5668\u5185\u90e8<br \/>\ndocker cp \u6587\u4ef6\u540d\u79f0 \u5bb9\u5668id:\u5bb9\u5668\u5185\u90e8\u8def\u5f84<br \/>\ndocker cp ssm.war \u5bb9\u5668id:\/usr\/local\/tomcat\/webapps\/<br \/>\n\u67e5\u770b\u65e5\u5fd7\uff1adocker logs -f \u5bb9\u5668id<\/p>\n<p><strong>4.\u6570\u636e\u5377<\/strong><\/p>\n<p>\u4e3a\u4e86\u90e8\u7f72\u9879\u76ee\u7684\u5de5\u7a0b\uff0c\u9700\u8981\u4f7f\u7528\u5230cp\u7684\u547d\u4ee4\u5c06\u5bbf\u4e3b\u673a\u5185\u7684ssm.war\u6587\u4ef6\u590d\u5236\u5230\u5bb9\u5668\u5185\u90e8<br \/>\n\u6570\u636e\u5377\uff1a\u5c06\u5bbf\u4e3b\u673a\u7684\u4e00\u4e2a\u76ee\u5f55\u6620\u5c04\u5230\u5bb9\u5668 \u7684\u4e00\u4e2a\u76ee\u5f55\u4e2d<br \/>\n\u53ef\u4ee5\u5728\u5bbf\u4e3b\u673a\u4e2d\u64cd\u4f5c\u76ee\u5f55\u4e2d\u7684\u5185\u5bb9\uff0c\u90a3\u4e48\u5bb9\u5668\u5185\u90e8\u6620\u5c04\u7684\u6587\u4ef6\uff0c\u4e5f\u4f1a\u8ddf\u7740\u4e00\u8d77\u6539\u53d8\u3002<\/p>\n<p>a.\u521b\u5efa\u6570\u636e\u5377\uff1adocker volume create \u6570\u636e\u5377\u540d\u79f0<br \/>\n\u521b\u5efa\u6570\u636e\u5377\u4e4b\u540e\uff0c\u9ed8\u8ba4\u4f1a\u653e\u5728 \/var\/lib\/docker\/volumes\/\u6570\u636e\u5377\u540d\u79f0\/_data<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/9.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>b.\u67e5\u770b\u6570\u636e\u5377\u7684\u8be6\u7ec6\u4fe1\u606f<br \/>\ndocker volume inspect \u6570\u636e\u5377\u540d\u79f0<\/p>\n<p>c.\u67e5\u770b\u5168\u90e8\u6570\u636e\u5377\uff1adocker volume ls<\/p>\n<p>d.\u5220\u9664\u6570\u636e\u5377\uff1adocker volume rm \u6570\u636e\u5377\u540d\u79f0<\/p>\n<p>e.\u6570\u636e\u5377\u5e94\u7528<\/p>\n<p>\u5f53\u4f60\u6620\u5c04\u6570\u636e\u5377\u65f6\uff0c\u5982\u679c\u6570\u636e\u5377\u4e0d\u5b58\u5728\uff0cdocker\u4f1a\u5e2e\u4f60\u81ea\u52a8\u521b\u5efa\uff0c\u4f1a\u5c06\u5bb9\u5668\u5185\u90e8\u81ea\u5e26\u7684\u6587\u4ef6\uff0c\u5b58\u50a8\u5728\u9ed8\u8ba4\u7684\u5b58\u653e\u8def\u5f84\u4e2d\u3002<br \/>\ndocker run -v \u6570\u636e\u5377\u540d\u79f0:\u5bb9\u5668\u5185\u90e8\u7684\u8def\u5f84 \u955c\u50cfid<\/p>\n<p>\u76f4\u63a5\u6307\u5b9a\u4e00\u4e2a\u8def\u5f84\u4f5c\u4e3a\u6570\u636e\u5377\u7684\u5b58\u653e\u4f4d\u7f6e\uff0c\u8fd9\u4e2a\u8def\u5f84\u4e0b\u662f\u7a7a\u7684<br \/>\ndocker run -v \u8def\u5f84:\u5bb9\u5668\u5185\u90e8\u7684\u8def\u5f84 \u955c\u50cfid<\/p>\n<p><span style=\"color: #ff0000;\"><strong>docker volume create \u6570\u636e\u5377\u540d\u79f0<\/strong><\/span><br \/>\n<span style=\"color: #ff0000;\"><strong>docker run -d -p 8080:8080 &#8211;name ssm_tomcat -v \u6570\u636e\u5377\u540d\u79f0:\/usr\/local\/tomcat\/webapps \u955c\u50cf\u6807\u8bc6<\/strong><\/span><br \/>\n<span style=\"color: #ff0000;\"><strong>\u628awar\u5305\u590d\u5236\u5230\u6570\u636e\u5377\u7684_data\u76ee\u5f55\u4e0b<\/strong><\/span><br \/>\n<span style=\"color: #ff0000;\"><strong>cd ~<\/strong><\/span><br \/>\n<span style=\"color: #ff0000;\"><strong>cp ssm.war \/var\/lib\/docker\/volumes\/\u6570\u636e\u5377\u540d\u79f0\/_data<\/strong><\/span><br \/>\n<span style=\"color: #ff0000;\"><strong>docker logs -f \u955c\u50cf\u6807\u8bc6<\/strong><\/span><\/p>\n<p>\u6548\u679c\u56fe<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/13.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/14.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/09\/15.png\" alt=\"\" width=\"680\" \/><\/p>\n<hr \/>\n<h3>\u81ea\u5b9a\u4e49\u955c\u50cf<\/h3>\n<p>\u4e2d\u592e\u4ed3\u5e93\u4e0a\u7684\u955c\u50cf\uff0c\u4e5f\u662fDocker\u7684\u7528\u6237\u81ea\u5df1\u4e0a\u4f20\u8fc7\u53bb\u7684<\/p>\n<p>1.\u521b\u5efa\u4e00\u4e2aDockerfile\u6587\u4ef6\uff0c\u5e76\u4e14\u6307\u5b9a\u81ea\u5b9a\u4e49\u955c\u50cf\u4fe1\u606f<br \/>\nDockerfile\u6587\u4ef6\u4e2d\u5e38\u89c1\u7684\u5185\u5bb9\uff1a<strong>war\u5305\u8981\u8ddf\u6587\u4ef6\u653e\u5728\u540c\u4e00\u7ea7\u76ee\u5f55<\/strong><br \/>\nfrom\uff1a\u6307\u5b9a\u5f53\u524d\u81ea\u5b9a\u4e49\u955c\u50cf\u4f9d\u8d56\u7684\u73af\u5883<br \/>\ncopy\uff1a\u5c06\u76f8\u5bf9\u8def\u5f84\u4e0b\u7684\u5185\u5bb9\u590d\u5236\u5230\u81ea\u5b9a\u4e49\u955c\u50cf\u4e2d<br \/>\nworkdir \uff1a\u58f0\u660e\u955c\u50cf\u7684\u9ed8\u8ba4\u5de5\u4f5c\u76ee\u5f55<br \/>\ncmd \uff1a\u9700\u8981\u6267\u884c\u7684\u547d\u4ee4(\u5728workdir\u4e0b\u6267\u884c\u7684\uff0ccmd\u53ef\u4ee5\u5199\u591a\u7684\uff0c\u53ea\u4ee5\u6700\u540e\u4e00\u4e2a\u4e3a\u51c6)<\/p>\n<p>from daocloud.io\/library\/tomcat:8.5.15-jre8-alpine<br \/>\ncopy ssm.war \/usr\/local\/tomcat\/webapps<\/p>\n<p>2.\u5c06\u51c6\u5907\u597d\u7684Dockerfile\u548c\u76f8\u5e94\u7684\u6587\u4ef6\u62d6\u62fd\u5230Linux\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u901a\u8fc7docker\u547d\u4ee4\u5236\u4f5c\u955c\u50cf<br \/>\ndocker build -t \u81ea\u5b9a\u4e49\u955c\u50cf\u540d:\u7248\u672c \u8def\u5f84.(&#8220;.&#8221; \u4e3a\u5f53\u524d\u76ee\u5f55)<br \/>\ndocker build -t ssm-tomcat:1.0.0 .<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/10\/1.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/10\/2.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/10\/3.png\" alt=\"\" width=\"680\" \/><\/p>\n<hr \/>\n<h3>docker-compose<\/h3>\n<p><strong>\u4e0b\u8f7ddocker-compose<\/strong><\/p>\n<p>\u4e4b\u524d\u8fd0\u884c\u4e00\u4e2a\u955c\u50cf\uff0c\u9700\u8981\u6dfb\u52a0\u5927\u91cf\u7684\u53c2\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7docker-compose\u7f16\u5199\u8fd9\u4e9b\u53c2\u6570\u3002<br \/>\ndocker-compose\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u6279\u91cf\u7684\u7ba1\u7406\u5bb9\u5668\u3002\u53ea\u9700\u8981\u901a\u8fc7\u4e00\u4e2adocker-compose.yml\u6587\u4ef6\u53bb\u7ef4\u62a4\u5373\u53ef<\/p>\n<p><a href=\"https:\/\/github.com\/docker\/compose\/releases\/download\/1.24.1\/docker-compose-Linux-x86_64\" target=\"_blank\" rel=\"noopener noreferrer\">\u4e0b\u8f7ddocker-compose<\/a>\uff0c\u7248\u672c1.24.1<\/p>\n<p>\u5c06\u4e0b\u8f7d\u597d\u7684\u6587\u4ef6\u62d6\u62fd\u5230Linux\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u7136\u540e\u79fb\u52a8\u5230\/usr\/local<br \/>\nmv docker-compose-Linux-x86_64 \/usr\/local<\/p>\n<p>\u9700\u8981\u5c06docker-compose\u6587\u4ef6\u7684\u540d\u79f0\u4fee\u6539\uff0c\u57fa\u4e8edocker-compose\u6587\u4ef6\u662f\u4e00\u4e2a\u53ef\u6267\u884c\u7684\u6743\u9650<br \/>\nmv docker-compose-Linux-x86_64 docker-compose<br \/>\nchmod 777 docker-compose<\/p>\n<p>\u65b9\u4fbf\u540e\u671f\u64cd\u4f5c\uff0c\u914d\u7f6e\u4e00\u4e2a\u73af\u5883\u53d8\u91cf<br \/>\n\u5c06docker-compose\u6587\u4ef6\u79fb\u52a8\u5230\u4e86\/usr\/local\/bin\uff0c\u4fee\u6539\u4e86\/etc\/profile\u6587\u4ef6\uff0c\u7ed9usr\/local\/bin\u914d\u7f6e\u5230\u4e86PATH\u4e2d\u3002<br \/>\nmv docker-compose \/usr\/local\/bin<br \/>\nvi \/etc\/profile<br \/>\nexport PATH=$JAVA_HOME\/bin:\/usr\/local\/bin:$PATH<br \/>\nsource \/etc\/profile<br \/>\n\u6d4b\u8bd5\uff1adocker-compose<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/10\/4.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>docker-compose\u7ba1\u7406mysql\u548cTomcat\u5bb9\u5668<\/strong><\/p>\n<p>yml\u6587\u4ef6\u4ee5key: value\u65b9\u5f0f\u6765\u6307\u5b9a\u914d\u7f6e\u4fe1\u606f<br \/>\n\u591a\u4e2a\u914d\u7f6e\u4fe1\u606f\u4ee5\u6362\u884c+\u7f29\u8fdb\u7684\u65b9\u5f0f\u6765\u533a\u5206<\/p>\n<pre>version: '3.1'\r\nservices:\r\n  mysql:  #\u670d\u52a1\u7684\u540d\u79f0\r\n    restart: always  #\u4ee3\u8868\u53ea\u8981docker\u542f\u52a8\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5bb9\u5668\u5c31\u8ddf\u7740\u4e00\u8d77\u542f\u52a8\r\n    image: daocloud.io\/library\/mysql:5.7.4  #\u6307\u5b9a\u955c\u50cf\u8def\u5f84\r\n    container_name: mysql  #\u6307\u5b9a\u5bb9\u5668\u540d\u79f0\r\n    ports:\r\n      - 3306:3306  #\u6307\u5b9a\u7aef\u53e3\u53f7\u7684\u6620\u5c04\r\n    environment:\r\n      MYSQL_ROOT_PASSWORD: root  #\u6307\u5b9amysql\u7684root\u7528\u6237\u767b\u5f55\u5bc6\u7801\r\n      TZ: Asia\/Shanghai  #\u6307\u5b9a\u65f6\u533a\r\n    volumes:\r\n      - \/opt\/docker_mysql_tomcat\/mysql_data:\/var\/lib\/mysql  #\u6620\u5c04\u6570\u636e\u5377\r\n  tomcat:\r\n    restart: always  #\u4ee3\u8868\u53ea\u8981docker\u542f\u52a8\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5bb9\u5668\u5c31\u8ddf\u7740\u4e00\u8d77\u542f\u52a8\r\n    image: daocloud.io\/library\/tomcat:8.5.15-jre8-alpine  #\u6307\u5b9a\u955c\u50cf\u8def\u5f84\r\n    container_name: tomcat  #\u6307\u5b9a\u5bb9\u5668\u540d\u79f0\r\n    ports:\r\n      - 8080:8080  #\u6307\u5b9a\u7aef\u53e3\u53f7\u7684\u6620\u5c04\r\n    environment:\r\n      TZ: Asia\/Shanghai  #\u6307\u5b9a\u65f6\u533a\r\n    volumes:\r\n      - \/opt\/docker_mysql_tomcat\/tomcat_webapps:\/usr\/local\/tomcat\/webapps  #\u6620\u5c04\u6570\u636e\u5377\r\n      - \/opt\/docker_mysql_tomcat\/tomcat_logs:\/usr\/local\/tomcat\/logs\r\n    \r\n<\/pre>\n<p><strong>\u4f7f\u7528docker-compose\u547d\u4ee4\u7ba1\u7406\u5bb9\u5668<\/strong><\/p>\n<p>\u5728\u4f7f\u7528docker-compose\u7684\u547d\u4ee4\u65f6\uff0c\u9ed8\u8ba4\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u627edocker-compose.yml\u6587\u4ef6<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/10\/5.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/10\/6.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>1.\u57fa\u4e8edocker-compose.yml\u542f\u52a8\u7ba1\u7406\u7684\u5bb9\u5668<br \/>\ndocker-compose run -d<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/10\/7.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>2.\u5173\u95ed\u5e76\u5220\u9664\u5bb9\u5668<br \/>\ndocker-compose down<\/p>\n<p>3.\u5f00\u542f|\u5173\u95ed|\u91cd\u542f\u5df2\u7ecf\u5b58\u5728\u7684\u6709docker-compose\u7ef4\u62a4\u7684\u5bb9\u5668<br \/>\ndocker-compose start|stop|restart<\/p>\n<p>4.\u67e5\u770b\u7531docker-compose\u7ba1\u7406\u7684\u5bb9\u5668<br \/>\ndocker-compose ps<\/p>\n<p>5.\u67e5\u770b\u65e5\u5fd7<br \/>\ndocker-compose logs -f<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/10\/8.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>\u4f7f\u7528docker-compose\u914d\u7f6edockerfile\u4f7f\u7528<\/strong><\/p>\n<p>yml\u6587\u4ef6<\/p>\n<pre>version: '3.1'\r\nservices:\r\n  ssm:  #\u670d\u52a1\u7684\u540d\u79f0\r\n    restart: always  #\u4ee3\u8868\u53ea\u8981docker\u542f\u52a8\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5bb9\u5668\u5c31\u8ddf\u7740\u4e00\u8d77\u542f\u52a8\r\n    build:\r\n      context: ..\/  #\u6307\u5b9adockerfile\u6587\u4ef6\u7684\u6240\u5728\u8def\u5f84\r\n      dockerfile: Dockerfile  #\u6307\u5b9adockerfile\u6587\u4ef6\u540d\u79f0\r\n    image: ssm:1.0.1  #\u6307\u5b9a\u955c\u50cf\u8def\u5f84\r\n    container_name: ssm  #\u6307\u5b9a\u5bb9\u5668\u540d\u79f0\r\n    ports:\r\n      - 8081:8080  #\u6307\u5b9a\u7aef\u53e3\u53f7\u7684\u6620\u5c04\r\n    environment:\r\n      TZ: Asia\/Shanghai  #\u6307\u5b9a\u65f6\u533a\r\n<\/pre>\n<p>dockerfile:<\/p>\n<p>from daocloud.io\/library\/tomcat:8.5.15-jre8-alpine<br \/>\ncopy ssm.war \/usr\/local\/tomcat\/webapps<\/p>\n<p>1.\u521b\u5efadocker_ssm\u76ee\u5f55<br \/>\n2.\u521b\u5efadockerfile\u6587\u4ef6<br \/>\n3.\u7c98\u8d34war\u5305<br \/>\n4.\u521b\u5efadocker-compose\u76ee\u5f55<br \/>\n5.\u521b\u5efadocker-compose.yml\u6587\u4ef6<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/10\/9.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u53ef\u4ee5\u76f4\u63a5\u542f\u52a8\u57fa\u4e8edocker-compose.yml\u6587\u4ef6\u4ee5\u53cadockerfile\u6587\u4ef6\u6784\u5efa\u7684\u81ea\u5b9a\u4e49\u955c\u50cf<br \/>\ndocker-compose up -d<br \/>\n\u5982\u679c\u81ea\u5b9a\u4e49\u955c\u50cf\u4e0d\u5b58\u5728\uff0c\u4f1a\u81ea\u52a8\u6784\u5efa\u81ea\u5b9a\u4e49\u955c\u50cf\uff0c\u5982\u679c\u81ea\u5b9a\u4e49\u955c\u50cf\u5df2\u5b58\u5728\uff0c\u4f1a\u76f4\u63a5\u8fd0\u884c\u8fd9\u4e2a\u81ea\u5b9a\u4e49\u955c\u50cf<\/p>\n<p>\u91cd\u65b0\u6784\u5efa\u7684\u8bdd\uff1a<br \/>\n\u91cd\u65b0\u6784\u5efa\u81ea\u5b9a\u4e49\u955c\u50cf\uff1adocker-compose build<br \/>\n\u8fd0\u884c\u524d\uff0c\u91cd\u65b0\u6784\u5efa\uff1adocker-compose up -d &#8211;build<\/p>\n<hr \/>\n<h3>Docker CI\u3001CD<\/h3>\n<p>\u524d\u8a00\uff1a<br \/>\n\u9879\u76ee\u90e8\u7f72\uff1a<br \/>\n1.\u5c06\u9879\u76ee\u901a\u8fc7maven\u8fdb\u884c\u7f16\u8bd1\u6253\u5305<br \/>\n2.\u5c06\u6587\u4ef6\u4e0a\u4f20\u5230\u6307\u5b9a\u7684\u670d\u52a1\u5668\u4e2d<br \/>\n3.\u5c06war\u5305\u653e\u5230tomcat\u7684\u76ee\u5f55\u4e2d<br \/>\n4.\u901a\u8fc7dockerfile\u5c06tomcat\u548cwar\u5305\u8f6c\u6210\u4e00\u4e2a\u955c\u50cf\uff0c\u7531docker-compose\u53bb\u8fd0\u884c\u5bb9\u5668<\/p>\n<p>\u95ee\u9898\uff1a\u9879\u76ee\u66f4\u65b0\u4e86\u53c8\u8981\u5c06\u4e0a\u8ff0\u6d41\u7a0b\u518d\u6b21\u4ece\u5934\u5230\u5c3e\u6267\u884c\u4e00\u904d<\/p>\n<p><strong>CI\u4ecb\u7ecd<\/strong><\/p>\n<p>CI(continuous Intergration)\u6301\u7eed\u96c6\u6210<\/p>\n<p>\u6301\u7eed\u96c6\u6210\uff1a\u7f16\u5199\u4ee3\u7801\u65f6\uff0c\u5b8c\u6210\u4e86\u4e00\u4e2a\u529f\u80fd\u540e\uff0c\u7acb\u5373\u63d0\u4ea4\u4ee3\u7801\u5230git\u4ed3\u5e93\u4e2d\uff0c\u5c06\u9879\u76ee\u91cd\u65b0\u7684\u6784\u5efa\u5e76\u4e14\u6d4b\u8bd5<br \/>\n\u5feb\u901f\u53d1\u73b0\u9519\u8bef\u3001\u653e\u7f6e\u4ee3\u7801\u504f\u79bb\u4e3b\u5206\u652f\u3002<\/p>\n<p><strong>\u5b9e\u73b0\u6301\u7eed\u96c6\u6210<\/strong><\/p>\n<p>1.\u642d\u5efagitlab\u670d\u52a1\u5668<br \/>\n\u6b65\u9aa4\uff1a<br \/>\n1.\u521b\u5efa\u4e00\u4e2a\u5168\u65b0\u7684\u865a\u62df\u673a\uff0c\u5e76\u4e14\u81f3\u5c114G\u8fd0\u884c\u5185\u5b58<br \/>\n2.\u5b89\u88c5docker\u4ee5\u53cadocker-compose<br \/>\n3.docker-compose.yml\u6587\u4ef6\u53bb\u5b89\u88c5gitlab<br \/>\n4.<br \/>\ncd \/opt<br \/>\nmkdir docker_gitlab<br \/>\ncd docker_gitlab<br \/>\n\u521b\u5efa docker-compose.yml\u6587\u4ef6<\/p>\n<pre>version: '3.1'\r\nservices:\r\n gitlab:\r\n  image: 'twang2218\/gitlab-ce-zh:11.1.4'\r\n  container_name: \"gitlab\"\r\n  restart: always\r\n  privileged: true\r\n  hostname: 'gitlab'\r\n  environment:\r\n   TZ: 'Asia\/Shanghai'\r\n   GITLAB_OMNIBUS_CONFIG: |\r\n    external_url 'http:\/\/192.168.2.124'\r\n    gitlab_rails['time_zone'] = 'Asia\/Shanghai'\r\n    gitlab_rails['smtp_enable'] = true\r\n    gitlab_rails['gitlab_shell_ssh_port'] = 22\r\n  ports:\r\n   - '80:80'\r\n   - '443:443'\r\n   - '22:22'\r\n  volumes:\r\n   - \/opt\/docker_gitlab\/config:\/etc\/gitlab\r\n   - \/opt\/docker_gitlab\/data:\/var\/opt\/gitlab\r\n   - \/opt\/docker_gitlab\/logs:\/var\/log\/gitlab\r\n\r\n\r\n\r\n<\/pre>\n<p>\u7136\u540e docker-compose up -d<br \/>\n\u542f\u52a8 docker-compose logs -f<\/p>\n<p><strong>\u4fee\u6539Xterm\u768422\u7aef\u53e3\uff1a<br \/>\nvi \/etc\/ssh\/sshd_config<\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2021\/01\/12\/1.png\" alt=\"\" width=\"680\" \/><\/p>\n<h3>gitlab-runner<\/h3>\n<p><a href=\"\/wp-content\/uploads\/2021\/01\/12\/install.md\" target=\"_blank\" rel=\"noopener noreferrer\">\u5b89\u88c5\u6b65\u9aa4\u70b9\u51fb\u67e5\u770b<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>2020java\u5fae\u670d\u52a1\u67b6\u6784\u4e8c\u4e4bDocker\u5bb9\u5668\u5316\u6280\u672f Docker\u7684\u601d\u60f3 1.\u96c6\u88c5\u7bb1\uff1a \u4f1a\u5c06\u6240\u6709\u9700\u8981\u7684\u5185\u5bb9\u653e\u5230 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2927","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2927"}],"version-history":[{"count":20,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2927\/revisions"}],"predecessor-version":[{"id":3072,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2927\/revisions\/3072"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}