TVG
TVG

Reputation: 422

How to add relative paths and how to mount volumes in a container with Podman

I'd like to build a container using Podman which would contains the following:

To do that, I've added a Dockerfile in my home directory. I had to put the Dockerfile at a such high path level because it seems that it needs to be above any folder I want to add in the container. Indeed, I've tried to add folders using rising path with "../../some/path/" but it doesn't work. Then, a first question is: Is there a solution to add folders which are not below (in path) the Dockerfile?

Below is the content of the Dockerfile:

FROM python:3

# Add the Python application
ADD /path/to/my_python_app /my_python_app

# Add the Python modules used by the Python application
ADD /path/to/my_modules /my_modules

# Add the whole mambaforge folder (contains the virtual envs) with the exact same path than the local one
ADD /path/to/mambaforge /exact/same/path/to/mambaforge

# Create a customized .bashrc (contains 'export PATH' to add mamba path and 'export PYTHONPATH' to add my_modules path)
ADD Dockerfile_bashrc /root/.bashrc

Then, I build the container with:

podman build -t python_app .

And run it with:

podman run -i -t python_app -v /path/to/input/data:/mnt/input -v /path/to/output/data:/mnt/output /bin/bash

The container runs correctly and I can execute my Python application into. However, the volumes do not appear in /mnt. A second question is: How to mount volumes in a container? I've tried with '--volume' and '--mount', with '/path/to/input/data:/mnt/input:z' and '/path/to/input/data:/mnt/input:Z', but nothing works.

Many thanks for your help!

Upvotes: 1

Views: 1629

Answers (1)

TVG
TVG

Reputation: 422

Solutions were given in comments. Here is a summary:

Is there a solution to add folders which are not below (in path) the Dockerfile? No, not allowing ADD ../some/path/ is due to security reasons.

How to mount volumes in a container? The order of the arguments was not correct. The option -v needs to come before the image name. The following command works fine:

podman run -i -t -v /path/to/input/data:/mnt/input -v /path/to/output/data:/mnt/output python_app /bin/bash

Upvotes: 1

Related Questions