docker / docker/docker-py

Not able to run docker container with mount

Open
#2,914 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

Hello,

I am trying to write a python program to run a third party docker image using docker-py. Unfortunately, I am not able to run the third-party program successfully.

I am trying to implement the program using the following:

  • Python 3.6
  • docker==5.0.3

Following is the docker command I am trying to mimic with docker-py:

docker run --rm --user root -v /host/dir:/container_dir quay.io/biocontainers/ensembl-vep:104.3--pl5262h4a94de4_0 /bin/bash -c "variant_recoder --input_file /container_dir/test_input.txt --pretty --species homo_sapiens > /container_dir/test_output.json"
import docker

client = docker.from_env()

working_dir = "/home/user/downloads/"
container_dir = "/data"
input_file = "test_input.txt"
output_file = "tes_toutput.json"

container = client.containers.run(image="quay.io/biocontainers/ensembl-vep:104.3--pl5262h4a94de4_0",
                            command=["variant_recoder", "--input_file", input_file, "--pretty", "--species", "homo_sapiens", ">", output_file],
                            volumes={working_dir: {"bind":container_dir, "mode": "rw"}},
                            user="root",
                            remove=True
                           )
print(container)

Following is the error I am experiencing when running the above python script. I believe the mounting of the directory is not happening and because of that, the program is not able to read the file.

Error log:

docker.errors.ContainerError: Command '['variant_recoder', '--input_file', '/data/test_vep_test_input.txt', '--pretty', '--species', 'homo_sapiens', '>', '/data/docker_vep_recoder_output.json']' in image 'quay.io/biocontainers/ensembl-vep:104.3--pl5262h4a94de4_0' returned non-zero exit status 2: b'Possible precedence issue with control flow operator at /usr/local/lib/site_perl/5.26.2/Bio/DB/IndexedBase.pm line 805.\n\n-------------------- EXCEPTION --------------------\nMSG: ERROR: File "/data/test_vep_test_input.txt" does not exist\n\nSTACK Bio::EnsEMBL::VEP::Parser::file /usr/local/share/ensembl-vep-104.3-0/modules/Bio/EnsEMBL/VEP/Parser.pm:231\nSTACK Bio::EnsEMBL::VEP::Parser::new /usr/local/share/ensembl-vep-104.3-0/modules/Bio/EnsEMBL/VEP/Parser.pm:125\nSTACK Bio::EnsEMBL::VEP::Runner::get_Parser /usr/local/share/ensembl-vep-104.3-0/modules/Bio/EnsEMBL/VEP/Runner.pm:801\nSTACK Bio::EnsEMBL::VEP::Runner::get_InputBuffer /usr/local/share/ensembl-vep-104.3-0/modules/Bio/EnsEMBL/VEP/Runner.pm:828\nSTACK Bio::EnsEMBL::VEP::Runner::init /usr/local/share/ensembl-vep-104.3-0/modules/Bio/EnsEMBL/VEP/Runner.pm:136\nSTACK Bio::EnsEMBL::VEP::VariantRecoder::init /usr/local/share/ensembl-vep-104.3-0/modules/Bio/EnsEMBL/VEP/VariantRecoder.pm:160\nSTACK Bio::EnsEMBL::VEP::VariantRecoder::recode_all /usr/local/share/ensembl-vep-104.3-0/modules/Bio/EnsEMBL/VEP/VariantRecoder.pm:182\nSTACK main::main /usr/local/bin/variant_recoder:104\nSTACK toplevel /usr/local/bin/variant_recoder:97\nDate (localtime)    = Wed Nov 17 21:17:41 2021\nEnsembl API version = 104\n---------------------------------------------------\n'

If anyone can point out what am I doing wrong, I would greatly appreciate the help.

Thank you.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at client.containers.run and compare its command and volumes arguments with the documented docker-py behavior for the equivalent Docker command. Reproduce the reported container invocation and determine whether the failure comes from mounting the host path or from passing shell redirection as a command argument; done means identifying a confirmed library issue or documenting the correct invocation.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.