{"id":1386,"date":"2021-07-11T00:53:37","date_gmt":"2021-07-10T15:53:37","guid":{"rendered":"http:\/\/www.agile-software.site\/?p=1386"},"modified":"2021-07-17T18:34:54","modified_gmt":"2021-07-17T09:34:54","slug":"docker%e3%81%ae%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab","status":"publish","type":"post","link":"https:\/\/agile-software.net\/?p=1386","title":{"rendered":"Docker\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Windows\u74b0\u5883<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"543\" src=\"http:\/\/www.agile-software.site\/wp-content\/uploads\/2021\/07\/Docker_install-1024x543.png\" alt=\"\" class=\"wp-image-1387\" srcset=\"https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install-1024x543.png 1024w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install-300x159.png 300w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install-768x407.png 768w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install-1536x815.png 1536w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install.png 1904w, http:\/\/www.agile-software.site\/wp-content\/uploads\/2021\/07\/Docker_install-1024x543.png 856w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"706\" height=\"489\" src=\"http:\/\/www.agile-software.site\/wp-content\/uploads\/2021\/07\/Docker_install2.png\" alt=\"\" class=\"wp-image-1388\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"706\" height=\"489\" src=\"http:\/\/www.agile-software.site\/wp-content\/uploads\/2021\/07\/Docker_install3-1.png\" alt=\"\" class=\"wp-image-1390\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"581\" src=\"http:\/\/www.agile-software.site\/wp-content\/uploads\/2021\/07\/Docker_install4-1024x581.png\" alt=\"\" class=\"wp-image-1391\" srcset=\"https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install4-1024x581.png 1024w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install4-300x170.png 300w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install4-768x435.png 768w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install4.png 1270w, http:\/\/www.agile-software.site\/wp-content\/uploads\/2021\/07\/Docker_install4-1024x581.png 856w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker version\n$ docker-compose version<\/code><\/pre><\/div>\n\n\n\n<p>\u305d\u308c\u305e\u308c\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u308c\u3070Docker\u306f\u6b63\u5e38\u306b\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"732\" src=\"http:\/\/www.agile-software.site\/wp-content\/uploads\/2021\/07\/Docker_install5.png\" alt=\"\" class=\"wp-image-1392\" srcset=\"https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install5.png 859w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install5-300x256.png 300w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/07\/Docker_install5-768x654.png 768w, http:\/\/www.agile-software.site\/wp-content\/uploads\/2021\/07\/Docker_install5.png 856w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Linux\u74b0\u5883<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u53e4\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u30a2\u30f3\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>sudo apt-get remove docker docker-engine docker.io containerd runc<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u30d1\u30c3\u30b1\u30fc\u30b8\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>sudo apt-get update<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">HTTPS\u7d4c\u7531\u3067\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ sudo apt-get install \\\n    apt-transport-https \\\n    ca-certificates \\\n    curl \\\n    gnupg-agent \\\n    software-properties-common<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Docker\u516c\u5f0f\u306eGPG\u30ad\u30fc\u306e\u8ffd\u52a0<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo apt-key add -\n$ sudo apt-key fingerprint 0EBFCD88<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u8a2d\u5b9a<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ sudo add-apt-repository \\\n   &quot;deb [arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu \\\n   $(lsb_release -cs) \\\n   stable&quot;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Docker\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ sudo apt-get update\n$ sudo apt-get install docker-ce docker-ce-cli containerd.io\n$ apt-cache madison docker-ce\n$ sudo apt-get install docker-ce=5:18.09.5~3-0~ubuntu-bionic  docker-ce-cli=5:18.09.5~3-0~ubuntu-bionic containerd.io<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Docker\u304c\u6b63\u5e38\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u304b\u78ba\u8a8d<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ sudo docker run hello-world<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Docker\u3092\u81ea\u52d5\u8d77\u52d5\u3055\u305b\u308b<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>sudo systemctl enable docker<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Docker Compose\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>sudo curl -L &quot;https:\/\/github.com\/docker\/compose\/releases\/download\/1.25.4\/docker-compose-$(uname -s)-$(uname -m)&quot; -o \/usr\/local\/bin\/docker-compose<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b9f\u884c\u6a29\u9650\u9069\u7528<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>sudo chmod +x \/usr\/local\/bin\/docker-compose<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u78ba\u8a8d<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>docker-compose --version<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Django\u3092Docker\u4e0a\u3067\u52d5\u4f5c<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u30d5\u30a9\u30eb\u30c0\u304a\u3088\u3073\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ mkdir sql\n$ touch Dockerfile docker-compose.yml command.sh requirements.txt sql\/init.sql<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\" data-file=\"Dockerfile\"><code>FROM python:3.7\nENV PYTHONUNBUFFERED 1\n\nRUN mkdir \/code\nWORKDIR \/code\n\nADD requirements.txt \/code\/\nRUN pip3 install -r requirements.txt\n\nADD . \/code\/\nEXPOSE 8000\n\nCOPY .\/command.sh \/command.sh\nCMD [&quot;\/command.sh&quot;]<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\" data-file=\"docker-compose.yml\"><code>version: &#39;3&#39;\nservices:\n\n  web:\n    build: .\n    command: python3 manage.py runserver 0.0.0.0:8000\n    working_dir: \/code\n    ports:\n      - &#39;8000:8000&#39;\n    volumes:\n      - .:\/code\n    depends_on:\n      - db\n\n  db:\n    image: mysql:5.6\n    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci\n    environment:\n      MYSQL_ROOT_PASSWORD: root\n      MYSQL_DATABASE: django_docker\n      MYSQL_USER: user\n      MYSQL_PASSWORD: password\n    volumes:\n      - web-db-data:\/var\/lib\/mysql\n      - .\/sql:\/docker-entrypoint-initdb.d\n    ports:\n      - &#39;3306:3306&#39;\n\nvolumes:\n  web-db-data:<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\" data-file=\"command.sh\"><code>set -e\n\ncd \/code\n\nwait_count=0\nwhile ! python3 manage.py shell -c &quot;\nfrom django.db import connection\nwith connection.cursor() as cursor:\n    cursor.execute(&#39;select 1&#39;)\n    cursor.fetchall()\n&quot; 2&gt; \/dev\/null\ndo\n  echo Wait until DB is ready... $((wait_count += 1))\n  sleep 5\ndone\n\npython3 manage.py migrate --noinput\npython3 manage.py collectstatic --noinput<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>Django==2.2.10\nmysqlclient==1.4.6<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\" data-file=\"sql\/init.sql\"><code>GRANT ALL PRIVILEGES ON test_django_docker TO &#39;user&#39;@&#39;%&#39;;\nFLUSH PRIVILEGES;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8d77\u52d5<\/strong><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker-compose up db<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u4f5c\u6210<\/strong><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ docker-compose build web\n$ docker-compose run web django-admin startproject mysite .<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">MySQL\u306b\u5909\u66f4<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Windows\u74b0\u5883 \u305d\u308c\u305e\u308c\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u308c\u3070Docker\u306f\u6b63\u5e38\u306b\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u3059\u3002 Linux\u74b0\u5883 \u53e4\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u30a2\u30f3\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb \u30d1\u30c3\u30b1\u30fc\u30b8\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8 HTTPS\u7d4c\u7531\u3067\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u30d1\u30c3\u30b1\u30fc\u30b8<\/p>\n","protected":false},"author":1,"featured_media":1438,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jin_ogp_image_url":"","_jin_last_featured_id":0,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1386","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/1386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1386"}],"version-history":[{"count":3,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/1386\/revisions"}],"predecessor-version":[{"id":1489,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/1386\/revisions\/1489"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/media\/1438"}],"wp:attachment":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}