dotnet安装脚本 dotnet-install-3.1.sh

可以根据需要换成其他版本

# Based on instructiions at https://www.microsoft.com/net/download/linux-package-manager/debian9/sdk-current
# Install dependency for .NET Core 2
apt-get update
apt-get install -y curl libunwind8 gettext apt-transport-https

# Based on instructions at https://www.microsoft.com/net/download/linux-package-manager/debian9/sdk-current
# Install microsoft.qpg & Install the .NET Core framework 

wget -O- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget https://packages.microsoft.com/config/debian/9/prod.list
mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
chown root:root /etc/apt/sources.list.d/microsoft-prod.list

apt-get update
apt-get install -y dotnet-sdk-3.1
apt-get install -y zip
apt-get clean

Dockerfile部分

FROM jenkins/jenkins:lts
# Switch to root to install .NET Core SDK
USER root
# Show distro information!
RUN uname -a && cat /etc/*release
RUN apt-get update && apt-get install -y libltdl7

ARG dockerGid=999
RUN echo "docker:x:${dockerGid}:jenkins" >> /etc/group

COPY dotnet-install-3.1.sh install.sh
RUN bash install.sh

# Switch back to the jenkins user.
USER jenkins

终端输入

sudo chown -R 1000:1000 /var/docker_data/jenkins/jenkins_home

# 制作镜像
docker build . -t jenkins-dotnet

# 启动镜像
# 注意端口映射规则 其中18080为jenkins访问端口 50000为底层tcp端口

docker run --name kaki-jenkins-dotnet -p 18080:8080 -p 50000:50000 -v /var/docker_data/jenkins/jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -v /volume1/docker/jenkins/backups/jenkins-153:/var/backups -v /volume1/Outofbag/server:/var/server -v $(which docker):/usr/bin/docker -e JAVA_OPTS=-Dorg.apache.commons.jelly.tags.fmt.timeZone=Asia/Shanghai -d jenkins-dotnet

docker-compose.yml

对应docker-compose文件

version: '2'
services:
  jenkins-core:
    build: ./
    environment:
      - JAVA_OPTS=-Dorg.apache.commons.jelly.tags.fmt.timeZone=Asia/Shanghai 
    ports:
      - 18080:8080
      - 50000:50000
    # uncomment for docker in docker
    privileged: true
    restart: always
    volumes:
        # enable persistent volume (warning: make sure that the local jenkins_home folder is created)
        - /var/docker_data/jenkins/jenkins_home:/var/jenkins_home
        # mount docker sock and binary for docker in docker (only works on linux)
        - /var/run/docker.sock:/var/run/docker.sock
		- /volume1/docker/jenkins/backups/jenkins-153:/var/backups
        - /usr/local/bin/docker:/usr/bin/docker
		- /volume1/Outofbag/server:/var/server