{"id":3356,"date":"2020-12-30T12:49:43","date_gmt":"2020-12-30T04:49:43","guid":{"rendered":"https:\/\/www.liangliang.org.cn\/?p=3356"},"modified":"2020-12-30T12:59:21","modified_gmt":"2020-12-30T04:59:21","slug":"%e6%b7%bb%e5%8a%a0%e5%92%8c%e4%bf%ae%e6%94%b9docker%e5%ae%b9%e5%99%a8%e7%ab%af%e5%8f%a3%e6%98%a0%e5%b0%84%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.liangliang.org.cn\/?p=3356","title":{"rendered":"\u6dfb\u52a0\u548c\u4fee\u6539docker\u5bb9\u5668\u7aef\u53e3\u6620\u5c04\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u4e00\u3001\u6dfb\u52a0docker\u5bb9\u5668\u7aef\u53e3\u6620\u5c04<\/p>\n<p>\u4ee5tomcat\u5bb9\u5668\u4e3a\u4f8b\uff1a<\/p>\n<pre><code>root@localhost \/]# docker run --name mytomcat -d -p 8888:8080 tomcat<\/code><\/pre>\n<p>\u2013name\uff1a\u521b\u5efa\u7684tomcat\u955c\u50cf\u540d\u79f0<br \/>\n\u2010d\uff1a\u540e\u53f0\u8fd0\u884c<br \/>\n\u2010p\uff1a\u5c06\u4e3b\u673a\u7684\u7aef\u53e3\u6620\u5c04\u5230\u5bb9\u5668\u7684\u4e00\u4e2a\u7aef\u53e3\uff0c8888:8080\u4ee3\u8868\uff1a\u4e3b\u673a\u7aef\u53e3:\u5bb9\u5668\u5185\u90e8\u7684\u7aef\u53e3<\/p>\n<p>\u6267\u884c\u5b8c\u4f1a\u8fd4\u56de\u65b0\u521b\u5efa\u7684tomcat\u955c\u50cfID<\/p>\n<p>\u4e8c\u3001\u4fee\u6539docker\u5bb9\u5668\u7aef\u53e3\u6620\u5c04<\/p>\n<p>\u65b9\u6cd5\u4e00<\/p>\n<ul>\n<li>1\u3001\u67e5\u770btomcat\u955c\u50cfID(docker ps)<\/li>\n<\/ul>\n<pre><code>root@localhost \/]# docker ps\nCONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES\nbf96392335e8        tomcat              &quot;catalina.sh run&quot;   5 minutes ago       Up 5 minutes        0.0.0.0:8888-&gt;8080\/tcp   mytomcat<\/code><\/pre>\n<ul>\n<li>2\u3001\u505c\u6b62\u5bb9\u5668(docker stop \u955c\u50cfID)<\/li>\n<\/ul>\n<pre><code>[root@localhost \/]# docker stop bf96392335e8<\/code><\/pre>\n<ul>\n<li>3\u3001\u505c\u6b62docker\u670d\u52a1(systemctl stop docker)<\/li>\n<\/ul>\n<pre><code>[root@localhost \/]# systemctl stop docker<\/code><\/pre>\n<ul>\n<li>4\u3001\u4fee\u6539\u6b64\u5bb9\u5668\u7684hostconfig.json\u6587\u4ef6\u4e2d\u7684\u6620\u5c04\u7aef\u53e3\uff0c\u82e5config.v2.json\u91cc\u9762\u4e5f\u8bb0\u5f55\u4e86\u7aef\u53e3\uff0c\u4e5f\u8981\u4fee\u6539\u3002<\/li>\n<\/ul>\n<pre><code>[root@localhost \/]# cd \/var\/lib\/docker\/containers\/bf96392335e8*\n[root@localhost bf96392335e88f3a0825aaec15bdd23100e642e899b6c34f9d2c33299178c464]# vi hostconfig.json<\/code><\/pre>\n<p>hostcongfig.json\uff1a<\/p>\n<pre><code>{&quot;Binds&quot;:null,&quot;ContainerIDFile&quot;:&quot;&quot;,&quot;LogConfig&quot;:{&quot;Type&quot;:&quot;journald&quot;,&quot;Config&quot;:{}},&quot;NetworkMode&quot;:&quot;default&quot;,&quot;PortBindings&quot;:{&quot;8080\/tcp&quot;:[{&quot;HostIp&quot;:&quot;&quot;,&quot;HostPort&quot;:&quot;8888&quot;}]},&quot;RestartPolicy&quot;:{&quot;Name&quot;:&quot;no&quot;,&quot;Ma\nximumRetryCount&quot;:0},&quot;AutoRemove&quot;:false,&quot;VolumeDriver&quot;:&quot;&quot;,&quot;VolumesFrom&quot;:null,&quot;CapAdd&quot;:null,&quot;CapDrop&quot;:null,&quot;Dns&quot;:[],&quot;DnsOptions&quot;:[],&quot;DnsSearch&quot;:[],&quot;ExtraHosts&quot;:null,&quot;GroupAdd&quot;:null,&quot;IpcMode&quot;:&quot;&quot;,&quot;Cgro\nup&quot;:&quot;&quot;,&quot;Links&quot;:[],&quot;OomScoreAdj&quot;:0,&quot;PidMode&quot;:&quot;&quot;,&quot;Privileged&quot;:false,&quot;PublishAllPorts&quot;:false,&quot;ReadonlyRootfs&quot;:false,&quot;SecurityOpt&quot;:null,&quot;UTSMode&quot;:&quot;&quot;,&quot;UsernsMode&quot;:&quot;&quot;,&quot;ShmSize&quot;:67108864,&quot;Runtime&quot;:&quot;docker\n-runc&quot;,&quot;ConsoleSize&quot;:[0,0],&quot;Isolation&quot;:&quot;&quot;,&quot;CpuShares&quot;:0,&quot;Memory&quot;:0,&quot;NanoCpus&quot;:0,&quot;CgroupParent&quot;:&quot;&quot;,&quot;BlkioWeight&quot;:0,&quot;BlkioWeightDevice&quot;:null,&quot;BlkioDeviceReadBps&quot;:null,&quot;BlkioDeviceWriteBps&quot;:null,&quot;Blki\noDeviceReadIOps&quot;:null,&quot;BlkioDeviceWriteIOps&quot;:null,&quot;CpuPeriod&quot;:0,&quot;CpuQuota&quot;:0,&quot;CpuRealtimePeriod&quot;:0,&quot;CpuRealtimeRuntime&quot;:0,&quot;CpusetCpus&quot;:&quot;&quot;,&quot;CpusetMems&quot;:&quot;&quot;,&quot;Devices&quot;:[],&quot;DiskQuota&quot;:0,&quot;KernelMemory&quot;:0\n,&quot;MemoryReservation&quot;:0,&quot;MemorySwap&quot;:0,&quot;MemorySwappiness&quot;:-1,&quot;OomKillDisable&quot;:false,&quot;PidsLimit&quot;:0,&quot;Ulimits&quot;:null,&quot;CpuCount&quot;:0,&quot;CpuPercent&quot;:0,&quot;IOMaximumIOps&quot;:0,&quot;IOMaximumBandwidth&quot;:0}<\/code><\/pre>\n<p>\u5176\u4e2d\uff1a\u201cPortBindings\u201d:{\u201c8080\/tcp\u201d:[{\u201cHostIp\u201d:&quot;&quot;,\u201cHostPort\u201d:\u201c8888\u201d}]}\u4ee3\u8868\u7aef\u53e3\u6620\u5c04\u914d\u7f6e\uff0c\u4fee\u6539HostPort\u9879\u7684\u503c\u540e\u4fdd\u5b58\u9000\u51fa\u3002<\/p>\n<ul>\n<li>5\u3001\u542f\u52a8docker(systemctl start docker)<\/li>\n<\/ul>\n<pre><code>[root@localhost \/]# systemctl start docker<\/code><\/pre>\n<ul>\n<li>6\u3001\u542f\u52a8tomcat\u955c\u50cf(docker start \u955c\u50cfID)<\/li>\n<\/ul>\n<pre><code>[root@localhost \/]# docker start bf96392335e8<\/code><\/pre>\n<p>\u65b9\u6cd5\u4e8c<\/p>\n<ul>\n<li>1\u3001\u83b7\u5f97\u5bb9\u5668IP<br \/>\n\u5c06container_name \u6362\u6210\u5b9e\u9645\u73af\u5883\u4e2d\u7684\u5bb9\u5668\u540d<\/li>\n<\/ul>\n<pre><code>docker inspect `container_name` | grep IPAddress<\/code><\/pre>\n<ul>\n<li>2\u3001iptable\u8f6c\u53d1\u7aef\u53e3<br \/>\n\u5c06\u5bbf\u4e3b\u673a\u76848888\u7aef\u53e3\u6620\u5c04\u5230IP\u4e3a192.168.1.15\u5bb9\u5668\u76848080\u7aef\u53e3<\/li>\n<\/ul>\n<pre><code>iptables -t nat -A  DOCKER -p tcp --dport 8888 -j DNAT --to-destination 192.168.1.15:8080<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6dfb\u52a0docker\u5bb9\u5668\u7aef\u53e3\u6620\u5c04 \u4ee5tomcat\u5bb9\u5668\u4e3a\u4f8b\uff1a root@localhost \/]# docker run &#8211;name mytomcat -d -p 8888:8080 tomcat \u2013&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[],"class_list":["post-3356","post","type-post","status-publish","format-standard","hentry","category-docker"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3356"}],"version-history":[{"count":5,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3356\/revisions"}],"predecessor-version":[{"id":3364,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3356\/revisions\/3364"}],"wp:attachment":[{"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}