インストール
インストール開始
- Get Dockerからインストーラーをダウンロード
- インストーラーを実行
- 再起動
- サブスクリプション同意のダイアログ
- 無償条件は小規模事業(従業員250人未満かつ年間収益1,000万ドル未満)、個人利用、教育、非商用オープンソースプロジェクト)
- 個人利用ならキャンセル
WSLでエラー
インストール中にWSL (Windows Subsystem for Linux)のバージョンが低すぎるとエラーになった。
WSLをアップデート。
1 2 3 |
C:\Users\me\dev\docker >wsl.exe --update インストール中: Linux 用 Windows サブシステム Linux 用 Windows サブシステム はインストールされました。 |
再起動。
1 2 3 4 5 6 7 8 9 10 11 |
C:\Users\me\dev\docker >docker version error during connect: this error may indicate that the docker daemon is not running: Get "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/version": open //./pipe/docker_engine: The system cannot find the file specified. Client: Cloud integration: v1.0.35-desktop+001 Version: 24.0.5 API version: 1.43 Go version: go1.20.6 Git commit: ced0996 Built: Fri Jul 21 20:36:24 2023 OS/Arch: windows/amd64 Context: default |
Docker Desktop起動
WindowsのアプリケーションからDocker Desktopを起動後、コンソールでバージョンを確認。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
C:\Users\me\dev\docker >docker version Client: Cloud integration: v1.0.35-desktop+001 Version: 24.0.5 API version: 1.43 Go version: go1.20.6 Git commit: ced0996 Built: Fri Jul 21 20:36:24 2023 OS/Arch: windows/amd64 Context: default Server: Docker Desktop 4.22.1 (118664) Engine: Version: 24.0.5 API version: 1.43 (minimum version 1.12) Go version: go1.20.6 Git commit: a61e2b4 Built: Fri Jul 21 20:35:45 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.21 GitCommit: 3dce8eb055cbb6872793272b4f20ed16117344f8 runc: Version: 1.1.7 GitCommit: v1.1.7-0-g860f061 docker-init: Version: 0.19.0 GitCommit: de40ad0 |
イメージやコンテナは空っぽの状態。
1 2 3 4 5 |
C:\Users\m\dev\docker e>docker images REPOSITORY TAG IMAGE ID CREATED SIZE C:\Users\me\dev\docker >docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
Learning Center
Welcome
Docker DesktopのLearning centerを試してみる。まずWelcomeをGitHubからクローン。
1 2 3 4 5 6 7 8 |
C:\Users\me\dev\docker >git clone https://github.com/docker/welcome-to-docker Cloning into 'welcome-to-docker'... remote: Enumerating objects: 94, done. remote: Counting objects: 100% (25/25), done. remote: Compressing objects: 100% (10/10), done. Receiving objects: 70% (66/94)used 15 (delta 15), pack-reused 69 Receiving objects: 100% (94/94), 312.87 KiB | 26.07 MiB/s, done. Resolving deltas: 100% (42/42), done. |
得られたフォルダー。
1 2 3 4 5 6 7 |
C:\Users\me\dev\docker >dir C:\Users\me\dev\docker のディレクトリ 2023/09/11 21:44 <DIR> . 2023/09/11 21:44 <DIR> .. 2023/09/11 21:44 <DIR> welcome-to-docker |
ターゲットのフォルダーに移動してビルド。welcomeの画面が表示される。
1 2 3 |
>cd welcome-to-docker >docker build -t welcome-to-docker . |
multi-container-app
GitHubからクローン。
1 2 3 4 5 6 7 8 |
>git clone https://github.com/docker/multi-container-app Cloning into 'multi-container-app'... remote: Enumerating objects: 2283, done. remote: Counting objects: 100% (15/15), done. remote: Compressing objects: 100% (12/12), done. remote: Total 2283 (delta 3), reused 11 (delta 2), pack-reused 2268 Receiving objects: 100% (2283/2283), 3.81 MiB | 10.63 MiB/s, done. Resolving deltas: 100% (358/358), done. |
フォルダー構成。
1 2 3 4 5 6 7 8 9 10 11 12 |
>cd multi-container-app multi-container-app>dir C:\Users\me\dev\docker\multi-container-app のディレクトリ 2023/09/11 13:04 <DIR> . 2023/09/11 13:04 <DIR> .. 2023/09/11 13:04 18 .gitignore 2023/09/11 13:04 <DIR> app 2023/09/11 13:04 888 compose.yaml 2023/09/11 13:04 215 README.md |
compose.ymlの内容。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# Comments are provided throughout this file to help you get started. # If you need more help, visit the Docker compose reference guide at # https://docs.docker.com/compose/compose-file/ # Here the instructions define your application as two services called "todo-app" and “todo-database” # The service “todo-app” is built from the Dockerfile in the /app directory, # and the service “todo-database” uses the official MongoDB image # from Docker Hub - https://hub.docker.com/_/mongo. # You can add other services your application may depend on here. services: todo-app: build: context: ./app links: - todo-database environment: NODE_ENV: production ports: - 3000:3000 todo-database: image: mongo:6 #volumes: # - database:/data/db ports: - 27017:27017 #volumes: #database: |
compose実行。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
>docker compose up -d [+] Running 1/10 [+] Running 1/10 9 layers [⠀⣿⠀⠀⠀⠀⠀⠀⠀] 51.19kB/5.051MB Pulling 4.8s [+] Running 1/10 9 layers [⠀⣿⡀⠀⠀⠀⠀⠀⠀] 1.108MB/5.051MB Pulling 4.9s [+] Running 1/10 9 layers [⠀⣿⡀⠀⠀⠀⠀⠀⠀] 1.108MB/5.051MB Pulling 5.0s [+] Running 1/10 9 layers [⠀⣿⣄⠀⠀⠀⠀⠀⠀] 2.206MB/5.051MB Pulling 5.1s [+] Running 1/10 9 layers [⠀⣿⣤⠀⠀⠀⠀⠀⠀] 2.968MB/35.49MB Pulling 5.2s [+] Running 1/10 9 layers [⠀⣿⣦⠀⠀⠀⠀⠀⠀] 3.619MB/35.49MB Pulling 5.3s [+] Running 2/10 9 layers [⠀⣿⣶⠀⠀⠀⠀⠀⠀] 5.028MB/35.49MB Pulling 5.4s - todo-database 9 layers [⠀⣿⣿⠀⠀⠀⠀⠀⠀] 1.245MB/30.44MB Pulling 5.5s [+] Running 2/10b Downloading [==> ] 1.245MB/... 1.4s - todo-database 9 layers [⠀⣿⣿⠀⠀⠀⠀⠀⠀] 1.245MB/30.44MB Pulling 5.6s [+] Running 2/10b Downloading [==> ] 1.245MB/... 1.5s - todo-database 9 layers [⠀⣿⣿⠀⠀⠀⠀⠀⠀] 1.868MB/30.44MB Pulling 5.7s [+] Running 2/10b Downloading [===> ] 1.868MB/... 1.6s - todo-database 9 layers [⠀⣿⣿⠀⠀⠀⠀⠀⠀] 3.121MB/31.69MB Pulling 5.8s ..... [+] Running 1/1 [+] Running 2/2ti-container-app_default Created 0.1s ✔ Network multi-container-app_default Created 0.1s[+] Running 2/3lti-container-app-todo-database-1 Creating 0.0s ✔ Network multi-container-app_default Created 0.1s[+] Running 2/3ulti-container-app-todo-app-1 Created 0.0s ✔ Network multi-container-app_default Created 0.1s[+] Running 2/3ulti-container-app-todo-app-1 Created 0.0s ✔ Network multi-container-app_default Created 0.1s[+] Running 2/3ulti-container-app-todo-app-1 Created 0.0s ✔ Network multi-container-app_default Created 0.1s[+] Running 2/3ulti-container-app-todo-app-1 Created 0.0s ✔ Network multi-container-app_default Created 0.1s[+] Running 2/3 ✔ Network multi-container-app_default Created 0.1s[+] Running 3/3 ✔ Network multi-container-app_default Created 0.1s ✔ Container multi-container-app-todo-database-1 Started 0.5s ✔ Container multi-container-app-todo-app-1 Started |
localhost:3000にアクセスして結果確認。
Persisting Data
GitHubからクローン後、compose.ymlを確認。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# Comments are provided throughout this file to help you get started. # If you need more help, visit the Docker compose reference guide at # https://docs.docker.com/compose/compose-file/ # Here the instructions define your application as two services called "todo-app" and “todo-database” # The service “todo-app” is built from the Dockerfile in the /app directory, # and the service “todo-database” uses the official MongoDB image # from Docker Hub - https://hub.docker.com/_/mongo. # You can add other services your application may depend on here. services: todo-app: build: context: ./app links: - todo-database environment: NODE_ENV: production ports: - 3000:3000 todo-database: image: mongo:6 volumes: - database:/data/db ports: - 27017:27017 volumes: database: |
compose実行。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
multi-container-app>docker compose up -d [+] Running 3/0 ✔ Network multi-container-app_default Created 0.0s [+] Running 3/4ti-container-app_database" Created 0.0s ✔ Network multi-container-app_default Created 0.0s ✔ Container multi-container-app-todo-database-1 Created 0.0s [+] Running 3/4ti-container-app_database" Created 0.0s ✔ Network multi-container-app_default Created 0.0s - Container multi-container-app-todo-database-1 Starting 0.2s [+] Running 3/4ti-container-app_database" Created 0.0s ✔ Network multi-container-app_default Created 0.0s - Container multi-container-app-todo-database-1 Starting 0.3s [+] Running 3/4ti-container-app_database" Created 0.0s ✔ Network multi-container-app_default Created 0.0s - Container multi-container-app-todo-database-1 Starting 0.4s [+] Running 3/4ti-container-app_database" Created 0.0s ✔ Network multi-container-app_default Created 0.0s ✔ Container multi-container-app-todo-database-1 Started 0.4s [+] Running 4/4ti-container-app_database" Created 0.0s ✔ Network multi-container-app_default Created 0.0s ✔ Container multi-container-app-todo-database-1 Started 0.4s ✔ Volume "multi-container-app_database" Created 0.0s - Container multi-container-app-todo-app-1 Starting 0.5s ✔ Container multi-container-app-todo-database-1 Started 0.4s ✔ Container multi-container-app-todo-app-1 Started |
これでコンテナーを停止/削除してもデータが保存される。なお、volumeの実体の保存場所はWindowsの場合以下の場所で、エクスプローラーのアドレスバーに\\wsl$
と入力してたどっていける。
1 |
ネットワーク\wsl$\docker-desktop-data\data\docker\volumes |