title: Run tests in docker container using TestContainers and Jenkins (docker.sock Permission denied)
body: <p>In my tests I use <code>TestContainers</code>. I want run tests in container using Jenkins. I created this image for run tests with <code>maven</code>.
  Dockerfile:</p>
  
  <pre><code>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 \
  &amp;&amp; dpkg -i ndbclient_7.6.10-1debian9_amd64.deb &amp;&amp; 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 &amp;&amp; useradd -m --uid 10028 --gid 10000 jenkins
  RUN echo "jenkins ALL=(ALL) NOPASSWD:ALL" &gt; /etc/sudoers
  
  COPY settings.xml /home/jenkins/
  
  USER jenkins
  </code></pre>
  
  <p>In my tests I use <code>MySQL Cluster</code> container. </p>
  
  <p>For <code>Jenkins</code> I add node in Jenkinsfile:</p>
  
  <pre><code>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/"'
                      }
                  }
      }
  }
  </code></pre>
  
  <p>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 <code>docker.sock</code> is denied:</p>
  
  <pre><code>Caused by: java.io.IOException: com.sun.jna.LastErrorException: [13] Permission denied
      at org.testcontainers.shaded.org.scalasbt.ipcsocket.UnixDomainSocket.&lt;init&gt;(UnixDomainSocket.java:62)
      at org.testcontainers.dockerclient.transport.okhttp.UnixSocketFactory$1.&lt;init&gt;(UnixSocketFactory.java:27)
      at org.testcontainers.dockerclient.transport.okhttp.UnixSocketFactory.createSocket(UnixSocketFactory.java:27)
  </code></pre>
  
  <p>I studied this page: <a href="https://www.testcontainers.org/supported_docker_environment/continuous_integration/dind_patterns/" rel="noreferrer">https://www.testcontainers.org/supported_docker_environment/continuous_integration/dind_patterns/</a> but it didn't help me. There everything starts from the root user, and of course he has no problems.</p>
  
  <p>How can I fix it?</p>