skip to Main Content

I have an AWX environment where each job runs on docker container with Centos 8.
I was requested to enable the ability to run docker commands such as push/pull/build/tag inside the container (no need to run container within the container) for a new job.
I’m trying to understand how do i modify the dockerfile so when the docker container starts automatically by the awx it will have this ability.

I saw some posts saying i need to mount the /var/run/docker.sock on the container so i will have access to the host’s docker daemon but when i tried to add to the dockerfile the line –
VOLUME /var/run/docker.sock
and when i tried to build the image and run it locally and do some docker commands i get the output-

"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"

will appreciate your help 🙂

2

Answers


  1. The Dockerfile describes what the image looks like, but it needs arguments passed either via docker run or docker-compose to tell the container created from the image how to interface with the actual host.

    For example, Portainer is a docker image that manages a docker instance running on the host. The communication from the container to host is done by passing the socket with the --volumes argument in docker run.

    docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ee:latest

    This binds the host’s docker socket to the guest container. Likewise, you’d need to start your container with -v /var/run/docker.sock:/var/run/docker.sock

    Login or Signup to reply.
  2. Try to add a custom specification for the Instance Group you are using in your template, this works for me:

        apiVersion: v1
        kind: Pod
        metadata:
          namespace: awx
        spec:
          serviceAccountName: default
          automountServiceAccountToken: false
          containers:
            - image: 'my-ansible-ee:1.0.0'
              name: worker
              args:
                - ansible-runner
                - worker
                - '--private-data-dir=/runner'
              resources:
                requests:
                  cpu: 3000m
                  memory: 3000Mi
              securityContext:
                privileged: true
                runAsUser: 0
              volumeMounts:
                - mountPath: /var/run/docker.sock
                  name: docker-sock
                  readOnly: false
          volumes:
            - name: docker-sock
              hostPath:
                path: "/var/run/docker.sock"
                type: File
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search