Every now and then I come across the requirement to build Docker images inside a Docker container. More often than not, this happens when I need to build Docker images as part of a Continuous Integration pipeline running Jenkins - where the Jenkins master (or agent) is running inside a Docker container.
Docker doesn't recommend running the Docker daemon inside a container (except for very few use cases like developing Docker itself), and the solutions to make this happen are generally hacky and/or unreliable.
Fear not though, there is an easy workaround: mount the host machine's Docker socket in the container. This will allow your container to use the host machine's Docker daemon to run containers and build images.
Your container still needs compatible Docker client binaries in it, but I have found this to be acceptable for all my use cases.
The TL;DR version using my prebuilt image is:
docker run \ -p 8080:8080 \ -v /var/run/docker.sock:/var/run/docker.sock \ --name jenkins \ getintodevops/jenkins-withdocker:lts
The guide below is for Jenkins, but you can apply the same logic to any other build server.
Building Docker containers with Jenkins inside a container
First, we'll run Jenkins as a container using the official Jenkins image:
docker run -p 8080:8080 \ -v /var/run/docker.sock:/var/run/docker.sock \ --name jenkins \ jenkins/jenkins:lts
Note that the key here is mounting /var/run/docker.sock from the host machine to the same location inside the container.
Then, we'll need to install the Docker binaries inside the container. Spawn an interactive shell inside the running Jenkins container:
docker exec -it -u root jenkins bash
Because the official Jenkins image is based on Debian 9, we can use apt to install the Docker binaries as instructed in the Docker installation guide. This is a single snippet to install some prerequisites, configure the official Docker apt repositories and install the latest Docker CE binaries:
apt-get update && \ apt-get -y install apt-transport-https \ ca-certificates \ curl \ gnupg2 \ 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
Caveat: The Docker daemon running on your host machine must be compatible with the version of client binaries you are installing. To verify the version, run docker version on your host machine.
Ta-da! Your Jenkins container should now have a functioning Docker installation. Verify by running:
docker ps
The output should be the same as when running the command on the host machine (you should at least expect to see the Jenkins container running!).
Next, you'll need to finish the installation of Jenkins as usual. Open the Jenkins installer by navigating to http://localhost:8080.
You will need the initial admin password, which can be obtained by running:
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
Next select "Install recommended plugins", and wait for Jenkins to install everything. The Docker Pipeline plugin is installed by default, which means you are ready to go!
I have pre-built a Jenkins 2.73.1 image with Docker 17.09.0-ce binaries. It's available on Docker Hub as getintodevops/jenkins-withdocker.
Next, read How to build your first Docker image with Jenkins!
tip, docker
相关推荐
离线环境下,在centos7.6系统上安装docker-ce-19.03,nvidia-docker2.4版本,其中docker-ce-19.03在docker-local.tar压缩文件里面,nvidia-docker2在nvidia-docker2.zip文件中。 具体安装流程如下: 1.安装docker ...
docker-ce-17.03.2.ce-1.el7.centos.x86_64 Centos7 离线安装包和依赖包、 audit-libs-python-2.7.6-3.el7.x86_64.rpm checkpolicy-2.5-4.el7.x86_64.rpm docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm docker-ce-...
The purpose of this project is to help you install Docker in an offline environment. Generally speaking, Docker only support 64bit Linux operation system. online-install If you are in an online ...
一键离线安装docker、docker-compose
docker-compose v2.17.2
docker-compose-window-2.14.2.exe免费下载
tvial/docker-mailserver邮箱服务器。可以自己在小网中搭建一个邮件服务器自己玩。启动方法 docker run --name forsaken-mail -itd -p 2255:25 -p 3000:3000 tvial/docker-mailserver:latest
Docker-in-Action.pdf In 2011, I started working at Amazon.com. In that first week my life was changed as I learned how to use their internal build, dependency modeling, and deployment tool- ing. This ...
docker社区版linux离线包docker-20.10.9.tgz供docker学习使用,资源来自官方https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz
1、免积分,不需要VIP,直接下载即可(如果后期被系统修改要VIP,可随意私信我要); 2、由于网上关于 aarch64 的资源特别少,尤其是 docker 这一块的,其他网友写的...3、本资源适用于docker-compose-linux-aarch64
最新版本的docker client for windows, 方便VSCODE使用,通过配置DOCK TCP HOST啥的连接docker 实例。 docker --version Docker version 20.10.17, build 100c701 docker-compose.exe --version docker-compose ...
mv docker-compose /usr/local/bin/docker-compose 验证安装 systemctl restart docker docker version (看到版本信息证明安装成功) docker-compose version (看到版本信息证明安装成功)
多体系结构:在amd64,arm(RaspberryPI ...)等上运行变更日志 :page_with_curl: 参见最新版本最新标签:跑步最低要求: docker run -d --name radicale \ -p 5232:5232 \ tomsquest/docker-radicale 基本说明: ...
docker run --rm \ -e SETTINGS_FLAVOR=qiniustorage \ -e QINIU_BUCKET=YOUR_BUCKET \ -e QINIU_ACCESSKEY=YOUR_ACCESSKEY \ -e QINIU_SECRETKEY=YOUR_SECRETKEY \ -e QINIU_DOMAIN=YOUR_BUCKET_DOMAIN \ -p...
ubuntu 16.04 docker 离线安装包 docker-ce_18.03.1 上传到服务器,执行安装命令 # sudo dpkg -i libltdl7_2.4.6-0.1_amd64.deb # sudo dpkg -i libseccomp2...# sudo dpkg -i docker-ce_18.03.1~ce-0~ubuntu_amd64.deb
docker-compose-Linux-x86_64,版本1.24.0,docker-compose工具,教程可见《CentOS7安装docker-compose(附docker-compose命令介绍)》(https://blog.csdn.net/qq_43312020/article/details/123429307)
docker/docker-runc docker/dockerd docker/docker-containerd-ctr docker/docker-containerd-shim docker/docker-init [root@localhost opt]# cp docker/* /usr/bin/ # 将docker注册为service,在/etc/systemd/...
docker-compose-viz, Docker 组合图形可视化 docker-compose-viz :如何使用 Docker考虑到当前工作目录是你的docker-compose.yml 文件所在的位置:docker run --rm -it --name dcv
liunx的docker-ce18.09.0-3稳定版本,网上的资源比较少。 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
离线镜像文件大概有3个多G,存放在百度云上面,下面附上我们总结在window10 上和centos 上面创建docker for oracle 12c 容器的经验内容,坑过多少坑了。再也不需要使用安装版的oracle 。 具体: store/oracle/...