Home Dockerfile部署Jenkins(Docker-Out-Of-Docker)
Post
Cancel

Dockerfile部署Jenkins(Docker-Out-Of-Docker)

Dockerfile

主要是基于Jenkins的容器搭建docker的环境,然后运行时docker.sock使用外部docker的即可

创建sources.list,增加以下内容下载依赖更快

1
2
3
4
5
6
7
8
deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib

创建Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
FROM jenkins/jenkins:2.477-jdk17

USER root

ADD ./sources.list /etc/apt/
ENV DEBIAN_FRONTEND=noninteractive

RUN cat /etc/os-release &&  cat /etc/apt/sources.list &&  apt-get update -qq\
    && apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | apt-key add -
RUN add-apt-repository \
   "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/debian/ \
   $(lsb_release -cs) \
   stable"
RUN apt-get update -qq\
    && apt-get install docker-ce -y
RUN usermod -aG docker jenkins

编译生成镜像

1
docker build -t jiangker/jenkins:2.477-jdk17 .

运行容器

1
docker run -d --name jenkins -p 8080:8080 -v /etc/localtime:/etc/localtime -v /root/.ssh:/root/.ssh -v /cloud/docker/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock --restart=always jiangker/jenkins:2.477-jdk17

因为jenkins一般需要使用git,所以.ssh直接使用外部容器的了,也可以单独创建内部的。

搭建环境

rust编译环境

官方脚本

1
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

如果访问不了,可以替换为,更改了源地址,方便国内下载

1
curl --proto '=https' --tlsv1.2 -sSf https://gitee.com/jiangkerlove/ssh-script/blob/master/rustup-init.sh | sh 

也可以用wget下载

1
sh -c "$(wget -O- https://gitee.com/jiangkerlove/ssh-script/raw/master/rustup-init.sh)

安装完成之后测试命令

1
cargo --version

如果使用不了,再重新加载一下source文件

1
source .bashrc

其余可以看交叉编译

This post is licensed under CC BY 4.0 by the author.