Access docker in Jenkins shell command on Docker Desktop Windows

Spread the love
  1. Install Ubuntu on WSL 2 and set it the default distro
  2. Install docker desktop with WSL as backend plane for running containers.
  3. Go to settings of docker desktop -> Resources -> WSL Integration and enable the integration with Ubuntu distro and restart the docker from home page -> bottom left.
  4. Use the latest jenkins image from docker hub to run the jenkins container.
  5. Copy the run command from menu of container.
  6. Add the docker sock binding by adding the following to the run command:
    –volume=/var/run/docker.sock:/var/run/docker.sock –volume=/usr/bin/docker:/usr/bin/docker –privileged
  7. Open cmd and go to shell of ubuntu distro: wsl -d <distro-name>
  8. Paste the run command. You will have a new container running in ubuntu and will be visible in docker desktop GUI.
  9. Go to containers and click on the name of container for jenkins image. You will have the default password for jenkins installation in the Logs.
  10. Go to the browser and open the localhost:<port> and complete the Jenkins setup.
  11. Now you should be able to access the docker in jenkins shell command.