{"id":210,"date":"2019-03-25T23:02:37","date_gmt":"2019-03-25T15:02:37","guid":{"rendered":"https:\/\/www.aiqinqin.info\/?p=210"},"modified":"2019-03-27T23:15:07","modified_gmt":"2019-03-27T15:15:07","slug":"210","status":"publish","type":"post","link":"https:\/\/www.aiqinqin.info\/?p=210","title":{"rendered":"docker\u7684\u4f7f\u7528"},"content":{"rendered":"<ul>\n<li>-&#45;link\u8868\u793a\u8fde\u63a5\u5230redis\u8fd9\u4e2a\u5bb9\u5668; -p \u662f\u6620\u5c04\u7aef\u53e3 ;-e \u662f\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/li>\n<\/ul>\n<pre><code class=\"\">docker run -d --link redis --name flask-redis -p 5000:5000 -e REDIS_HOST=redis xiang\/flash-redis\n<\/code><\/pre>\n<ul>\n<li>\u4e0d\u540c\u5bbf\u4e3b\u673a\u91cc\u9762\u5bb9\u5668\u7684\u901a\u4fe1\uff0c\u901a\u8fc7Overlay\u7f51\u7edc\u548cetcd\u5b9e\u73b0<\/li>\n<li>\u6570\u636e\u6301\u4e45\u5316<\/li>\n<\/ul>\n<pre><code class=\"\">docker run -d -v mysql:\/var\/lib\/mysql --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql\n<\/code><\/pre>\n<blockquote><p>\n  \u591a\u673a\u5668\u901a\u4fe1\u73af\u5883\u642d\u5efa\n<\/p><\/blockquote>\n<ol>\n<li>\u73af\u5883\u662fnode1\u4e3a:172.16.50.32; node2\u4e3a\uff1a 172.16.50.33\uff1b\u7cfb\u7edf\u90fd\u4e3aCENTOS7\u7cfb\u7edf<\/li>\n<li>\u5b89\u88c5etcd\u96c6\u7fa4\uff0c\u5e76\u7528\u4e0b\u9762\u547d\u4ee4\u8fd0\u884c,\u7cfb\u7edf\u9700\u8981\u653e\u5f002379\u548c2380\u4e24\u4e2a\u7aef\u53e3\uff1a<\/li>\n<\/ol>\n<pre><code class=\"\">nohup \/opt\/etcd\/etcd --name docker-node1 --initial-advertise-peer-urls http:\/\/172.16.50.32:2380 \\\n--listen-peer-urls http:\/\/172.16.50.32:2380 \\\n--listen-client-urls http:\/\/172.16.50.32:2379,http:\/\/127.0.0.1:2379 \\\n--advertise-client-urls http:\/\/172.16.50.32:2379 \\\n--initial-cluster-token etcd-cluster \\\n--initial-cluster docker-node1=http:\/\/172.16.50.32:2380,docker-node2=http:\/\/172.16.50.33:2380 \\\n--initial-cluster-state new&amp;\n\nnohup \/opt\/etcd\/etcd --name docker-node2 --initial-advertise-peer-urls http:\/\/172.16.50.33:2380 \\\n--listen-peer-urls http:\/\/172.16.50.33:2380 \\\n--listen-client-urls http:\/\/172.16.50.33:2379,http:\/\/127.0.0.1:2379 \\\n--advertise-client-urls http:\/\/172.16.50.33:2379 \\\n--initial-cluster-token etcd-cluster \\\n--initial-cluster docker-node1=http:\/\/172.16.50.32:2380,docker-node2=http:\/\/172.16.50.33:2380 \\\n--initial-cluster-state new&amp;\n\n\/opt\/etcd\/etcdctl cluster-health ##\u67e5\u770betcd\u96c6\u7fa4\u72b6\u6001\n<\/code><\/pre>\n<ol start=\"3\">\n<li>\u505c\u6b62\u8fd0\u884cdocker\u670d\u52a1\uff0c\u5e76\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5728\u76f8\u5e94\u7684\u8282\u70b9\u4e0a\u8fd0\u884c\uff0c\u9700\u8981\u653e\u884c2375\u548c7496\u4e24\u4e2a\u7aef\u53e3<\/li>\n<\/ol>\n<pre><code class=\"\">\/usr\/bin\/dockerd -H tcp:\/\/0.0.0.0:2375 -H unix:\/\/\/var\/run\/docker.sock --cluster-store=etcd:\/\/172.16.50.32:2379 --cluster-advertise=172.16.50.32:2375&amp;\n\n\/usr\/bin\/dockerd -H tcp:\/\/0.0.0.0:2375 -H unix:\/\/\/var\/run\/docker.sock --cluster-store=etcd:\/\/172.16.50.33:2379 --cluster-advertise=172.16.50.33:2375&amp;\n<\/code><\/pre>\n<ol start=\"4\">\n<li>\u521b\u5efa\u4e00\u4e2aoverlay\u7684\u7f51\u7edc, \u53ea\u5728\u4e00\u4e2a\u8282\u70b9\u4e0a\u9762\u5efa\u7acb\u5c31\u53ef\u4ee5\u4e86<\/li>\n<\/ol>\n<pre><code class=\"\">docker network create -d overlay demo\n<\/code><\/pre>\n<ol start=\"5\">\n<li>\u6d4b\u8bd5\u5728node1\u548cnode2\u4e0a\u9762\u5206\u522b\u521b\u5efa\u4e00\u4e2adocker<\/li>\n<\/ol>\n<pre><code class=\"\">docker run -d --name test1 --net demo busybox sh -c \"while true;do sleep 3600;done\"  # node1\u4e0a\u9762\u8fd0\u884c\ndocker run -d --name test2 --net demo busybox sh -c \"while true;do sleep 3600;done\"  # node2\u4e0a\u9762\u8fd0\u884c\n<\/code><\/pre>\n<blockquote><p>\n  \u4f7f\u7528compose\u642d\u5efa\u4e00\u4e2awordpress\u7ad9\u70b9\n<\/p><\/blockquote>\n<pre><code class=\"\">version: '3'\nservices:\n  wordpress:\n    image: wordpress\n    ports:\n      - 8080:80\n    environment:\n      WORDPRESS_DB_HOST: mysql\n      WORDPRESS_DB_PASSWORD: wordpress_password\n    networks:\n      - my-bridge\n  mysql:\n    image: mysql:5.7\n    environment:\n      MYSQL_ROOT_PASSWORD: wordpress_password\n      MYSQL_DATABASE: wordpress\n    volumes:\n      - mysql-data:\/var\/lib\/mysql\n    networks:\n      - my-bridge\nvolumes:\n  mysql-data:\nnetworks:\n  my-bridge:\n    driver: bridge\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>-&#45;link\u8868\u793a\u8fde\u63a5\u5230redis\u8fd9\u4e2a\u5bb9\u5668; -p \u662f\u6620\u5c04\u7aef\u53e3 ;-e \u662f\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf docker r [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,6],"tags":[],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-docker","category-vitual"],"_links":{"self":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=210"}],"version-history":[{"count":4,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":214,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/210\/revisions\/214"}],"wp:attachment":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}