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?

WSL+DockerでPython環境構築

Last updated at Posted at 2025-10-31

2025,11

Docker Desktopをインストール

ここから

  1. Download Docker Descktop
  2. Download for - Windows ADM64 (intel, AMDの場合)

作業用プロジェクトの作成

mkdir docker-python
cd docker-python

次のような構成をniコマンドなどを使って作成

docker-python/
├─ Dockerfile
├─ docker-compose.yml
└─ opt/
   └─ main.py

ファイルの準備

  • Dockerfile
    Python3,Ubuntu22.04をベースに作成
FROM python:3.11-slim

WORKDIR /root

# ホストのコードをコピー(composeでvolume指定してれば不要)
COPY ./opt ./opt

CMD ["/bin/bash"]
  • docker-compose.yml
services:
  python3:
    build: .
    container_name: python3
    working_dir: /root
    tty: true
    volumes:
      - ./opt:/root/opt
  • main.py
    サンプルコードを作成
print("Hello world")

実行手順

<追記>

  • 以降,wsldocker-descktopが起動している状態
  1. イメージをビルド&コンテナ起動
docker compose up -d --build
  1. コンテナの確認
docker ps        # 実行中のコンテナ一覧
docker images    # イメージ一覧
  1. コンテナに入る
docker compose exec python3 bash
  1. Pythonを実行
python3 opt/main.py
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?