Drone

Cant expose a Local Port to Docker container

Hi,
I was trying to build a docker image locally using drone exec in windows.
Here is my .drone.yml file
kind: pipeline
name: default

clone:
  disable: true

steps:

  - name: docker_local_build
    image: docker
    privileged: true
    environment:
      DOCKER_HOST: "tcp://localhost:2375"
    commands:
      - docker build -t foo/bar .

While running I’m receiving this error.
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?

I think the container is not exposed to the local port 2375. Is there any possible way to expose local ports to the container in .drone.yml.

image: docker
ports: [2375]

I think it should work.
Ref: Expose ports from service containers

Thanks for the update :slightly_smiling_face:.

But received the same error and while seeing container list using docker ps during build,
there is no exposed port details in it.

The volume socket is not being mounted onto the docker image. Hence the docker image cannot connect detect the docker service on host machine.

Solution:

kind: pipeline
name: default

steps:
- name: docker_local_build
  image: docker
  privileged: true
  volumes:
      - name: mounted
        path: /var/run/docker.sock
  commands:
    - docker --version
    - ps uax
    - docker ps
    - docker build -t foo/bar .

volumes:
- name: mounted
  host:
    path: /var/run/docker.sock
1 Like

Thanks, @Rewanth_Cool :heart_eyes: . It seems helpful.