How to setup jenkins agent docker in docker

Hi all,
I’m Jenkins newbie
I have an Ubuntu server , docker installed, I run jenkins with docker compose as below

version: "3"

services:

  jenkins:
    image: jenkins/jenkins:2.430-jdk21
    container_name: jenkins
    environment:
      - TZ=Asia/Ho_Chi_Minh
    ports:
      - "8080:8080"
    volumes:
      - ./jenkins_home:/var/jenkins_home
    networks:
      - jenkins-net

networks:
  jenkins-net:
    driver: bridge
    name: jenkins-net

Please give me instruction to:

  1. Setup Jenkins agent running with docker compose on same server. (like gitlab runner docker in docker)
  2. Add Jenkins agent to Jenkins controller UI (as node ?) so my pipeline can use it to build/run docker image , deploy yml manifest to k8s (like add gitlab runner to gitlab UI)
    I read Jenkins documentation but I don’t fully understand yet, thank you very much.

I follow this article https://devopscube.com/docker-containers-as-build-slaves-jenkins/?unapproved=63874&moderation-hash=d5464a664348e998b876cdc761385caa#comment-63874

I run Jenkins controller by docker compose as below

version: "3"

services:

  jenkins:
    image: jenkins/jenkins:2.430-jdk21
    container_name: jenkins
    privileged: true
    user: root
    environment:
      - TZ=Asia/Ho_Chi_Minh
    ports:
      - "8080:8080"
      - "50000:50000"
    volumes:
      - ./jenkins_home:/var/jenkins_home
    networks:
      - jenkins-net

networks:
  jenkins-net:
    driver: bridge
    name: jenkins-net

I install another Ubuntu server , docker installed , configure this Host With Remote API , tested with curl ok

Configure Jenkins Server With Docker Plugin , test connection ok , I use image bibinwilson/jenkins-agent:latest

When I test Jenkins Build Inside a Docker container , it keeps pending—java-docker-agent-000032lllkxdq is offline

Hello there,

You could also have a look at this project: GitHub - gounthar/quickstart-tutorials: Jenkins tutorial files .