반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

for Time in Life:

Dockerfile for python 본문

개발 환경

Dockerfile for python

rooter 2023. 2. 10. 17:37

Here is the final code of dockerfile

# Use an official Python image as the base image
FROM python:3.9.2-buster

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install required packages and Chrome browser
RUN apt-get update \
    # Update the package list
    && apt-get install -y wget gnupg \
    # Install wget and gnupg packages
    && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    # Download and add the Google Linux repository signing key
    && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
    # Add the Google Linux repository to the sources list
    && apt-get update \
    # Update the package list again
    && apt-get install -y google-chrome-stable
    # Install the Chrome browser

# Install Chrome Driver
RUN CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \
    # Get the latest version of Chrome Driver
    wget -N https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P ~/ \
    # Download the Chrome Driver archive
    && unzip ~/chromedriver_linux64.zip -d ~/ \
    # Unzip the Chrome Driver archive
    && rm ~/chromedriver_linux64.zip \
    # Remove the Chrome Driver archive
    && mv -f ~/chromedriver /usr/local/bin/chromedriver \
    # Move the Chrome Driver binary to the system PATH
    && chown root:root /usr/local/bin/chromedriver \
    # Change the ownership of the Chrome Driver binary to root
    && chmod 0755 /usr/local/bin/chromedriver
    # Set the executable permission for the Chrome Driver binary

# Set the environment variable for Chrome Driver
ENV CHROME_DRIVER_PATH /usr/local/bin/chromedriver

# Install required Python packages
RUN pip install --no-cache-dir -r requirements.txt

# Run the command when the container launches
CMD ["python", "your_script.py"]

 

here is a more detailed explanation of each command in the Dockerfile:

# Use an official Python image as the base image
FROM python:3.9.2-buster

The FROM command specifies the base image to use for the Docker container. In this case, we are using an official Python image with version 3.9.2 and the buster distribution.

# Set the working directory in the container
WORKDIR /app

The WORKDIR command sets the working directory for the subsequent commands in the Dockerfile. In this case, we are setting it to /app.

# Copy the current directory contents into the container at /app
COPY . /app

The COPY command copies the contents of the current directory on the host into the specified directory in the Docker container. In this case, we are copying everything in the current directory (.) into the /app directory in the container.

# Install required packages and Chrome browser
RUN apt-get update \
    # Update the package list
    && apt-get install -y wget gnupg \
    # Install wget and gnupg packages
    && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    # Download and add the Google Linux repository signing key
    && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
    # Add the Google Linux repository to the sources list
    && apt-get update \
    # Update the package list again
    && apt-get install -y google-chrome-stable
    # Install the Chrome browser

The RUN command runs a shell command in the Docker container. In this case, we are using the apt-get command to install the necessary packages and the Chrome browser.

  • The first apt-get update command updates the package list.
  • The apt-get install -y wget gnupg command installs the wget and gnupg packages.
  • The wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - command downloads the Google Linux repository signing key and adds it to the system.
  • The echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /
반응형