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).
Related
In my application, I need to build a docker image on a k8s init-container using docker-in-docker approach.
This is the Dockerfile of the init container:
FROM docker-hub-mirror.mycorp.com/docker:dind
ARG username
ARG password
RUN apk update && apk add --no-cache bash curl git git-lfs ca-certificates coreutils
RUN git-lfs install
COPY daemon.json /etc/docker/daemon.json
COPY scripts/* /bin/
RUN docker login harbor.mycorp.com -u=${username} -p=${password};\
sed -i "s/ROBOT_USER/${username}:${password}/g" /bin/build_image.sh
ENV SHOWROOM_LOG_PATH=/var/log/showroom/app.log
ENTRYPOINT ["dockerd-entrypoint.sh"]
The flow is to build the input docker image first and use that image to run the application in application containers later.
This is the input Dockerfile:
# https://gitlab.com/nvidia/container-images/cuda/-/blob/master/dist/11.7.1/ubuntu2204/devel/cudnn8/Dockerfile
FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu22.04
ENV DEBIAN_FRONTEND noninteractive
WORKDIR /content
RUN apt-get update -y && apt-get upgrade -y && apt-get install -y sudo && apt-get install -y python3-pip && pip3 install --upgrade pip
RUN apt-get install -y curl gnupg wget htop sudo git git-lfs software-properties-common build-essential libgl1 zip unzip
RUN add-apt-repository ppa:flexiondotorg/nvtop
RUN apt-get upgrade -y
RUN apt-get install -y nvtop
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs
RUN npm install
RUN npm install -g configurable-http-proxy
ENV PATH="/home/admin/.local/bin:${PATH}"
RUN pip3 install jupyterhub && \
pip3 install --upgrade notebook && \
pip3 install oauthenticator && \
pip3 install pandas scipy matplotlib && \
pip3 install --upgrade jupyterlab jupyterlab-git && \
pip3 install ipywidgets && \
pip3 install torch torchvision torchaudio && \
jupyter lab build
RUN jupyter nbextension enable --py widgetsnbextension
RUN git clone https://github.com/camenduru/jupyter
COPY login.html /usr/local/lib/python3.10/dist-packages/jupyter_server/templates/login.html
RUN adduser --disabled-password --gecos '' admin
RUN adduser admin sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN chown -R admin:admin /content
RUN chmod -R 777 /content
RUN chown -R admin:admin /home
RUN chmod -R 777 /home
USER admin
EXPOSE 7860
CMD jupyter-lab --ip 0.0.0.0 --port 7860 --no-browser --allow-root --NotebookApp.token='huggingface' --NotebookApp.tornado_settings="{'headers': {'Content-Security-Policy': 'frame-ancestors *'}}" --NotebookApp.cookie_options="{'SameSite': 'None', 'Secure': True}" --NotebookApp.disable_check_xsrf=True
It failed at this line
RUN add-apt-repository ppa:flexiondotorg/nvtop
At first, I got this error from the init-container logs
#0 2.170 File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 230, in __init__
#0 2.170 super(Launchpad, self).__init__(
#0 2.170 File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 472, in __init__
#0 2.170 self._wadl = self._browser.get_wadl_application(self._root_uri)
#0 2.170 File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 447, in get_wadl_application
#0 2.170 response, content = self._request(url, media_type=wadl_type)
#0 2.170 File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 389, in _request
#0 2.170 response, content = self._request_and_retry(
#0 2.170 File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 359, in _request_and_retry
#0 2.170 response, content = self._connection.request(
#0 2.170 File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1725, in request
#0 2.171 (response, content) = self._request(
#0 2.171 File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 144, in _request
#0 2.171 response, content = super(LaunchpadOAuthAwareHttp, self)._request(
#0 2.171 File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 184, in _request
#0 2.171 return super(RestfulHttp, self)._request(
#0 2.171 File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1441, in _request
#0 2.171 (response, content) = self._conn_request(conn, request_uri, method, body, headers)
#0 2.171 File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1363, in _conn_request
#0 2.171 conn.connect()
#0 2.171 File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1199, in connect
#0 2.172 raise socket_err
#0 2.172 File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1153, in connect
#0 2.172 sock.connect((self.host, self.port))
#0 2.172 OSError: [Errno 99] Cannot assign requested address
I've tried two solutions, first is to use the option --network=host
I've modified the build step to
docker build --network=host -t $tag .
then I got this error
File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 230, in __init__
super(Launchpad, self).__init__(
File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 472, in __init__
self._wadl = self._browser.get_wadl_application(self._root_uri)
File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 447, in get_wadl_application
response, content = self._request(url, media_type=wadl_type)
File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 389, in _request
response, content = self._request_and_retry(
File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 359, in _request_and_retry
response, content = self._connection.request(
File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1725, in request
(response, content) = self._request(
File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 144, in _request
response, content = super(LaunchpadOAuthAwareHttp, self)._request(
File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 184, in _request
return super(RestfulHttp, self)._request(
File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1441, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1363, in _conn_request
conn.connect()
File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1153, in connect
sock.connect((self.host, self.port))
TimeoutError: [Errno 110] Connection timed out
The second solution is to use add-host, I modified the build command to:
docker build --add-host dockerhost:`/sbin/ip route|awk '/default/ { print $3}'` -t $tag .
I got the OSError: [Errno 99] Cannot assign requested address like before.
I can build the input Dockerfile locally on my computer, I'm not sure what might be the correct network configuration to make this work on a k8s environment.
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
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.
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?
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