https://tutorials.releaseworksacademy.com/learn/the-simple-way-to-run-docker-in-docker-for-ci
Connection way using docker volume.
- docker installed host /var/run/docker.sock and jenkins in docker /var/run/docker.sock
FROM jenkins/jenkins:lts
USER root
COPY docker_install.sh /docker_install.sh
RUN chmod +x /docker_install.sh
RUN /docker_install.sh
#!/bin/sh
apt-get update && \
apt-get -y install apt-transport-https \
ca-certificates \
curl \
gnupg2 \
zip \
unzip \
software-properties-common && \
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey && \
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable" && \
apt-get update && \
apt-get -y install docker-ce
version: '3'
services:
jenkins:
build:
context: .
dockerfile: Dockerfile
container_name: 'jenkins'
restart: always
ports:
- '8081:8080'
- '50200:50000'
expose:
- '8080'
- '50000'
volumes:
- 'jenkins_data:/var/jenkins_home'
- '/var/run/docker.sock:/var/run/docker.sock'
environment:
TZ: "Asia/Seoul"
networks:
- jenkins
volumes:
jenkins_data:
networks:
jenkins:
docker compose up --file docker-compose-jenkins.yaml --detach --project-name="jenkins"
docker exec -it jenkins bash
root@c83639ffd83c:/# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c83639ffd83c jenkins_jenkins "/sbin/tini -- /usr/…" About a minute ago Up About a minute 0.0.0.0:8081->8080/tcp, 0.0.0.0:50200->50000/tcp jenkins