Search code examples
dockerfile-permissions

How to mount the volume of host to docker container with executable file permission using docker api


When I tried to create django docker container using remote api, I can bind the host volume to docker container volume. But when I use "Cmd" along with docker create, it showing an error(not for shell commands),

<Response [500]>
Cannot start container d07b316a1d790b67442a9a4ee49de6e6f2191e14d15ebd528d752b3fad63d9b1: exec: "pip install -r requirements.txt&& python manage.py runserver 0.0.0.0:8888": executable file not found in $PATH

This is my json input.

d = {
     "Hostname": "",
     "Domainname": "",
     "User": "",
     "Memory": 0,
     "MemorySwap": 0,
     "CpuShares": 512,
     "Cpuset": "0,1",
     "AttachStdin": True,
     "AttachStdout": True,
     "AttachStderr": True,
     "Tty": True,
     "OpenStdin": True,
     "StdinOnce": False,
     "Env": "[$PATH=/usr/local/bin]",
     "Cmd": [
             "pip install -r requirements.txt&& python manage.py runserver 0.0.0.0:8888"
     ],
     "Entrypoint": "",
     "Image": "django:python3",
     "Volumes": {
             "/usr/src/app": {},
     },
     "WorkingDir": "/usr/src/app",
     "NetworkDisabled": False,
     "MacAddress": mac_id,
     "ExposedPorts": {
             "8888/tcp": {}
     },
     "SecurityOpts": [""],
     "HostConfig": {
       "Binds": ["/home/user/Sample:usr/src/app"],
       "Links": [],
       "LxcConf": {"lxc.utsname":"docker"},
       "PortBindings": { "8888/tcp": [{ "HostPort": "8888" }] },
       "PublishAllPorts": False,
       "Privileged": False,
       "ReadonlyRootfs": False,
       "Dns": ["8.8.8.8"],
       "DnsSearch": [""],
       "ExtraHosts": '',
       "VolumesFrom": [],
       "CapAdd": ["NET_ADMIN"],
       "CapDrop": ["MKNOD"],
       "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 },
       "NetworkMode": "bridge",
       "Devices": []
    }
}

Using "docker run" command it works fine for me. How can I fix this issue.


Solution

  • I haven't used the remote API, but the problem is that you've passed it all as a single argument, so it's looking for a file called "pip install -r requirements.txt&& python manage.py runserver 0.0.0.0:8888".

    You need to figure out how to pass the arguments separately, and you may need to give an absolute path to pip.