my project is using playwright-python and my team has been unable to run playwright in a docker container. We are able to build the docker image successfully, but problems arise when the image is running. May I obtain some guidance on how to tackle this issue?
We are using Ubuntu 20.04 Focal, so it is not a version issue.
Here is the configuration of our Dockerfile.
# syntax=docker/dockerfile:1
FROM python:3.8
#ENV PATH=.envScriptsActivate.ps1
WORKDIR /code
#RUN which python3
COPY ./requirement.txt /code/requirement.txt
#RUN set -xe
# && apt-get update -y
# && apt-get install - y python3-pip
#RUN pip3 install -r requirement.txt
RUN set -xe
RUN apt-get upgrade -y
RUN apt-get update
#RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get install -y python3 pip
#RUN python3 --version
RUN pip3 install --no-cache-dir --upgrade -r /code/requirement.txt
COPY ./ /code/server
RUN playwright install
RUN playwright install-deps
RUN ls -al
SHELL ["/bin/bash", "-c", "source /code/server/env/bin/activate && pip3 install --upgrade -r /code/requirement.txt"]
CMD ["python3", "-m", "uvicorn", "server.main:app", "--port", "9900", "--host", "0.0.0.0"]
Here is the error we are getting:
╔════════════════════════════════════════════════════════════╗
║ Host system is missing a few dependencies to run browsers. ║
║ Please install them with the following command: ║
║ ║
║ playwright install-deps ║
║ ║
║ <3 Playwright Team ║
╚════════════════════════════════════════════════════════════╝ File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 61, in app
response = await func(request)
File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 226, in app
raw_response = await run_endpoint_function(
File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 159, in run_endpoint_function
return await dependant.call(**values)
File "/Project-Scrapee/./server/multiproxy/route.py", line 35, in refresh_proxy_list
await crud.refresh_proxy_list()
File "/Project-Scrapee/./server/multiproxy/crud.py", line 65, in refresh_proxy_list
await scheduler_crud.refresh_proxy()
File "/Project-Scrapee/./server/scheduler.py", line 640, in refresh_proxy
await multiproxy_crud.scrape_proxies()
File "/Project-Scrapee/./server/multiproxy/crud.py", line 77, in scrape_proxies
page = await page_gen.anext()
File "/Project-Scrapee/./server/template/crud.py", line 785, in get_pw_page
browser = await p.chromium.launch(
File "/usr/local/lib/python3.9/site-packages/playwright/async_api/_generated.py", line 11602, in launch
await self._async(
File "/usr/local/lib/python3.9/site-packages/playwright/_impl/_async_base.py", line 68, in _async
setattr(task, "pw_stack_trace", traceback.extract_stack())
We have tried many ways to install playwright but we can’t get to install playwright in the image.
2
Answers
This was an existing issue that was fixed in some earlier release. It shouldn’t be happening now. As suggested in this thread, can you try installing
libxtst6
using this commandRUN apt-get install -y python3 pip && apt install libxtst6
and then try with the docker imageI was NOT able to install Playwright dependencies starting from a Python base image (ie
FROM python:3.9
), the only way to get it working was to use an Ubuntu base image which is supported OS by Playwright, then install Python and the rest (application dependencies and Playwright)