반응형
ubuntu:22.04 위에 python3.10 설치하는 Dockerfile
openai, langchain 을 설치후 사용하려고 만듬 - 인터넷 여러 Dockerfile 소스를 참조함
ubuntu:22.04 - python3.10 Dockerfile
#Dockerfile
#https://codepal.ai/dockerfile-writer.py/query/2yZiifQq/dockerfile-installing-python-3-9-ubuntu-22-04
#https://luis-sena.medium.com/creating-the-perfect-python-dockerfile-51bdec41f1c8
# Use the Ubuntu 22.04 as the base image - 순수 ubuntu:22.04 size = 77.8MB
FROM ubuntu:22.04
#아래 쉘스크립트 에러 방지 - .bashrc 관련에서 에러
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# Set environment variables for configuration
ENV PYTHON_VERSION=3.10
# Set maintainer label
LABEL maintainer="Your Name <your.email@example.com>"
# Update the package lists and install necessary packages
RUN apt-get update && \
apt-get install -y python${PYTHON_VERSION} && \
apt-get install -y python3-pip && \
apt-get clean
# Set the default working directory
WORKDIR /app
#RUN echo 'alias python=python3' >> /home/.bashrc
# alias 적용
RUN \
echo 'alias python="/usr/bin/python3"' >> /root/.bashrc && \
echo 'alias pip="/usr/bin/pip3"' >> /root/.bashrc && \
source /root/.bashrc
# python library list 복사
COPY requirements.txt requirements.txt
# python library 설치
RUN pip install -r requirements.txt
# Copy your application code to the container
#배포때만 필요한 - 개발때는 docker -v 옵션으로 실시간 연결로 사용해야함
#COPY . /app
# make sure all messages always reach console
ENV PYTHONUNBUFFERED=1
requirements.txt
#requirements.txt
python-dotenv
langchain==0.0.316
openai==0.28.1
도커 관련 명령 예시
#도커 이미지 리스트
docker images
#도커 이미지 강제 삭제 (-f 옵션은 컨테이너까지 삭제함 - 컨테이너 실행중에는 삭제안됨)
docker rmi -f 1974ec24bb07(IMAGE ID)
#도커 이미지 생성
docker build -t ubuntu2204-python310 .
#도커 실행 - --rm=컨테이너끝날때 삭제, -it=터미널 창이 보이기, -v=현재폴더와 /app/code를 링크시킴
# 도커 이미지 실행하면서 bash 쉘 실행하기 - 파이썬 코드 실행을 위해서
docker run --rm -it -v .:/app ubuntu2204-python310 /bin/bash
관련글
[langchain + openai 에러] AttributeError: module 'openai' has no attribute 'error'
파이썬에서 openai를 이용하기 위해 langchain을 사용하였는데 계속 에러가 발생하면서 제대로 실행이 안됨, langchain공식 문서에 있는 소스를 가져와서 실행해도 계속 에러 발생함. 에러 내용은 Attrib
dtbb.tistory.com
반응형
'Linux' 카테고리의 다른 글
배포자동화(CI/CD) - Github Actions/Nuxtjs/Docker/EC2 [링크] (4) | 2024.08.27 |
---|---|
크론탭(crontab) 등록 및 확인 (0) | 2024.04.25 |
타 사이트를 NGINX Reverse Proxy를 사용중 CORS 에러 해결법은? (2) | 2024.04.17 |
Windows에 Docker 설치후 실행하기 (f. Docker Desktop 없을때) (0) | 2024.04.02 |
도커 이미지 컨테이너 (Docker) 관련 자주 쓰는 명령어 (2) | 2023.11.13 |