1
votes

I am trying to set the PATH environment variable inside the container using python docker api but doesnt seems to work , the container is not starting

does anybody has idea how to set the PATH env variable, other env variables works file.

I am seeing the below error OCI runtime exec failed: exec failed: container_linux.go:344: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown

(exitCode, socConn) = self.container.exec_run('bash -e build/otin/BashCheckGCCVersion.sh',socket=True,environment=["PATH=/usr/lib64/ccache"]) 

 or


 environment=[
        "CCACHE_DIR=/work/.ccache",
        "PATH=/usr/lib64/ccache",
        "BUILDS_ALL_TIME=" + sys.argv[2],
        "PATCH_10.2=" + sys.argv[1]],
    working_dir="/OTINBuild",
3
That sounds like setting the environment variable is working fine, but the only container path being searched for any binaries at all is /usr/lib64/ccache and there's not a bash binary in that single directory. (If you want /bin to be searched it needs to be in $PATH too.) - David Maze
As @DavidMaze mentioned it could be incorrect path / the path doesnt exist , check the docker logs (or) login into the newly created container and verify the path exist using basic commands ls -l yourpath and also verify whether other Environment variables are set or not. - Senthil

3 Answers

0
votes

please share the api details (or) the python script full details - here its minimal includes your docker file (docker build cmd) .Refer below for the syntax and whether you are trying to override the environment variables set by the docker image build process ?

Ref: https://docker-py.readthedocs.io/en/stable/api.html

exec_create(container, cmd, stdout=True, stderr=True, stdin=False, tty=False, privileged=False, user='', environment=None, workdir=None, detach_keys=None)


environment (dict or list) – A dictionary or a list of strings in the following format ["PASSWORD=xxx"] or {"PASSWORD": "xxx"}.
0
votes

Does the docker image has bash command. Try other generic command like sh, ls instead of bash.

0
votes

If you use the dictionary to set up your environment variable it will work like this:

environment = {"Name_Variable":"Name_Path","Name_Variable2":"Name_Path2"...}
(exitCode, socConn) = self.container.exec_run('bash -e build/otin/BashCheckGCCVersion.sh',socket=True,environment=environment)

If you try to see if it work with the following command :

docker exec -it "Name_Container" echo $Name_Variable

It won't show you the value.

The terminal is executing the $Name_Variable, before "sending" it to docker.

You have to enter in your container using the bash and do echo $Name_Variable.