1
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?

Docker + Python +Poetryの環境構築

Last updated at Posted at 2024-11-06

目的

DockerでPython + Poetryの環境を構築しようとしたら、恐ろしく苦戦したためここに完成した環境のメモを残す。

構築環境

↓フォルダツリー

C:
│  .gitignore
│  docker-compose.yml
│  README.md
│
└─backend
      Dockerfile # 最初はbackendフォルダにDockerFileのみ作成。
      poetry.lock
      pyproject.toml

↓docker-compose.yml

docker-compose.yml
services:
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    volumes:
      - ./backend:/app
    working_dir: /app
    ports:
      - 8000:8000
    tty: true

↓Dockerfile

FROM python:3.13

# 作業ディレクトリを設定
WORKDIR /app
ENV PYTHONUNBUFFERED 1

# poetryインストール
RUN curl -sSL https://install.python-poetry.org | python3 - && \
    ln -s /root/.local/bin/poetry /usr/local/bin/poetry


# # コンテナ内で仮想環境の作成を無効
RUN poetry config virtualenvs.create false && \
    poetry config virtualenvs.in-project true

COPY . .

  1. docker-compose up --buildでコンテナ作成&起動
  2. コンテナの中に入ってpoetry -versionが動くことを確認
  3. Poetryを使って好きなフレームワークとかを構築できる
1
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
1
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?