Contenido del Curso
Docker for Python Developers
4. Advanced Concepts
Docker for Python Developers
Installing Libraries
In this chapter, we'll pack into the container not only Python and Python script but also several Python libraries.
After specifying the base image, you use the RUN pip install
command to install additional Python packages using the pip
package manager. In this case, you're installing the numpy
, pandas
, and scikit-learn
packages, which for example, might be crucial for data analysis and machine learning.
Code Description
FROM python:3.9-slim
indicates the use of the base Python image version
3.9-slim
;-
RUN pip install numpy pandas scikit-learn
installs the numpy
, pandas
, and scikit-learn
packages;- The
COPY . .
command copies all files and folders from the local directory into the root directory of the container.-
CMD ["python", "app.py"]
specifies running the Python application located in the app.py
file.
This Dockerfile demonstrates how to install dependencies and additional files in your Docker container for use in your data analysis or machine learning projects.
Installing Requirements
Here's the revised Dockerfile where libraries are installed using a requirements file:
You also need to create a requirements.txt
file listing the libraries you want to install. For example:
After that, you can build the Docker image using the command docker build -t <image_name> .
, where <image_name>
is the name you want to give to your image.
¿Todo estuvo claro?
Contenido del Curso
Docker for Python Developers
4. Advanced Concepts
Docker for Python Developers
Installing Libraries
In this chapter, we'll pack into the container not only Python and Python script but also several Python libraries.
After specifying the base image, you use the RUN pip install
command to install additional Python packages using the pip
package manager. In this case, you're installing the numpy
, pandas
, and scikit-learn
packages, which for example, might be crucial for data analysis and machine learning.
Code Description
FROM python:3.9-slim
indicates the use of the base Python image version
3.9-slim
;-
RUN pip install numpy pandas scikit-learn
installs the numpy
, pandas
, and scikit-learn
packages;- The
COPY . .
command copies all files and folders from the local directory into the root directory of the container.-
CMD ["python", "app.py"]
specifies running the Python application located in the app.py
file.
This Dockerfile demonstrates how to install dependencies and additional files in your Docker container for use in your data analysis or machine learning projects.
Installing Requirements
Here's the revised Dockerfile where libraries are installed using a requirements file:
You also need to create a requirements.txt
file listing the libraries you want to install. For example:
After that, you can build the Docker image using the command docker build -t <image_name> .
, where <image_name>
is the name you want to give to your image.
¿Todo estuvo claro?