0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows11上にWSL2+dockerを構築する

Posted at

WSLもDockerも触ったことない初心者がDockerfileから環境を構築する話。

環境

ホストPC

  • OS:Windows11 Home 24H2
  • GPU:NVIDIA GeForce RTX 4060

Dockerfile

docker-compose.yaml
services:
  dev1:
    build:
      context: .
      dockerfile: dockerfiles/Dockerfile.gpu
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    container_name: atla4
    ports:
      - "8080:8080"
    volumes:
      - .:/workspace
    tty: true

環境構築開始

はじめはこの記事に従って環境構築を進める。
ただし、Dockerfileからのコンテナ構築なので、起動コマンドがdocker compose up -dとなる。

しかし、この手順ですんなりはいかずに、いくつかのトラブルが発生した。

トラブル①

Dockerを起動しようとするが、「6.permissionを与える」でうまくいかない。
記事の手順に従うが、エラーが消えない。

WSL/Ubuntu-22.04/terminal
unable to get image 'simulator_dist-dev1': permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.51/images/simulator_dist-dev1/json": dial unix /var/run/docker.sock: connect: permission denied

sudo usermod -aG docker usernameコマンドを実行後に、newgrp dockerコマンドを実行することでうまくいった。

Docker起動が進むことを確認した。

WSL/Ubuntu-22.04/terminal
$ docker compose up -d
 [+] Running 2/2
 ✔ simulator_dist-dev1             Built                                                        0.0s
 ✘ Network simulator_dist_default  Error                                                        0.0s
failed to create network simulator_dist_default: Error response from daemon: Failed to Setup IP tables: Unable to enable SKIP DNAT rule:  (iptables failed: iptables --wait -t nat -I DOCKER -i br-2e50c495159a -j RETURN: iptables: No chain/target/match by that name.
 (exit status 1))

トラブル②

「7. iptablesの設定を古いものに変更する」のエラーが出て、記事の手順に従うが、エラーが消えない。

iptablesを見てみるとDocker関連の設定がないことがわかる。

WSL/Ubuntu-22.04/terminal
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

どうやら、iptablesを再起動などしたときは、Dockerの再起動もしたほうが良いらしい。

sudo systemctl restart dockerコマンドを実行して、Dockerを再起動する。
Docker起動が進むことを確認した。

WSL/Ubuntu-22.04/terminal
$ docker compose up -d
 ✔ Network simulator_dist_default  Created                                                      0.0s
 ⠋ Container atla4                 Starting                                                     0.1s
Error response from daemon: could not select device driver "nvidia" with capabilities: [[gpu]]

トラブル③

元の記事にはないが、ホストPCにはGPUがあるので、それを利用できるコンテナを構築しようと思う。
しかし、ドライバが無いというエラーが出た。

この記事の手順に従ってドライバーをインストールする。

Dockerの起動がうまいこといった。

$ docker compose up -d
 ✔ Container atla4  Started   

ステータスがUPになっていることも確認できた。

$ docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS                                         NAMES
6b068f1e9b92   simulator_dist-dev1   "/opt/nvidia/nvidia_…"   23 minutes ago   Up 40 seconds   0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp   atla4
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?