PermissionError: [Errno 13] Permission denied: '/app/manage.py' - docker

I run docker-compose command and get "PermissionDenied" error. I have used the same code about 2 month ago and it worked perfectly. I have searched internet and solutions didn't help much.
docker-compose run --rm app sh -c "django-admin startproject app ."
And it gives me an error:
Traceback (most recent call last):
File "/py/bin/django-admin", line 8, in <module>
sys.exit(execute_from_command_line())
File "/py/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/py/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/py/lib/python3.9/site-packages/django/core/management/commands/startproject.py", line 21, in handle
super().handle('project', project_name, target, **options)
File "/py/lib/python3.9/site-packages/django/core/management/templates.py", line 160, in handle
with open(new_path, 'w', encoding='utf-8') as new_file:
PermissionError: [Errno 13] Permission denied: '/app/manage.py'
My Dockerfile is :
FROM python:3.9-alpine3.13
LABEL maintainer="Kananappdeveloper"
ENV PYHTONUNBUFFERED 1
COPY ./requirements.txt /tmp/requirements.txt
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
COPY ./app /app
WORKDIR /app
EXPOSE 8000
ARG DEV=false
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
/py/bin/pip install -r /tmp/requirements.txt && \
if [ $DEV = "true" ]; \
then /py/bin/pip install -r /tmp/requirements.dev.txt ; \
fi && \
rm -rf /tmp && \
adduser \
--disabled-password \
--no-create-home \
django-user
ENV PATH="/py/bin:$PATH"
USER django-user
My OS is Ubuntu 22.04
Thank you in advance.

Related

How to add TailwindCSS to Docker container?

