dockerfile
Mcr.microsoft.com/dotnet/core/aspnet the FROM: 3.0 the AS Base . Note # and a space / between the host indicates the current directory to copy the contents of the image / publish directory the RUN LN -s / lib / the x86_64-Linux- the GNU / libdl- 2.24 .so / lib / x86_64-the GNU-Linux / libdl.so # start the installation prerequisites RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \ echo " Stretch main non-http://mirrors.163.com/debian/ the deb Free contrib " > /etc/apt/sources.list && \ echo " the deb http://mirrors.163.com/debian/ Stretch-proposed- Free contrib main non-Updates " >> / etc / APT / && the sources.list \ echo "deb-src http://mirrors.163.com/debian/ stretch main non-free contrib" >>/etc/apt/sources.list && \ echo "deb-src http://mirrors.163.com/debian/ stretch-proposed-updates main non-free contrib" >>/etc/apt/sources.list RUN apt-get update RUN apt-get install libfontconfig1 -y RUN apt-get install libgdiplus -y && ln -s libgdiplus.so gdiplus.dll FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build WORKDIR /src #COPY . . COPY ./JenkinsNetCoreDemo . #RUN dotnet restore --configfile nuget.config JenkinsNetCoreDemo.sln --no-cache && \ #dotnet build --no-restore -c Release JenkinsNetCoreDemo.sln RUN dotnet restore JenkinsNetCoreDemo.sln --no-cache && \ dotnet build --no-restore -c Release JenkinsNetCoreDemo.sln FROM build AS publish WORKDIR /src RUN dotnet publish --no-restore -c Release -o /app FROM base AS final ARG env #run echo $env #COPY . /app WORKDIR /app ENV ASPNETCORE_ENVIRONMENT=$env RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN echo 'Asia/Shanghai' >/etc/timezone #VOLUME /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "JenkinsNetCoreDemo.dll"]
node{ stage('git下载'){ checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'd77e88dc-f571-4a1f-a5d0-d84a00a89668', url: 'https://github.com/zx972243884/JenkinsNetCoreDemo.git']]]) } stage('构建'){ sh label: '', script: ''' docker build -t 192.168.160.130/library/jenkinsnetcoredemo -f ./JenkinsNetCoreDemo/JenkinsNetCoreDemo/Dockerfile . ''' } stage('上传到仓库'){ sh label: '', script: ''' docker push 192.168.160.130/library/jenkinsnetcoredemo docker rmi 192.168.160.130/library/jenkinsnetcoredemo ''' } stage('部署'){ sh label: '', script: ''' docker stop jenkinsnetcoredemo&&docker rm jenkinsnetcoredemo docker pull 192.168.160.130/library/jenkinsnetcoredemo docker run -d --name jenkinsnetcoredemo -p 9021:80 -v /etc/timezone:/etc/timezone --env ASPNETCORE_ENVIRONMENT=Development 192.168.160.130/library/jenkinsnetcoredemo:latest ''' } }
docker run -d --name jenkinsnetcoredemo -p 9021:80 -v /etc/timezone:/etc/timezone --env ASPNETCORE_ENVIRONMENT=Development --add-host xxx.xxxx.com:192.168.1.5 192.168.160.130/library/jenkinsnetcoredemo:latest
jenkinsnetcoredemo