docker入門してみた01(windows11)

# はじめに
記録用です。初投稿なのでご了承ください。
インフラエンジニアのサマーインターンに1週間参加してきました。
そこで、インフラの知識の乏しさと自身の力なさを感じたため、インフラの知識を増やすモチベが上がりました。

# 環境
プロセッサ: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz   1.80 GHz
RAM: 8.00 GB 
OS: windows 11


# Docker for windows
## 参考

https://qiita.com/gahoh/items/7b21377b5c9e3ffddf4a

## docker for windowsのDL
1. 以下に従ってインストールを進めます。プロパティはそのままにしました。

https://docs.docker.com/desktop/install/windows-install/

2. 以下の画面が出てくるので、WSLをそのままDLしました。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2261812/d04526b8-ff7c-0a15-8883-c36ff8335832.png)


## version, hello worldの実行
power shellで以下を実行しました
[先ほどのdockerの記事](https://qiita.com/gahoh/items/7b21377b5c9e3ffddf4a)より、versionの確認、docker run hello-worldにより、

```:docker version
PS C:\Users\wwwka> docker version
Client:
 Cloud integration: v1.0.28
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:09:02 2022
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.11.1 (84025)
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:23 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:        v1.1.2-0-ga916309
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
```


```:docker run hello-world
PS C:\Users\wwwka> docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:      
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
```

## docker for winの起動
### 1.repositoryのクローン
画面に従って操作します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2261812/c16abc67-a7ac-8ed5-37fb-73f6eeb6997e.png)

```:docker run --name repo alpine/git clone 
PS C:\Users\wwwka> docker run --name repo alpine/git clone https://github.com/docker/getting-started.git
Unable to find image 'alpine/git:latest' locally
latest: Pulling from alpine/git
213ec9aee27d: Pull complete
fd2d85b6e65f: Pull complete
72ec27a2c987: Pull complete
Digest: sha256:7b9c96bea8268579e925b17170ae208788e90d508ec334421384913ba61cd610
Status: Downloaded newer image for alpine/git:latest
Cloning into 'getting-started'...
```
### 2. Now, build the image
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2261812/9b7b3a9b-73e3-28e0-39f6-934156d3e5cf.png)

