for Time in Life:
Dockerfile for python 본문
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 thewget
andgnupg
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" >> /
'개발 환경' 카테고리의 다른 글
Difference between apt & apt-get (0) | 2023.02.10 |
---|---|
Difference between Chromedriver and Chromium-Chromedriver (0) | 2023.02.10 |
Installing Google Chrome and ChromeDriver in Linux Terminal (0) | 2023.02.10 |
시놀로지, 램 추가하기 (0) | 2022.09.03 |
pip, 패키지 리스트 관리하기 (0) | 2022.08.22 |