/usr/lib/x86_64-linux-gnu/libLLVM-4.0.so.1: version `LLVM_4.0' not found - docker

I am trying to run a tool that uses Clang and LLVM. The tool name is cppgrep that is available with the docker. Please find it from the github repository - https://github.com/peter-can-talk/cppnow-2017. I have tried using Ubuntu 16.04 and 17.10, I got the same error as below:
root#522051d201d2:/home# ./cppgrep -help
./cppgrep: /usr/lib/x86_64-linux-gnu/libLLVM-4.0.so.1: version `LLVM_4.0' not found (required by ./cppgrep)
./cppgrep: /usr/lib/x86_64-linux-gnu/libclang-4.0.so.1: version `LLVM_4.0' not found (required by ./cppgrep)
root#522051d201d2:/home#
After some online search, I found that I had to setup the environment variable LD_LIBRARY_PATH. So as a first step I found the library files location in the docker, please find the output below:
root#522051d201d2:/home# find / -iname *libclang*.so*
/usr/lib/x86_64-linux-gnu/libclang-4.0.so
/usr/lib/x86_64-linux-gnu/libclang-4.0.so.1
/usr/lib/llvm-4.0/lib/libclang.so.1
/usr/lib/llvm-4.0/lib/libclang-4.0.so
/usr/lib/llvm-4.0/lib/libclang-4.0.0.so
/usr/lib/llvm-4.0/lib/libclang.so
/usr/lib/llvm-4.0/lib/libclang-4.0.so.1
/usr/lib/llvm-4.0/lib/clang/4.0.0/lib/linux/libclang_rt.dyndd-x86_64.so
/usr/lib/llvm-4.0/lib/clang/4.0.0/lib/linux/libclang_rt.asan-i686.so
/usr/lib/llvm-4.0/lib/clang/4.0.0/lib/linux/libclang_rt.asan-x86_64.so
/usr/lib/llvm-4.0/lib/clang/4.0.0/lib/linux/libclang_rt.asan-i386.so
After this step, I setup the LD_LIBRARY_PATH as follows:
root#522051d201d2:/home# echo $LD_LIBRARY_PATH
/usr/lib:/usr/lib/llvm-4.0/lib/:/usr/lib/x86_64-linux-gnu/
And lastly, I have exported it using the command export LD_LIBRARY_PATH. Now, if I try to run the cppgrep tool, I am still getting the same error. The command to test the tool after building the docker is as follows:
(1) cd into the cppgrep directory, like code/cppgrep,
(2) enter the docker container and mount the folder under /home:
$ docker run -it -v $PWD:/home clang
(3) run cppgrep using ./cppgrep 'x' test.cpp command.
It is suppossed to return functions and variables that has name x.
To replicate the error, after downloading and unzipping the file from github repository, build the docker container using $ docker build -t clang . command. Then follow 1,2,3 steps in the above paragraph.

After couple of days struggle, solved it!!
My initial assumption about the reason for the error is correct. The clang-llvm environment was not available to the cppgrep tool, but I made the mistake in the way of providing the environment information to the cppgrep tool.
The answer has two steps: (1) change the Makefile to point the correct location where you have installed the llvm, in my case, I change the following line in Makefile from HEADERS := -isystem /llvm/include/ to HEADERS := -isystem /usr/lib/llvm-4.0/include/. (2) You have to compile the file again by using the make command, just enter an empty space and save the cppgrep.cpp file before giving the command, otherwise, you will get a message as make: Nothing to be done for 'all'..
That is it, now you should be able to run the cppgrep tool by running ./cppgrep 'x' test.cpp or ./cppgrep -help. For using the other tools in this docker such as ast-dump, mccabe, etc. you have to follow the same above two steps before using them.

Related

container_run_and_commit_layer fails with: docker not found

I have a problem when running container_run_and_commit_layer, the error message I get is
docker not found; do you need to manually configure the docker toolchain?
from what I see this is related to DOCKER variable not set:
# Resolve the docker tool path
DOCKER=""
DOCKER_FLAGS=""
if [[ -z "$DOCKER" ]]; then
echo >&2 "error: docker not found; do you need to manually configure the docker toolchain?"
exit 1
fi
I'm calling container_repositories() in my workspace file, am I missing something?
That rule requires Docker to be installed. By default, it expects to find docker via $PATH. When it doesn't, you get that error.
The Setup section of the rules_docker documentation lists all the optional tools, and shows how to set custom paths to them. Some of the rules_docker rules don't need any of those, so they'll work fine. The rules which do need those tools give errors like this when run when the given tools aren't installed.
If you install docker now, you might have to bazel clean --expunge after installing it to ensure the repository rule is evaluated again.

Jenkins cannot find g++

I am learning all of these new technologies. I have a home server for private development with latest version of centos 7.6 (minimal installation). I am trying to keep the server as light as possible.
I have installed jenkins (v2.164.2) and it is up and running correctly. I have created a new Freestyle project to compile a g++ project hosted on another own gogs server. I have defined gogs url and credentials and then added the following in the execute shell command:
which g++; make clean; make;
When I press the "Build Now" button, it fails with the following message:
which: no g++ in (/sbin:/usr/sbin:/bin:/usr/bin)
Cloning the repository, etc seems to be working fine.
I have NOT installed the default g++ version but instead I have installed the one that comes with devtools-7 (g++ v7.3.1). I have created a new file under /etc/profile.d/devtools.sh with the following text:
!#/bin/bash
source scl_source enable devtoolset-7
If I login into a bash shell in the server and then run which g++, I get the expected output.
Finally, the question: why jenkins is not picking this up? As far as I know, adding that file under /etc/profile.d ensures that everyone will be able to access g++.
Thanks very much in advance for any help.
I have managed to fix it at the end. I leave the question just in case someone else runs into the same problem. I only had to add the following line as first line in the "execute shell" command field:
#!/bin/bash -l
make clean; make;
That #!/bin/bash -l did the trick. (Please mind the -l).
Found it here: What shell does Jenkins use?

NodeMCU Build in Docker results in "exec format error"

I'm trying the NodeMCU Docker build in Ubuntu 16.04.4 LTS for the first time.
I have read the tagged articles here for Docker and NodeMCU, but don't see this particular error.
"docker run hello-world" has no problems.
I have tried the NodeMCU build command in both forms:
$ docker run --rm -ti -v `pwd`:/opt/nodemcu-firmware marcelstoer/nodemcu-build
and the explicit path variation:
$ docker run --rm -it -v /home/tim/nodemcu-firmware:/opt/nodemcu-firmware marcelstoer/nodemcu-build
In both cases, I get this error:
standard_init_linux.go:187: exec user process caused "exec format error"
I have searched on this error, and most solutions are related to a missing shebang.
However, I'm not sure what script would need the shebang, or why it would be not working in my case but correct for others.
Has anyone else run across this error?
Speaking without deep technical details, this error means that the kernel can not recognize the format of the executable file, thus, it can not run this file. In your case this error is about the executable file which is started when the container is launched. According to the Cmd entry in the output of docker inspect marcelstoer/nodemcu-build, it is a file /bin/sh, which is an ELF executable.
When Linux can not execute ELF binary and returns such an error (about the file format), it usually is related to the system architecture. More specifically, the image marcelstoer/nodemcu-build contains ELF64 executables (i.e. for amd64 architecture), and your system does not support it (is it i386 or even some flavor of arm?). Running docker run hello-world, however, works fine for you, because hello-world image exists for all architectures supported by Docker.
According to the Dockerfile of marcelstoer/nodemcu-build image, it is built from ubuntu, which exists for different architectures, thus, you may try building the marcelstoer/nodemcu-build image on your system rather than pulling it from the dockerhub.
P.S.: regarding the solution you have linked to your question. This is not about your case (ELF binary), rather it is about a script. In case of script, the executable format is recognized by the shebang (#!) at the very beginning of the file, thus, the script must start with #!, not with the newline. That's why the author got the same error: the kernel could not detect that this is a script and failed to start it. Different (but similar) reasons, same error.

Dockerd with Chocolatey

I am using Chocolatey to install Docker.
When I originally run the following command:
choco install docker
and try to run the "docker --version" command, everything goes as expected.
Docker version 17.10.0-ce, build f4ffd25
When I try to run "dockerd" command, it shows as not being part of my path.
'dockerd' is not recognized as an internal or external command,
Looking at the PATH variable, and navigating to where Chocolatey stores the executables, dockerd.exe is not present while docker.exe is. Am I missing something in instructing Chocolatey in adding dockerd?
The reason I need the dockerd executable is so that I can limit the number of concurrent downloads, as shown in the Docker documentation.
This is a decision that the package maintainer(s) for Docker have made. If you have a look here:
https://chocolatey.org/packages/docker#files
You will see that there is a dockerd.exe.ignore file. This file is used to instruct Chocolatey to explicitly not create what is referred to as a shim file, which would make it work from the command line, in the same way as Docker does.
My best suggestion would be to reach out to the maintainers of that package to ask them why this was done, and to perhaps get it changed. You can do this by clicking on the Contact Maintainers link on this page:
https://chocolatey.org/packages/docker
As a workaround, you could add the following path to your Windows PATH environment variable:
C:\ProgramData\chocolatey\lib\docker\tools\docker
Which would allow it to work.

`docker-credential-gcloud` not in system PATH

After the latest updates to gcloud and docker I'm unable to access images on my google container repository. Locally when I run: gcloud auth configure-docker as per the instructions after updating gcloud, I get the following message:
WARNING: `docker-credential-gcloud` not in system PATH.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.
gcloud credential helpers already registered correctly.
Running which docker-credential-gcloud returns docker-credential-gcloud not found.
I have no other gcloud-related path issues and for the life of me can't figure out how to install/add docker-credential-gcloud to path. Here's what I have installed (shown via gcloud version):
Google Cloud SDK 197.0.0
beta 2017.09.15
bq 2.0.31
container-builder-local
core 2018.04.06
docker-credential-gcr
gsutil 4.30
I also have Docker CE Version 18.03.0-ce-mac60 (23751).
Here's my $PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I also ran source /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc on original gcloud install.
Notice: All docker-credential-gcr below can be replaced with docker-credential-gcloud. I think it is just different versions of gcloud, I might be wrong.
I used Homebrew Cask to install gcloud too. I installed docker-credential-gcr with
$ gcloud components install docker-credential-gcr
And then like you said, which docker-credential-gcr doesn't gave you anything.
So I ran which gcloud to find there is a symlink to gcloud in /usr/local/bin. This symlink is created by Homebrew when you installed gcloud at first place. Now docker-credential-gcr wasn't installed by Homebrew but by gcloud itself, so there isn't a symlink.
I called readlink /usr/local/bin/gcloud and found out gcloud is installed in /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/.
Then:
$ ls /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin
There you should see docker-credential-gcr listed there.
I simply linked it to /usr/local/bin:
$ ln -s \
/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/docker-credential-gcr \
/usr/local/bin/
Then run:
$ docker-credential-gcr configure-docker
It should succeed.
Just had the same issue on Windows, running Docker with Linux containers, Docker engine v19.03.8. Using docker compose. I do not use gcloud for my dockerfiles...
DT1001 dockerpycreds.errors.InitializationError:
docker-credential-gcloud not installed or not available in PATH
Option 1: Edit the docker configuration file and remove all gcloud entries from there.
Windows c:/Users/<your account>/.docker/config.json
Linux & MacOS ~/.docker/config.json
Option 2: Go to Troubleshoot -> Reset to factory defaults.
After this my docker compose was creating containers and running the images without any issues.
On MacOS
Step 1:
Install gcloud and docker-credential-gcr,
following this tutorial
Step 2:
$ ln -s /usr/local/google-cloud-sdk/bin/docker-credential-gcr /usr/local/bin/docker-credential-gcloud
Step 3:
$ rm -rf ~/.docker
Step 4:
$ docker-compose build --pull
Finished!
Never found a way to directly resolve the docker-credential-gcloud issue, but the following got me up and running again. WARNING: the following will delete all your existing docker images and install a bunch of gcloud utilities:
gcloud components install docker-credential-gcr,
Restart the terminal completely
docker-credential-gcr configure-docker.
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
umount /var/lib/docker/overlay2
rm -rf /var/lib/docker
Restart the terminal completely.
The new version of google-cloud-sdk has only docker-credential-gcr but not docker-credential-gcloud anymore. On the other hand one of my python packages always requested docker-credential-gcloud.
The solution was to symlink docker-credential-gcloud to docker-credential-gcr:
ln -s /path/to/google-cloud-sdk/bin/docker-credential-gcr /usr/local/bin/docker-credential-gcloud
ls -l /usr/local/bin | grep docker should now print:
...
docker-credential-gcloud -> /path/to/google-cloud-sdk/bin/docker-credential-gcr
...
Usually, this error indicates that your $PATH variable has been clobbered by a package or program you have recently installed so that the Google Cloud SDK can't be found.
$PATH is altered by many programs when they install by altering ~/.profile, ~/.bash_profile or ~/.bashrc or their non-bash equivalents. With a bad $PATH, Google Cloud SDK is configured in docker but can't be seen as executables so we get this error. This assumes you have used the Google Cloud SDK in the past, but if gcloud is configured with your docker then you probably have. Don't reinstall gcloud or disable it, you already have it on your system and that is fine.
The solution then is to fix your $PATH, not to install anything.
echo $PATH
This should be a pretty long : delimited list of directories that your files are in. Do you see a google-cloud-sdk/bin in the string? Is the string way too short given all the trouble you've gotten into in your life on this computer? You use NVM but it is missing? Use Homebrew but it is missing? Try brew from the command line, does it work?
If the answer is "no" to any of the above, inspect the files above to see if there are any new entries at the bottom of each that might have broken things. Did you just install anything new?
Something is clobbering your $PATH and you need to figure out what that is. For me it is usually something to do with Anaconda Python via the conda init command. For you it might be nvm or something else. Figure out what it is and fix the problem. Don't start over with a new $PATH and install the same stuff over again or disable gcloud authentication.
It really seems to be something with the Homebrew Cask. I uninstalled the cask and then reinstalled the Google Cloud SDK by manually downloading the tar ball and running the packaged install script as described there.
Now docker-credential-gcloud is in my path:
$ which docker-credential-gcloud
/Users/moritz/google-cloud-sdk/bin/docker-credential-gcloud
I can't figure out what Google is trying to achieve here. On Linux there is docker-credential-gcloud and on Windows there is docker-credential-gcr.exe, and then there is docker-credential-gcloud.cmd which calls gcloud auth docker-helper. This is kind of a nightmare if you're trying to write portable build scripts or gradle rules because not everything seems capable of finding and calling docker-credential-gcloud.cmd when you exec docker-credential-gcloud... it might work from the dos prompt, but in general doesn't work.
After a ton of fooling around with .bat scripts, cygwin scripts, .cmd scripts and so forth, I found the best solution was to go into the gcloud installation and just copy docker-credential-gcr.exe docker-credential-gcloud.exe ... not a very satisfying solution, but is the only thing I found that would do the trick.
I got the issue when I tried to SSH from Google Cloud Build into an Engine VM Instance, so I had
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['compute', 'ssh',
'--project', '$PROJECT_ID',
'--zone', 'asia-southeast1-b',
'--strict-host-key-checking=no',
'username#instance-1',
'--command' ,'sh start.sh'
My start.sh
#!/bin/sh
echo "Started: $(date --iso-8601=seconds)"
docker pull gcr.io/aaa/bbbc/cccc
echo "Finished: $(date --iso-8601=seconds)"
The issue was How to set PATH when running a ssh command?
https://unix.stackexchange.com/questions/332532/how-to-set-path-when-running-a-ssh-command
So I just faced the same problem where I am trying to pull an image from GCR to an GCP instance and want to share my solution.
I ran gcloud auth configure-docker and got the warning:
WARNING: `docker-credential-gcloud\` not in system PATH.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.
I applied the accepted answer for this thread and ran gcloud components install docker-credential-gcr and got a long error:
ERROR: (gcloud.components.install) You cannot perform this action because this Cloud SDK installation is managed by an external package manager.
Please consider using a separate installation of the Cloud SDK created through the default mechanism described at: https://cloud.google.com/sdk/
When no solution was working, I uninstalled the Google provided google-cloud-sdk package that was installed via snap and instlled with distro specifice package manager, for me that is apt-get as instructed in the Installing Google Cloud SDK: Installation options page and re-ran the gcloud auth configure-docker and this time it solved my problem.
In my case the problem was due to how WSL 1 works with Docker on Windows. At first I only installed and initialized gcloud in WSL Ubuntu, not in Windows. However as Docker daemon is actually run by Windows, you need to install gcloud for Windows as well (and don't forget to run all of the inits and authorizations there).
On Windows 10/11, you need to ensure that C:\Users\USERNAME\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\ is added to your system $PATH environment variable. It may not have been added if the Google Cloud SDK was not able to add it during GCloud installation. So add it manually like this:
Windows Task Bar ➔ Press the search icon 🔍 or the search bar
Type "environment" ➔ and click on "Edit the System Environment Variables" (ensure that you have Administrator access)
At the bottom of the dialog, click the Environment Variables... button
System Variables ➔ click Path ➔ Edit... ➔ New ➔ paste in C:\Users\USERNAME\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\ (replace "USERNAME" with your username)
Close and restart any open Command Prompt windows.
Then verify on the Git Bash for Windows console:
Optional: Note that the AppData folder is hidden by default, so you may want to unhide AppData first, to see its contents.
Restart the Git Bash Terminal window
echo $PATH ➔ This should print a long string that contains: :/c/Users/USERNAME/AppData/Local/Google/Cloud SDK/google-cloud-sdk/bin
where docker-credential-gcloud ➔ This should print C:\Users\USERNAME\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\docker-credential-gcloud.cmd

Resources