0

Working on a Mac. I am trying to run docker in a docker container by mounting docker client and socket like so:

services:
  jenkins:
    image: ubuntu:latest
    container_name: ubuntu
    privileged: true
    tty: true
    volumes:
      - ./ubuntu/home:/home
      - /usr/local/bin/docker:/usr/bin/docker
      - /var/run/docker.sock:/var/run/docker.sock

When I now exec into the container and try to run a docker command, I get this:

➜  test docker exec -it ubuntu /bin/bash
root@c586d6f5fca4:/# which docker
root@c586d6f5fca4:/# docker -h
bash: docker: command not found
root@c586d6f5fca4:/#

Why am I not able to run docker in the container even though the hosts (my Mac) docker client and socket are mounted?

root@c586d6f5fca4:/# ls -la /usr/bin | grep docker
+drwxr-xr-x 2 root root        40 Oct 12 08:49 docker
root@c586d6f5fca4:/var/run# ls -la
total 20
drwxr-xr-x 1 root root 4096 Oct 22 05:54 .
drwxr-xr-x 1 root root 4096 Oct 22 05:54 ..
srwxr-xr-x 1 root root    0 Sep 18 12:38 docker.sock
drwxrwxrwt 2 root root 4096 Oct  3 21:41 lock
drwxr-xr-x 2 root root 4096 Oct  3 21:41 mount
drwxr-xr-x 2 root root 4096 Oct  3 21:44 systemd

The path to docker client on Mac is correct:

➜  ~ which docker
/usr/local/bin/docker

Thanks!

  • You're trying to bind mount a MacOS binary into a Linux container, and one OS can't run the other OS's binaries. [Docker not found when building docker image using Docker Jenkins container pipeline](https://stackoverflow.com/questions/44850565/docker-not-found-when-building-docker-image-using-docker-jenkins-container-pipel) discusses some alternative approaches, does one of those work for you? – David Maze Oct 22 '22 at 10:34
  • Will check. Thank you! Will check the approaches. – fiedegufei Oct 22 '22 at 17:59
  • Thanks again! The first solution - installing the docker client in the container - works fine. Stupid me, not realizing that different OS' need different binaries. – fiedegufei Oct 23 '22 at 06:08

0 Answers0