public:docker:app:jenkins

docker 部署 jenkins

docker-compose.yml
version: "3.7"

services:
  jenkins:
    image: 'jenkins/jenkins:lts-alpine'
    restart: always
    ports:
      - '8080:8080'
      #- '50000:50000'
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - jenkins-data:/var/jenkins_home

  java11-node1:
    image: 'gulucat/java-agent:jdk11'
    restart: always
    volumes:
      - /home/deploy/dist:/dist
      - maven_repository:/root/.m2
    environment:
      - TZ=Asia/Shanghai

volumes:
  jenkins-data:
  maven_repository:
  1. 直接备份 /var/jenkins_home 中的所有内容即可。
  2. 升级时,直接把旧镜像删除,再使用新镜像创建容器即可。(数据已挂载到容器外)

vi agent_jdk11.dockerfile

FROM maven:3-jdk-11

RUN sed -i "s@http://deb.debian.org@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list \
    && sed -i "s@http://security.debian.org@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
        ssh \
        curl \
        vim-tiny \
    && rm -rf /var/lib/apt/lists/* \
    && mkdir /run/sshd

RUN echo "export PATH=/usr/local/openjdk-11/bin:\$PATH" >> /root/.bashrc \
    && echo "export JAVA_HOME=/usr/local/openjdk-11" >> /root/.bashrc \
    && mkdir -p /home/jenkins \
    && mkdir /root/.ssh

# jenkins 里创建一对密钥,把公钥提出来,放到节点镜像中,实现免密控制。
COPY ./certs/id_ed25519.pub /root/.ssh/authorized_keys

CMD ["/usr/sbin/sshd", "-D"]
docker build -f agent_jdk11.dockerfile -t gulucat/java-agent:jdk11 .

  • 最后更改: 2023/08/15 01:29
  • 由 Jinkin Liu