amazon-web-servicesdockerdockerfileamazon-ecsamazon-ecr

How to add --init parameter to AWS ECS Task


I have a Docker image that uses Playwright and xvfb. When I run it locally, I run docker run --init -it <image_id> (per this SO answer). Without the --init param, the container will run but will not execute the entrypoint, instead the container just hangs without error.

I am trying to get this to run in AWS ECS using Fargate, but I need to tell the ECS Task Definition to run the container with the --init param. I know there is a "Docker configuration" section in the task definition but I don't know the actual syntax to add this param there or if I should add this param in my Dockerfile (which I also don't know how to do)

Dockerfile:

FROM python:3.10.7
RUN apt-get clean && apt-get update
ENV PYTHONDONTWRITEBYTECODE=1
ENV PLAYWRIGHT_BROWSERS_PATH=/app/ms-playwright
ENV PYTHONUNBUFFERED=1
WORKDIR /test-repo
COPY . .
RUN pip install playwright
RUN pip install -r requirements.txt
# install manually all the missing libraries
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils xvfb
RUN PLAYWRIGHT_BROWSERS_PATH=/app/ms-playwright playwright install --with-deps chromium
ENTRYPOINT ["xvfb-run", "--auto-servernum", "--server-num=1", "python3", "main.py"]

Solution

  • Yes you can configure this at the task definition level with initProcessEnabled:

    Run an init process inside the container that forwards signals and reaps processes. This parameter maps to the --init option to docker run.