DEV Community

Discussion on: Docker & Azure Pipelines: Better Together!

Collapse
 
ashun_77 profile image
ASHUN KOTHARI • Edited

How can I specify a custom path for docker.sock while mentioning the resources or while mentioning container inside the task?

I am running the agent as a service on a linux machine which has docker installed but the socket is not at its default location. I want to run jobs inside a docker but the build fails as I am not able to specify the docker.sock path.

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

In order to use Docker from within a Docker container, you need to [bind-mount}(docs.docker.com/storage/bind-mounts/) the Docker socket.

you will need to add 2 parameters to your docker run command line which are -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker (Change it with your path)

Collapse
 
ashun_77 profile image
ASHUN KOTHARI

Thank you for the reply Davide! :)

The way I have configured my pipeline is somewhat like this

resources:
  containers:
  - container: u14
    image: ubuntu:14.04

  - container: u16
    image: ubuntu:16.04

  - container: u18
    image: ubuntu:18.04

jobs:
- job: RunInContainer
  pool:
    vmImage: 'ubuntu-18.04'
  container: u18

  steps:
  - script: printenv
Enter fullscreen mode Exit fullscreen mode

My agent is a running as a service. The docker installed on the agent is having its docker.sock file at a different place. As I am not running the docker run command manually is there a way I could specify it in the above configurations?

I tried giving it under resources > containers > container > options but that didn't work.

Thread Thread
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

Well, that should be in the docker run of your agent container (in the script you use to start the container that has the agent in it)

Some comments have been hidden by the post's author - find out more