Check npm version in Docker - docker

I have built an image with Dockerfile, it looks like this:
FROM node:12.18.1
USER root
RUN apt-get -y update
RUN apt-get -y install curl
RUN npm install
ENTRYPOINT ["curl"]
Now I can see that curl is installed, but how can I check on Node?
Every time I am trying to see the version I get an error:
'node'/'npm' is not recognized as an internal or external command,
I also tried this:
docker run -it --rm node /bin/bash -c 'node --version'
but ended up with this:
--version': -c: line 1: unexpected EOF while looking for matching `''
--version': -c: line 2: syntax error: unexpected end of file

Related

Is there any way to run "pkexec" from a docker container?

I am trying to set up a Docker image (my Dockerfile is available here, sorry for the french README: https://framagit.org/Gwendal/firefox-icedtea-docker) with an old version of Firefox and an old version of Java to run an old Java applet to start a VPN. My image does work and successfully allows me to start the Java applet in Firefox.
Unfortunately, the said applet then tries to run the following command in the container (I've simply removed the --config part from the command as it does not matter here):
INFO: launching '/usr/bin/pkexec sh -c /usr/sbin/openvpn --config ...'
Then the applet exits silently with an error. While investigating, I've tried running a command with pkexec with the same Docker image, and it gives me this result:
$ sudo docker-compose run firefox pkexec /firefox/firefox-sdk/bin/firefox-bin -new-instance
**
ERROR:pkexec.c:719:main: assertion failed: (polkit_unix_process_get_start_time (POLKIT_UNIX_PROCESS (subject)) > 0)
But I don't know polkit at all and cannot understand this error.
EDIT: A more minimal way to reproduce the problem is with this Dockerfile:
FROM ubuntu:16.04
RUN apt-get update \
&& apt-get install -y policykit-1
And then run:
$ sudo docker build -t pkexec-test .
$ sudo docker run pkexec-test pkexec echo Hello
Which leads here again to:
ERROR:pkexec.c:719:main: assertion failed: (polkit_unix_process_get_start_time (POLKIT_UNIX_PROCESS (subject)) > 0)
Should I conclude that pkexec cannot work in a docker container? Or is there any way to make this command work?
Sidenote: I have no control whatsoever on the Java applet that I try to run, it is a horrible and very dated proprietary black box that I am supposed to use at work, for which I have no access to the source code, and that I must use as is.
I have solved my own problem by replacing pkexec by sudo in the docker image, and by allowing passwordless sudo.
Given an ubuntu docker image where a user called developer was created and configured with a USER statement, add these lines:
# Install sudo and make 'developer' a passwordless sudoer
RUN apt-get install sudo
ADD ./developersudo /etc/sudoers.d/developersudo
# Replacing pkexec by sudo
RUN rm /usr/bin/pkexec
RUN ln -s /usr/bin/sudo /usr/bin/pkexec
with the file developersudo containing:
developer ALL=(ALL) NOPASSWD:ALL
This replaces any call to pkexec made in a process running in the container, by a call to sudo without any password prompt, which works nicely.

"dockerfile" text file busy

I want to create a project from dockerfile. Firstly, I should clone a framework from github and install it.
In my Dockerfile I have the following instrutions:
RUN git clone https://github.com/simgrid/project.git
WORKDIR "/project"
RUN cmake option1 options2 .
RUN sudo make
RUN sudo make install
I build image with:
docker build -t "myimage" .
But I have an error about text file busy. How can I overcome it?
make[2]: execvp: /simgrid/tools/sg_unit_extractor.pl: Text file busy
make[2]: *** [src/cunit_unit.cpp] Error 127
CMakeFiles/testall.dir/build.make:69: recipe for target 'src/cunit_unit.cpp' failed
CMakeFiles/Makefile2:616: recipe for target 'CMakeFiles/testall.dir/all' failed
make[1]: *** [CMakeFiles/testall.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2
The command '/bin/sh -c sudo make' returned a non-zero code: 2
My Dockerfile content is:
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y \
sudo \
git \
build-essential \
cmake \
libboost-dev \
libboost-all-dev \
doxygen \
python3
RUN git clone https://github.com/simgrid/simgrid.git
WORKDIR "/simgrid"
RUN cmake -Denable_documentation=OFF -Denable_coverage=OFF -Denable_java=OFF -Denable_model-checking=OFF \
-Denable_lua=OFF -Denable_compile_optimizations=OFF -Denable_smpi=OFF -Denable_smpi_MPICH3_testsuite=OFF -Denable_compile_warnings=OFF .
RUN sudo make
RUN sudo make install
The error message you are seeing is from the output of make. It does not appear be an error for Docker. Instead, this points back to the code being compiled inside the image and so you would want to raise this issue with them in github.
I do see a fair number of kernel and network components being compiled with the app, which may not properly function in a docker sandbox, and so the code you are trying to compile may not be able to run in this type of isolation without disabling some of the protections that docker provides. See docker's security documentation for more details, particularly on the namespaces, cgroups, and capabilities to protect the kernel.
Despite this is not a Docker issue there are some scenarios where you can face this error building a dockerfile.
Just to bring a known workaround (even if it is not the most elegant solution) let me show you this one.
In my case I got the message " Text file busy " when trying to build a Dockerfile with the following line:
RUN chmod 500 /build/build_dotcms.sh && /build/build_dotcms.sh ${BUILD_FROM} ${BUILD_ID}
Provoked an interruption with "Text file busy" intermitently.
The workaround was to add a "sleep 1" between chmod command and shell script execution
RUN chmod 500 /build/build_dotcms.sh && sleep 1 && /build/build_dotcms.sh ${BUILD_FROM} ${BUILD_ID}
I found the solution in a github thread: https://github.com/moby/moby/issues/9547
Hope it helps.

Docker: transaction check error

I am trying to install docker and following https://get.docker.com/
I am on CentOS7
-bash-4.2$ cd
-bash-4.2$ wget -qO- https://get.docker.com/ | sh
+ sudo -E sh -c 'sleep 3; yum -y -q install docker-engine'
Transaction check error:
file /usr/lib/systemd/system/blk-availability.service from install of device-mapper-7:1.02.107-5.el7_2.5.x86_64 conflicts with file from package lvm2-7:2.02.105-14.el7.x86_64
file /usr/sbin/blkdeactivate from install of device-mapper-7:1.02.107-5.el7_2.5.x86_64 conflicts with file from package lvm2-7:2.02.105-14.el7.x86_64
file /usr/share/man/man8/blkdeactivate.8.gz from install of device-mapper-7:1.02.107-5.el7_2.5.x86_64 conflicts with file from package lvm2-7:2.02.105-14.el7.x86_64
Error Summary
-------------
Anyone know what this error means and how to resolve it?
Looks like device-mapper-7 is incompatible with lvm2-7 on your system.
You could try deinstalling device-mapper-7. Then try to run the Docker installation one more time.
I've updated with:
sudo yum update
Now docker command works now

Installing docker on centos7: docker-engine-selinux conflicts with docker-selinux-*

I tried installing docker from yum and from the install script on Centos7 and both of them give the same error:
Error: docker-engine-selinux conflicts with docker-selinux-1.10.3-44.el7.centos.x86_64
I am unable to figure out how to fix this and get docker installed.
Full error traceback:
[root#mynode]# wget -qO- https://get.docker.com/ | sh
/usr/bin/docker: line 13: /usr/bin/docker-latest: No such file or directory
sh: line 149: [: -lt: unary operator expected
sh: line 153: [: -le: unary operator expected
Warning: the "docker" command appears to already exist on this system.
If you already have Docker installed, this script can cause trouble, which is
why we're displaying this warning and provide the opportunity to cancel the
installation.
If you installed the current Docker package using this script and are using it
again to update Docker, you can safely ignore this message.
You may press Ctrl+C now to abort this script.
+ sleep 20
+ sh -c 'sleep 3; yum -y -q install docker-engine'
Error: docker-engine-selinux conflicts with docker-selinux-1.10.3-44.el7.centos.x86_64
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
yum list installed|grep docker
yum remove docker-selinux.x86_64
If top answer doesn't work, try yum remove docker-engine-selinux instead

Running docker-compose on a docker gitlab-ci-multi-runner

I have a project running on Docker with docker-compose for dev environment.
I want to get it running on GitLabCI with a gitlab-ci-multi-runner "Docker mode" instance.
Here is my .gitlab-ci.yml file:
image: soullivaneuh/docker-bash
before_script:
- apk add --update bash curl
- curl --silent --location https://github.com/docker/compose/releases/download/1.5.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- ./configure
- docker-compose up -d
Note that soullivaneuh/docker-bash image is just a docker image with bash installed.
The script fails on docker-compose up -d command:
gitlab-ci-multi-runner 0.7.2 (998cf5d)
Using Docker executor with image soullivaneuh/docker-bash ...
Pulling docker image soullivaneuh/docker-bash:latest ...
Running on runner-1ee5079f-project-3-concurrent-1 via sd-59984...
Fetching changes...
Removing app/config/parameters.yml
Removing docker-compose.env
HEAD is now at 5c5e7ff remove docker service
From https://git.dummy.net/project/project
5c5e7ff..45e643d docker-ci -> origin/docker-ci
Checking out 45e643dd as docker-ci...
Previous HEAD position was 5c5e7ff... remove docker service
HEAD is now at 45e643d... Remove docker info commands
$ apk add --update bash curl
fetch http://dl-4.alpinelinux.org/alpine/v3.2/main/x86_64/APKINDEX.tar.gz
OK: 10 MiB in 28 packages
$ curl --silent --location https://github.com/docker/compose/releases/download/1.5.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose
$ ./configure
$ docker-compose up -d
bash: line 30: /usr/local/bin/docker-compose: No such file or directory
ERROR: Build failed with: exit code 1
I have absolutly no idea why this is failing.
Thanks for help.
The No such file or directory is misleading. I've received that many times while trying to run dynamically linked binaries using alpine linux (which it appears you are using).
The problem (as I understand it) is that the binary was compiled and linked against glibc, but alpine uses musl, not glibc.
You could use ldd /usr/local/bin/docker-compose to tell you which libraries are missing (or run it with strace if all else fails).
To get it working, it might be easier to install from python source (https://docs.docker.com/compose/install/#install-using-pip), which is what the official compose image does (https://github.com/docker/compose/blob/master/Dockerfile.run).
Or you could use an image built on debian or some other distro that uses glibc.

Resources