2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python Docker poetry

Posted at

## はじめに
備忘録
fastAPIの学習をするにあたりpoetryで環境を作ります。

構成

新規立ち上げ時はDockerfileのCOPYとRUNを修正してpoetryの初期化を行う

app/
  main.py
  poetry.lock
  pyproject.toml
docker-compose.yml
Dockerfile
.env

Dockerfile

FROM python:3.10.10-bullseye

# poetryのPATHを$PATHに追加
ENV PATH /root/.local/bin:$PATH

WORKDIR /app

COPY ["./app/pyproject.toml", "./app/poetry.lock", "/app/"]

RUN apt-get update \
    && curl -sSL https://install.python-poetry.org | python3 - \
    && poetry config virtualenvs.create false \ # コンテナなので仮想環境はいらない
    && poetry install

# コンテナ実行後に行いたいコマンドを記述する FastAPIの場合の例は下記
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]

docker-compose.yml

version: "3.8"
services:
  app:
    build:
      context: ./
      dockerfile: ./Dockerfile
    env_file: ./.env
    tty: true
    volumes:
      - ./app:/app
    ports:
      - "8000:8000"
    environment:
      - TZ=Asia/Tokyo
  db:
    image: mysql:8.0.31
    platform: linux/amd64
    env_file: ./.env
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    volumes:
      - ./db/data:/var/lib/mysql
      - ./db/conf.d:/etc/mysql/conf.d
    ports:
      - 3306:3306
    environment:
      TZ: Asia/Tokyo

おわりに

poetryでtypingをインストール使用して詰まった
typingはpythonの標準パッケージなので別途インストールする必要はなかった

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?