Error with Docker File Running Seleniarm as Base

243 Views Asked by At

Hi I am trying to create a docker file with seleniarm as base image (using raspberry pi so need multiarch), and adding python to it. This is my file:

# Use the Selenium base image
FROM seleniarm/standalone-chromium

# Switch to the root user
USER root

# Install Python and pip
RUN apt-get update && \
    apt-get install -y python3 python3-pip

# Set up a working directory
WORKDIR /app

# Copy your Python code or scripts into the container
COPY . /app

# Install required Python packages using pip
RUN pip3 install selenium requests==2.26.0 beautifulsoup4==4.9.3

# Specify the command to run when the container starts
CMD ["python3", "myscript.py"]

Every time I try to build the container, I am getting error with installing the python packages. Have tried via requirement.txt file and direct as above but its not working.

These are all the libraries I need, for the python script which creates booking in my club:

# Import all the required libraries
from datetime import datetime, timedelta, time
import time as tm
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains


# initiate Chrome driver and open website
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService

Am I doing something wrong?

The container doesn't build.

adding more details:

with this command

# Install required Python packages using pip
RUN pip3 install selenium requests==2.26.0 beautifulsoup4==4.9.3

I get this error

=> ERROR [5/5] RUN pip3 install selenium requests==2.26.0 beautifulsoup4==4.9.3                                                                                                                                   3.5s
------                                                                                                                                                                                                                  
 > [5/5] RUN pip3 install selenium requests==2.26.0 beautifulsoup4==4.9.3:                                                                                                                                              
1.572 WARNING: The directory '/home/seluser/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.                                                                                                                                                                 
1.588 error: externally-managed-environment                                                                                                                                                                             
1.588 
1.588 × This environment is externally managed
1.588 ╰─> To install Python packages system-wide, try apt install
1.588     python3-xyz, where xyz is the package you are trying to
1.588     install.
1.588     
1.588     If you wish to install a non-Debian-packaged Python package,
1.588     create a virtual environment using python3 -m venv path/to/venv.
1.588     Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
1.588     sure you have python3-full installed.
1.588     
1.588     If you wish to install a non-Debian packaged Python application,
1.588     it may be easiest to use pipx install xyz, which will manage a
1.588     virtual environment for you. Make sure you have pipx installed.
1.588     
1.588     See /usr/share/doc/python3.11/README.venv for more information.
1.588 
1.588 note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
1.588 hint: See PEP 668 for the detailed specification.
------
Dockerfile:18
--------------------
  16 |     
  17 |     # Install required Python packages using pip
  18 | >>> RUN pip3 install selenium requests==2.26.0 beautifulsoup4==4.9.3
  19 |     
  20 |     # Specify the command to run when the container starts
--------------------
ERROR: failed to solve: process "/bin/sh -c pip3 install selenium requests==2.26.0 beautifulsoup4==4.9.3" did not complete successfully: exit code: 1

and with below requirements.txt file

selenium
requests==2.26.0
beautifulsoup4==4.9.3

I get:

=> ERROR [5/5] RUN pip3 install -r requirements.txt                                                                                                                                                               2.0s
------                                                                                                                                                                                                                  
 > [5/5] RUN pip3 install -r requirements.txt:                                                                                                                                                                          
1.618 WARNING: The directory '/home/seluser/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.                                                                                                                                                                 
1.635 error: externally-managed-environment                                                                                                                                                                             
1.635 
1.635 × This environment is externally managed
1.635 ╰─> To install Python packages system-wide, try apt install
1.635     python3-xyz, where xyz is the package you are trying to
1.635     install.
1.635     
1.635     If you wish to install a non-Debian-packaged Python package,
1.635     create a virtual environment using python3 -m venv path/to/venv.
1.635     Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
1.635     sure you have python3-full installed.
1.635     
1.635     If you wish to install a non-Debian packaged Python application,
1.635     it may be easiest to use pipx install xyz, which will manage a
1.635     virtual environment for you. Make sure you have pipx installed.
1.635     
1.635     See /usr/share/doc/python3.11/README.venv for more information.
1.635 
1.635 note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
1.635 hint: See PEP 668 for the detailed specification.
------
Dockerfile:21
--------------------
  19 |     
  20 |     # Install any required Python packages using pip
  21 | >>> RUN pip3 install -r requirements.txt
  22 |     
  23 |     # Specify the command to run when the container starts
--------------------
ERROR: failed to solve: process "/bin/sh -c pip3 install -r requirements.txt" did not complete successfully: exit code: 1
0

There are 0 best solutions below