Reputation: 2125
I pull a docker image and when I run it, I realized that one of the python libraries is an old version.
Can I create a Dockerfile by building on top on this existing image and then upgrade that library to latest version ?
What will be the Dockfile ?
Upvotes: 0
Views: 2273
Reputation: 355
You can upgrade an existing Docker Image using a Dockerfile
.
Create a file called requirements.txt
and on each line put the name of the packages you wish to upgrade, even if it's just the one:
Flask
gunicorn
Pillow
Then create another file called Dockerfile
with no extension in the same directory:
FROM python:3.8
COPY ./requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt
You can generate a Docker Image from this by using the command:
docker build --rm --no-cache --tag <tag>:<version> .
Replace <tag>
with your new Docker Image name, and replace <version>
with the version you want to assign it. If you are calling the Docker Image koaystCustomPyTool
and want to omit the version, write the command like this:
docker build --rm --no-cache --tag koaystCustomPyTool .
Now when you run docker images
you will see an output similar to this:
REPOSITORY TAG IMAGE ID CREATED SIZE
koaystCustomPyTool latest 536d44c69a88 1 minute ago 275MB
If you need to provide a custom command to execute the Docker Image when you run it, add a line at the end of the Dockerfile like this:
CMD ["gunicorn", "-w", "2", "-b", ":8080", "poker.main:app"]
Here I have separated each command into it's own string value surrounded by double quotes "
and wraped in square brackets [
and ]
.
Upvotes: 2