I'm trying to add TailwindCSS to Docker container but after running tailwindcss command in bash, it just says:
Traceback (most recent call last):
File "/usr/local/bin/tailwindcss", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.10/site-packages/pytailwindcss/__main__.py", line 9, in main
completed_process = pytailwindcss.run(
File "/usr/local/lib/python3.10/site-packages/pytailwindcss/__init__.py", line 45, in run
install(version, bin_path)
File "/usr/local/lib/python3.10/site-packages/pytailwindcss/__init__.py", line 69, in install
return install_binary(version, ensure_is_pathlib_path(bin_path))
File "/usr/local/lib/python3.10/site-packages/pytailwindcss/installation.py", line 25, in install_binary
os.makedirs(bin_path.parent, exist_ok=True)
File "/usr/local/lib/python3.10/os.py", line 225, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.10/site-packages/pytailwindcss/bin
Dockerfile:
FROM mcr.microsoft.com/vscode/devcontainers/python:3.10-bullseye
ENV PYTHONUNBUFFERED=1
WORKDIR /app
ARG FLASK_APP=project.app
ENV FLASK_APP=${FLASK_APP}
ARG FLASK_RUN_PORT=5001
ENV FLASK_RUN_PORT=${FLASK_RUN_PORT}
CMD flask run --host=0.0.0.0 # --port=${FLASK_RUN_PORT} --app=${FLASK_APP}
COPY requirements.txt /tmp/pip-tmp/
RUN pip --disable-pip-version-check install -r /tmp/pip-tmp/requirements.txt && \
rm -rf /tmp/pip-tmp
COPY . .
RUN pip --disable-pip-version-check install -v -e .
ARG CI_COMMIT_SHA
ENV CI_COMMIT_SHA=${CI_COMMIT_SHA}
RUN echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> /app/.env
ARG USERNAME=vscode
RUN test ! -z "${USERNAME}" && mkdir -p /home/${USERNAME}/.vscode-server/extensions && \
chown -R $USERNAME /home/$USERNAME/.vscode-server
EDIT:
Requirements.txt
importlib-metadata
flask
python-dotenv
flask-login
passlib
flask-mongoengine
python-dateutil
pytailwindcss
pre-commit
sentry-sdk[flask]
sentry-sdk[pymongo]
Any idea how to make TailwindCSS work in a Docker container?

Cannot run python script in Docker using chromedriver

After building the Docker file, trying to run the image when the python sript starts return this error:
Traceback (most recent call last):
File "/data/ms_rewards_farmer.py", line 815, in <module>
browser = browserSetup(True, PC_USER_AGENT)
File "/data/ms_rewards_farmer.py", line 48, in browserSetup
chrome_browser_obj = webdriver.Chrome(options=options)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line
69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line
89, in __init__
self.service.start()
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 71,
in start self.process = subprocess.Popen(cmd, env=self.env,
File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: 'chromedriver'
This is the Dockerfile:
FROM python:3.9.2
RUN mkdir -p /logs
RUN apt-get update
RUN apt install wget
RUN apt-get install -y wget xvfb unzip
# install google chrome
RUN apt-get install -y chromium
# install chromedriver
RUN wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
RUN unzip chromedriver_linux64.zip
RUN mv chromedriver /usr/bin/chromedriver
RUN chown root:root /usr/bin/chromedriver
RUN chmod +x /usr/bin/chromedriver
COPY . /data
WORKDIR /data
RUN pip install --no-cache-dir -r requirements.txt
# set display port to avoid crash
ENV DISPLAY=:99
# Custom Env Vars
ENV DOCKER_IMAGE=true
I don't know what's the problem, i tried to change the installation of chromedriver from the Dockerfile, any ideas?
Requirements.txt:
certifi
chardet
idna
requests
selenium
urllib3
ipapi
schedule

Unable to run geckodriver on Docker image with Mac M1 chip. selenium WebDriverException: Message: Process unexpectedly closed with status 1

I've successfully built a Docker image but can't seem to be able to run it. This is my Dockerfile:
FROM python:3.9
RUN apt-get update
#install system depend
RUN apt-get install -y software-properties-common
#Download and install Fire
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A6DCF7707EBC211F
RUN apt-add-repository "deb http://ppa.launchpad.net/ubuntu-mozilla-security/ppa/ubuntu bionic main" -y
RUN apt-get update -y
RUN apt-get install firefox -y
# Download and install geckodriver
RUN GECKODRIVER_VERSION=$(curl https://github.com/mozilla/geckodriver/releases | grep -Eo 'v0+.[0-9]+.[0-9]+' | head -1) && \
wget https://github.com/mozilla/geckodriver/releases/download/"$GECKODRIVER_VERSION"/geckodriver-"$GECKODRIVER_VERSION"-macos-aarch64.tar.gz && \
tar -xvzf geckodriver* && \
chmod +x geckodriver && \
mv geckodriver /usr/local/bin
ENV DISPLAY=:99
#Install depend and cop files
COPY . .
RUN pip install -r requirements.txt
CMD ["python3", "scrapper_class.py"]
I've also got a scrapper_class.py file, in which I do:
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
...
self.driver = webdriver.Firefox(service = Service(GeckoDriverManager().install()))
and it's throwing this error:
Traceback (most recent call last):
File "//scrapper_class.py", line 914, in <module>
bot = Scrapper()
File "//scrapper_class.py", line 31, in __init__
self.driver = webdriver.Firefox(service = Service(GeckoDriverManager().install()))
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 181, in __init__
RemoteWebDriver.__init__(
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 269, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 360, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 425, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1
can anyone tell me what I'm doing wrong?

pip install: metadata-generation-failed in docker

This is my Dockerfile:
FROM alpine:3.14
# Install python/pip
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
RUN apk add python3-dev # for python3.x installs
RUN apk add musl-dev
RUN apk add gcc
RUN mkdir -p /usr/src/tap-stashstock
RUN mkdir -p /usr/singer
WORKDIR /usr/src/tap-stashstock
ADD . /usr/src/tap-stashstock
ADD singer /usr/singer
RUN pip3 install --upgrade .
This works and then I run docker run -it stashstock-to-bigquery pip3 install target-bigquery which results in this error
Collecting grpcio<2.0dev,>=1.38.1
Downloading grpcio-1.44.0.tar.gz (21.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 21.4/21.4 MB 3.9 MB/s eta 0:00:00
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [12 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-4wuwnk4b/grpcio_429c1ed72b4244a0a71ac7e9f1ec81c6/setup.py", line 256, in <module>
if check_linker_need_libatomic():
File "/tmp/pip-install-4wuwnk4b/grpcio_429c1ed72b4244a0a71ac7e9f1ec81c6/setup.py", line 203, in check_linker_need_libatomic
cpp_test = subprocess.Popen([cxx, '-x', 'c++', '-std=c++11', '-'],
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'c++'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
What am I missing from my Dockerfile?
This error may for not having a C/C++ compiler.
Try install gcc and build-essensial before pip installation.
Please follow the steps given in
https://github.com/grpc/issues/24556

Wine not running on Google Cloud Run (limitations of google cloud run)

This is my docker file, which is installing wine in order to run some exes that I want to, on Google cloud run:
ARG BASE_IMAGE="ubuntu"
ARG TAG="latest"
FROM ${BASE_IMAGE}:${TAG}
# Install prerequisites
RUN apt-get update \
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \
cabextract \
git \
gosu \
gpg-agent \
p7zip \
pulseaudio-utils \
software-properties-common \
tzdata \
unzip \
wget \
winbind \
xvfb \
zenity \
&& rm -rf /var/lib/apt/lists/*
# Install wine
ARG WINE_BRANCH="stable"
RUN wget -O- -nv https://dl.winehq.org/wine-builds/winehq.key | apt-key add - \
&& apt-add-repository "deb https://dl.winehq.org/wine-builds/ubuntu/ $(grep VERSION_CODENAME= /etc/os-release | cut -d= -f2) main" \
&& dpkg --add-architecture i386 \
&& apt-get update \
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y --install-recommends winehq-${WINE_BRANCH} \
&& rm -rf /var/lib/apt/lists/*
# Install winetricks
RUN wget -nv https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks -O /usr/bin/winetricks \
&& chmod +x /usr/bin/winetricks
# Download gecko and mono installers
COPY download_gecko_and_mono.sh /root/download_gecko_and_mono.sh
RUN chmod +x /root/download_gecko_and_mono.sh \
&& /root/download_gecko_and_mono.sh "$(dpkg -s wine-${WINE_BRANCH} | grep "^Version:\s" | awk '{print $2}' | sed -E 's/~.*$//')"
RUN apt-get update
RUN apt-get install -y python3.6 python3-pip
RUN pip3 install flask gunicorn
RUN apt-get install -y nginx
COPY . /app
WORKDIR /app
RUN chmod a+x /usr/bin/wine
ENTRYPOINT ["/usr/local/bin/gunicorn","-w","1","--timeout","900","-b","0.0.0.0:8005","app:app"]
EXPOSE 8005
I have tested this container locally on my linux 64 bit machine, and it is able to run the wine commands (app.py is a flask server that calls exes).
But when I try to call "wine" on the GCR container (I even tried calling it at the beginning of my app.py, which is guaranteed to run), I get this error:
Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/usr/local/lib/python3.8/dist-packages/gunicorn/workers/base.py", line 119, in init_process self.load_wsgi() File "/usr/local/lib/python3.8/dist-packages/gunicorn/workers/base.py", line 144, in load_wsgi self.wsgi = self.app.wsgi() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/wsgiapp.py", line 49, in load return self.load_wsgiapp() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp return util.import_app(self.app_uri) File "/usr/local/lib/python3.8/dist-packages/gunicorn/util.py", line 358, in import_app mod = importlib.import_module(module) File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/app/app.py", line 27, in <module> print(subprocess.call(["wine"]) File "/usr/lib/python3.8/subprocess.py", line 340, in call with Popen(*popenargs, **kwargs) as p: File "/usr/lib/python3.8/subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) OSError: [Errno 8] Exec format error: 'wine'
The important line in the error being:
OSError: [Errno 8] Exec format error:
It is particularly odd because I would assume docker would guarantee portability across linux platforms.
EDIT:
The original issue was that I was not using wine64 (gcr only supports linux 64 bit binaries ), which resolved the original issue of wine running.
However, due to Cloud Run fully managed using gVisor sandbox, it was still not possible to get my exe running.
I have eventually moved to other approaches to solve my problem.
It is very likely that Wine does not work on Cloud Run fully managed.
Cloud Run fully managed uses gVisor sandbox (https://gvisor.dev/), which is an user-space syscall emulator written in Go. This environment does not run a real Linux kernel or real Docker runtime.
It's expected that there could be compatibility issues with exotic executables such as Wine (that exercise the syscall APIs to their full extent and corner cases). However, most server-side apps should be working fine.
You can use strace on Cloud Run to identify the culprit syscall and make a feature request to gVisor mentioning you need this on Cloud Run. Alternatively, you can use Cloud Run for Anthos, which runs on Kubernetes, with a real Linux kernel and Docker (or containerd).

Resources