Mounting docker command into jenkins container

Hi, I’m trying to redirect docker binary and docker.sock into my jenkins docker container so it can use docker in its pipeline operations. I’m getting the following error when I do this:
bash: /usr/bin/docker: cannot execute: required file not found

here are the steps I followed;

  1. I get the absolute path of my host docker binary by doing readlink -f $(which docker)
  2. I created a docker-compose file. here are the contents;
version: "3"
services:
  jenkins:
    image: jenkins/jenkins:lts
    privileged: true
    user: root
    ports:
      - 8080:8080
      - 50000:50000
    container_name: jenkins
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /nix/store/pah5a5r2kyzdzac2115xsgzgnpypf6ps-docker-24.0.5/bin/docker:/usr/bin/docker
  1. I run the jenkins container and got into jenkins container shell. run docker and got the following error: bash: /usr/bin/docker: cannot execute: required file not found

does anyone know how to fix this?
I can provide more information if necessary

I believe what it can’t find is the DT_INTERP, the glibc dynamic linker, because this points into the Nix store.
You might try mounting the nix store into the container:

    ...
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /nix/store:/nix/store
      - /nix/store/pah5a5r2kyzdzac2115xsgzgnpypf6ps-docker-24.0.5/bin/docker:/usr/bin/docker

Note that hardcoding a store path into your Docker Compose file may be a bad idea, as nix store paths can eventually be GC’d. If you perform a nix build nixpkgs#docker or nix-build '<nixpkgs>' -A docker (pre-flake), you should get a result symlink in the current folder; that will act as a GC root that pins the store path that it points to from being GC’d as long as the directory is not removed or renamed. This isn’t a bullet proof solution, but I can’t think of a more intricate solution that might suit your workflow, off-hand.

1 Like

mounting /nix/store solved the problem. you saved me from installing ubuntu server. thank you.