본문 바로가기
Programming/Python

docker compose - python default 컨테이너 만들기

by Chan_찬 2023. 4. 5.
728x90

docker with python

매번 가상환경(pyenv, poetry) 생성하는 것보다, 별도의 도커 컨테이너 만들기

필요한 파일

  • docker-compose.yml
  • Dockerfile
  • requirements.txt
# docker-compose.yml
version: '3'

services:
  app:
    build: .
    stdin_open: true
    tty: true
    volumes:
      - .:/app

# Dockerfile
FROM python:3.11-slim-buster

WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt; \
	apt-get update; \
    apt-get install -y --no-install-recommends \
    git \
    curl \
    vim \
    ; \
    apt-get remove -y --auto-remove \
        wget \
        ; \
    rm -rf /var/lib/apt/lists/*;
COPY . .

# requirements.txt
...

docker-compose.yml 에서 `app` 부분, `test`는 디렉토리 이름

$ docker compose up
...
Attaching to test-app-1
test-app-1  | Python 3.11.2 (main, Mar 23 2023, 03:16:57) [GCC 8.3.0] on linux
test-app-1  | Type "help", "copyright", "credits" or "license" for more information.

2023.04.11 - [Programming/Rust] - docker compose - rust default 컨테이너 만들기

728x90
728x90
Buy me a coffeeBuy me a coffee

댓글