```:cd getting-started 
PS C:\Users\wwwka> cd getting-started
PS C:\Users\wwwka\getting-started> docker build -t docker101tutorial .
[+] Building 38.5s (28/28) FINISHED
 => [internal] load build definition from Dockerfile                   0.1s
 => => transferring dockerfile: 1.12kB                                 0.0s 
 => [internal] load .dockerignore                                      0.1s 
 => => transferring context: 52B                                       0.0s 
 => [internal] load metadata for docker.io/library/nginx:alpine        3.2s
 => [internal] load metadata for docker.io/library/node:12-alpine      3.0s 
 => [internal] load metadata for docker.io/library/python:alpine       3.2s 
 => [auth] library/node:pull token for registry-1.docker.io            0.0s
 => [auth] library/python:pull token for registry-1.docker.io          0.0s
 => [auth] library/nginx:pull token for registry-1.docker.io           0.0s 
 => [app-base 1/5] FROM docker.io/library/node:12-alpine@sha256:d4b15  8.9s
 => => resolve docker.io/library/node:12-alpine@sha256:d4b15b3d48f420  0.0s 
 => => sha256:4517380049fc3c9aacceae7764fcf3500354b0a 1.16kB / 1.16kB  0.0s 
 => => sha256:bb6d28039b8cec9aa8d9032f9aa640a792a60c2 6.58kB / 6.58kB  0.0s 
 => => sha256:df9b9388f04ad6279a7410b85cedfdcb2208c0a 2.81MB / 2.81MB  0.6s 
 => => sha256:d4b15b3d48f42059a15bd659be60afe21762aae 1.43kB / 1.43kB  0.0s 
 => => sha256:7939e601ee5e4737cf7fdb6d1dfe31ca4c26971 2.36MB / 2.36MB  1.0s 
 => => sha256:3bf6d738020517f4622814e8c21db4b4aaa78 24.91MB / 24.91MB  4.9s 
 => => extracting sha256:df9b9388f04ad6279a7410b85cedfdcb2208c0a003da  0.6s
 => => sha256:31f0fb9de071269230cb0f786012ae4e81d26e489b1 451B / 451B  1.0s 
 => => extracting sha256:3bf6d738020517f4622814e8c21db4b4aaa78ae7cab4  3.2s 
 => => extracting sha256:7939e601ee5e4737cf7fdb6d1dfe31ca4c2697109290  0.2s 
 => => extracting sha256:31f0fb9de071269230cb0f786012ae4e81d26e489b1f  0.0s 
 => [stage-6 1/3] FROM docker.io/library/nginx:alpine@sha256:082f8c10  7.0s 
 => => resolve docker.io/library/nginx:alpine@sha256:082f8c10bd47b6ac  0.0s 
 => => sha256:082f8c10bd47b6acc8ef15ae61ae45dd8fde0e9 1.65kB / 1.65kB  0.0s 
 => => sha256:2959a35e1b1e61e2419c01e0e457f75497e02d0 1.57kB / 1.57kB  0.0s 
 => => sha256:804f9cebfdc58964d6b25527e53802a3527a9ee 8.89kB / 8.89kB  0.0s 
 => => sha256:2546ae67167b3580b7dcc4a4d56e504594bac17 7.40MB / 7.40MB  4.8s
 => => sha256:23b845224e138d383175fc5fb15d93ad0795468b8d6 601B / 601B  4.5s 
 => => sha256:9bd5732789a330a86ed2257e6bf18928c6ae873107e 894B / 894B  4.8s
 => => sha256:328309e59ded59f3fc9eb5ade5c0135ec9aae5553ab 666B / 666B  5.0s
 => => sha256:b231d02e51502ce72ff0813057a12b7778148c2 1.40kB / 1.40kB  5.2s
 => => extracting sha256:2546ae67167b3580b7dcc4a4d56e504594bac17e22e0  0.8s
 => => extracting sha256:23b845224e138d383175fc5fb15d93ad0795468b8d62  0.0s
 => => extracting sha256:9bd5732789a330a86ed2257e6bf18928c6ae873107ef  0.0s
 => => extracting sha256:328309e59ded59f3fc9eb5ade5c0135ec9aae5553ab8  0.0s
 => => extracting sha256:b231d02e51502ce72ff0813057a12b7778148c2e629a  0.0s
 => [internal] load build context                                      0.3s
 => => transferring context: 10.45MB                                   0.3s
 => [base 1/4] FROM docker.io/library/python:alpine@sha256:0c46c7f15e  6.9s
 => => resolve docker.io/library/python:alpine@sha256:0c46c7f15ee201a  0.0s
 => => extracting sha256:9fc487f386544a636bd7edc089e9591a048401d4bd30  0.6s 
 => [base 2/4] WORKDIR /app                                            0.8s 
 => [base 3/4] COPY requirements.txt .                                 0.2s 
 => [base 4/4] RUN pip install -r requirements.txt                    24.1s 
 => [app-base 2/5] WORKDIR /app                                        0.2s 
 => [app-base 3/5] COPY app/package.json app/yarn.lock ./              0.1s 
 => [app-base 4/5] COPY app/spec ./spec                                0.1s 
 => [app-base 5/5] COPY app/src ./src                                  0.1s 
 => [app-zip-creator 1/4] COPY app/package.json app/yarn.lock ./       0.1s  => [app-zip-creator 2/4] COPY app/spec ./spec                         0.1s  => [app-zip-creator 3/4] COPY app/src ./src                           0.1s  => [app-zip-creator 4/4] RUN apk add zip &&     zip -r /app.zip /app  2.4s  => [stage-6 2/3] COPY --from=app-zip-creator /app.zip /usr/share/ngi  0.1s  => [build 1/2] COPY . .                                               0.1s  => [build 2/2] RUN mkdocs build                                       2.7s  => [stage-6 3/3] COPY --from=build /app/site /usr/share/nginx/html    0.1s  => exporting to image                                                 0.1s  => => exporting layers                                                0.1s  => => writing image sha256:51a90b87e7b664c82d000c038769dab899fa86ee9  0.0s  => => naming to docker.io/library/docker101tutorial                   0.0s 
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
```

### 3. Run your first container
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2261812/88e1d74b-007d-40fa-651e-32b1f8d3f6a1.png)

```:docker run -d -p 80:80 --name docker-tutorial docker101tutorial
PS C:\Users\wwwka\getting-started> docker run -d -p 80:80 --name docker-tutorial docker101tutorial
14f7e7c3bf6256991afaea26141336bf3ce1da40abdf4cc30c777df70cb1f970
```

### 4. Now save and share your image
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2261812/784a6c10-4714-9c35-940a-6b74339122c5.png)

```
PS C:\Users\wwwka\getting-started> docker tag docker101tutorial hwata001/docker101tutorial
```