I have a dockerfile looking like this :
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
ADD . /app
CMD python script.py
(requirements.txt contains "black").
I would like to run black on script.py before running script.py, so that script.py get formatted correctly when the container starts. I dont understand how I am supposed to do this, knowing that I cant use CMD twice . I feel like I'm missing how docker is supposed to be used.
CodePudding user response:
Additionally try not to use ADD, COPY is almost always better, use ADD only if you are copying files from link or copying compressed files.
CodePudding user response:
Solution is here. In my case, it is :
Dockerfile:
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
ADD . /app
ADD start.sh /
RUN chmod x /start.sh
CMD ["/start.sh"]
start.sh:
#!/bin/bash
black script.py
python script.py