python docker api how do we set the path environment variable? - docker

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",

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"}.

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

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.

Related

What is the use of %include docker file?

I am having a docker file which has following line in it
%include=../doxygen
If i try to run the docker command using this docker file, it gives me error
unknown instruction: %INCLUDE=../DOXYGEN
what is the purpose of %include in dockerfile?
is there anything that in need to pass in docker command to make it run?

docker-compose on ubntu 18.10 the input device is not a TTY error

I installed docker and docker compose in ubuntu 18.10 server, when i execute the command docker compose from terminal it is working, but when i configure a crontab to exexute a command with docker compose, i get this error :"The USER variable is not set. Defaulting to a blank string.the input device is not a TTY"
The USER error is related to an error with docker-compose.yml, juste for using ${USER}.
How can i fix the issue ?
PS: It was working normaly in ubuntu 18.04 server.
The cron daemon was designed in such a way that it does NOT execute commands within your normal shell environment. This means you cannot use bare commands in cron the way you would from the SSH shell command line. This is because the PATH environment variable is /usr/bin:/bin, and the SHELL environment variable is set to /bin/sh.
Something you can reference: here and here.
So you may have to specify shell environment variable directly in crontab, like
USER=xxx
* * * * * /bin/echo ${USER}

Detect Docker runtime on host using environment variables

I would like to run tests verifying the correct execution of Flyway migrations using TestContainers.
Using JUnit5, I would like to enable these tests only on a host that have a Docker daemon running (#EnabledIfSystemProperty(named = "docker...", matches = "")) https://junit.org/junit5/docs/current/user-guide/#writing-tests-conditional-execution-system-properties.
My question is: how can I check that a Docker daemon is available on host using environment variables?
PS: I don't have any access to the CI host.
If you can run bash before that, you can run :
export IS_DOCKER_RUNNING =`cat /var/run/docker.pid`
and check if the environment variable is empty or contain an id.
There are several variables involved with this ("does the calling user have permissions" is an important check; "is the Docker I have access to actually local" is another interesting question) and there isn't going to be a magic environment variable that tells you this.
I'd probably try running a throwaway container; something along the lines of
docker run --rm busybox /bin/true
and if it succeeds move forward with other Docker-based end-to-end tests.
Building on #NinaHashemi's answer, if it must be an environment variable, and you can run a shell script before/around your tests (any POSIX shell, not necessarily bash) then you can run
if docker run --rm busybox /bin/true >/dev/null 2>&1; then
export IS_DOCKER_RUNNING=yes
fi

Docker commands fail in Cygwin -- Docker service is up

I'm trying to login to my AWS account with a docker loginstring from aws ecr get-login --region eu-west-1 -- however, when I do, I get this:
Warning: failed to get default registry endpoint from daemon (error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.26/info: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.). Using system default: https://index.docker.io/v1/
error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.26/auth: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running
The peculiar thing is this was just working last week. I'm using Cygwin on Windows 10. I've verified that Docker is running in services.msc -- I'm not entirely sure what to check now.
If you want to run docker commands in cygwin on Windows 10, then call the following command from cygwin:
docker-machine env --shell=bash
It will show the environment variables needed by docker:
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.xx.xx:2376"
export DOCKER_CERT_PATH="C:\Users\...\machines\default"
export DOCKER_MACHINE_NAME="default"
export COMPOSE_CONVERT_WINDOWS_PATHS="true"
# Run this command to configure your shell:
# eval $(docker-machine env --shell=bash)
Run the following command to set the environment variables:
eval $(docker-machine env --shell=bash)
It looks like you are trying to open a pipe to the service by passing a windows pipe path to cygwin. It gets interpreted as an http path by cygwin.
This is probably happening because the docker command finds the cygwin python before it finds the windows python. There are several solutions. The simplest is to switch back to a windows context to execute the docker command. If docker is actually docker.bat then start it with cmd.exe /c docker.bat otherwise cmd.exe /c docker.exe. You may also try cmd.exe /c start /w /i docker.bat. Or some variation.
You do not want to execute any docker command directly in cygwin as it will likely not know how to translate between windows paths and the linux paths it expects.

Where is jenkins.xml in jenkins docker container

We are using jenkins inside docker (version: FROM jenkins:1.651.1).
We have problems with the html publisher plugin which isn't executing javascript by default. The same issue as described here.
We want to change our jenkins.xml (just like they said) to change it's configuration. The problem is the fact we can't find it inside our container. Does it has another name inside the docker container or where can we find it? Thanks
The jenkins docker image does not contain a jenkins.xml. This looks to be a windows specific file.
$ docker run --rm jenkins find / -name 'jenkins.xml' 2>/dev/null
# returns nothing
/usr/local/bin/jenkins.sh is run when a jenkins container is started. This contains the line:
eval "exec java $JAVA_OPTS -jar /usr/share/jenkins/jenkins.war $JENKINS_OPTS \"\$#\""
Therefore try setting the required setting in JENKINS_OPTS:
docker run -e JENKINS_OPTS="hudson.model.DirectoryBrowserSupport.CSP=" jenkins

Resources