In my tests I use TestContainers
. I want run tests in container using Jenkins. I created this image for run tests with maven
.
Dockerfile:
FROM registry.company.com/maven:3-jdk-8-slim
RUN apt update
RUN apt install -y wget libatomic1 curl gnupg
RUN wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-7.6/ndbclient_7.6.10-1debian9_amd64.deb \
&& dpkg -i ndbclient_7.6.10-1debian9_amd64.deb && rm ndbclient_7.6.10-1debian9_amd64.deb
RUN ln -s /usr/lib/x86_64-linux-gnu/libndbclient.so.6.1.0 /usr/lib/x86_64-linux-gnu/libndbclient.so
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get -y install nodejs
RUN groupadd --gid 10000 ldap && useradd -m --uid 10028 --gid 10000 jenkins
RUN echo "jenkins ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers
COPY settings.xml /home/jenkins/
USER jenkins
In my tests I use MySQL Cluster
container.
For Jenkins
I add node in Jenkinsfile:
node('Docker') {
checkout scm
docker.withRegistry('http://registry.company.com/v2/', 'cred_id') {
docker.image('integration-tests:latest')
.inside('-v $HOME/.m2:/home/jenkins/.m2:rw -u jenkins') {
stage('Test') {
sh 'mvn clean -s /home/jenkins/settings.xml'
sh 'mvn -s /home/jenkins/settings.xml test -DargLine="-Djava.library.path=/usr/lib/x86_64-linux-gnu/"'
}
}
}
}
The problem is that Jenkins is running from the user jenkins. I created the same user with the same userid and groupid. But when I start the tests I get that access to docker.sock
is denied:
Caused by: java.io.IOException: com.sun.jna.LastErrorException: [13] Permission denied
at org.testcontainers.shaded.org.scalasbt.ipcsocket.UnixDomainSocket.<init>(UnixDomainSocket.java:62)
at org.testcontainers.dockerclient.transport.okhttp.UnixSocketFactory$1.<init>(UnixSocketFactory.java:27)
at org.testcontainers.dockerclient.transport.okhttp.UnixSocketFactory.createSocket(UnixSocketFactory.java:27)
I studied this page: https://www.testcontainers.org/supported_docker_environment/continuous_integration/dind_patterns/ but it didn't help me. There everything starts from the root user, and of course he has no problems.
How can I fix it?
If running elevated Docker commands does not fix the permission denied error, verify that your Docker Engine is running. Similar to running a docker command without the sudo command, a stopped Docker Engine triggers the permission denied error. How do you fix the error? By restarting your Docker engine.
The Docker socket file should therefore have permissions of 660 or more restrictive permissions.
Running tests against a browser in a Docker container through an Open Agent that is running in another Docker container. The browser and the Open Agent communicate with each other through a Docker network. The test executor is running on your local Windows machine. Running tests entirely from Docker containers.
A dirty fix is:
sudo chmod a+rw /var/run/docker.sock
This might have some security risks, but I am on my local machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With