Reputation: 51
I am trying to put a python program in a container. The program requires a config file to be in /etc/cdr_arhive.conf
.
I create the container with a mapped volume based on how I found other people do it folloing blogs and posts. It however does not work with any combination of options I have tried.
The Dockerfile:
FROM python:3.11
RUN groupadd -g 1000 python && \
useradd -r -u 1000 -g python python
COPY ../requirements.txt .
RUN pip install -r requirements.txt
RUN mkdir /app && chown python:python /app
WORKDIR /app
COPY main.py minio_controller.py mysqldump.py storage_controller.py db-checks.py .
RUN mkdir util
COPY util/ util/
USER 1000
CMD ["python"]
Building and creating the container:
johan@kompir ~/P/cdr-archiver (master)> podman build -t cdrarchiver .
STEP 1/11: FROM python:3.11
STEP 2/11: RUN groupadd -g 1000 python && useradd -r -u 1000 -g python python
--> Using cache 9f36ca3676187e5b58180cd124c37c246ae6ee41fcf4163850635b7f55813dd5
--> 9f36ca36761
STEP 3/11: COPY ../requirements.txt .
--> Using cache 33e56da82582af392371e3af89abd757ecf55bf4bbeb8beafbbd88e27c5fb6b3
--> 33e56da8258
STEP 4/11: RUN pip install -r requirements.txt
--> Using cache 08c45ba7ab9157ea2bc576f5b2405378f71917a089f4a2b35a9e4d8b85012835
--> 08c45ba7ab9
STEP 5/11: RUN mkdir /app && chown python:python /app
--> Using cache 58620616aa86938ebe43c3e46a9c0e929f94b36f771e7b11ed0847fd5b522afd
--> 58620616aa8
STEP 6/11: WORKDIR /app
--> Using cache 8b11db9a1afcda370b8aef5e2cfb8d6e291eabf688754340964ba17814f7f857
--> 8b11db9a1af
STEP 7/11: COPY main.py minio_controller.py mysqldump.py storage_controller.py db-checks.py .
--> 2db0b02eee9
STEP 8/11: RUN mkdir util
--> ba4ff005421
STEP 9/11: COPY util/ util/
--> 6ba25a873e3
STEP 10/11: USER 1000
--> 6bc9cd1ef9f
STEP 11/11: CMD ["python"]
COMMIT cdrarchiver
--> c14101cdda0
Successfully tagged localhost/cdrarchiver:latest
c14101cdda0cb476b4868e514f32cc496a2ba8e743fa6ff7bf51baf49bd1232b
Getting the working config file to be visible inside the container:
johan@kompir ~/P/cdr-archiver (master)> cp /etc/cdr_archive.conf .
johan@kompir ~/P/cdr-archiver (master) [1]> ls -l cdr_archive.conf
-rw-r--r-- 1 johan johan 561 Apr 29 08:06 cdr_archive.conf
johan@kompir ~/P/cdr-archiver (master)> podman create --name cdr_archiver -v $PWD/cdr_archive.conf:/etc/cdr_archive.conf cdrarchiver
c78baa6b74fdce5ace5803e4931374ee39a7a23101cd325cc2a953ceeeb5031f
When trying to run the program I get a Python exception saying that the config file could not be read (Expected behavior when the config file is missing).
When I check it with podman exec I can confirm that the file is not there:
johan@kompir ~/P/cdr-archiver (master)> podman run -i -t localhost/cdrarchiver ls -l /etc/cdr_archive.conf
ls: cannot access '/etc/cdr_archive.conf': No such file or directory
For what it is worth, the container is created on Fedora 39, using podman 3.4.2. The one thing I have not yet tried is to run it as root, but even if it works that is not an acceptable solution.
Any idea what I am doing wrong?
Basically I have tried to get a file mapped into a podman container. There is no error, but the file is not seen in the container.
Upvotes: 1
Views: 281
Reputation: 51
The solution is to use
podman run -ti -v /path/to/file:/path/to/file localhost/imagename
This is because podman run
creates a new container and ignores any mapped volumes used on prior podman create
commands.
Note ':Z' to map SElinux contexts may be needed depending on your operating system, as hinted by @mattdm.
Upvotes: 2