我拼命尝试构建一个dotnet core 3.1项目,然后使用docker从中创建一个映像并将其推送到我的注册表中
这是我的azure-pipeline.yaml:
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- none
pool:
vmImage: 'ubuntu-latest'
variables:
- group: obs-devops-global-variables
# Put variable group for your team (variable groups in Pipelines-->Library)
- group: obs-devops-tso-variables
- name: AzureSubscription
value: 'obs-acr-sc-dev'
- name: ACR
value: obsaksacrdev.azurecr.io
- name: ImagePrefix
value: obs-$(team)/
# Put name of Image same like name of repo
- name: ImageName
value: obs-datalake-raw2gold
- name: BuildConfiguration
value: 'Release'
- name: imageTag
value: '4.0.$(build.buildId)'
- name: rid
value: 'linux-x64'
steps:
#- script: |
# dotnet restore
# dotnet build
# dotnet publish ./RawToGold.Worker/ --configuration $(buildConfiguration)
- task: UseDotNet@2
inputs:
version: '3.1.x'
packageType: sdk
- task: DotNetCoreCLI@2
displayName: 'dotnet build $(buildConfiguration)'
inputs:
command: 'build'
arguments: '-r $(rid) --configuration $(buildConfiguration) /p:SourceRevisionId=$(Build.SourceVersion)'
- task: DotNetCoreCLI@2
displayName: "Publish"
inputs:
command: 'publish'
publishWebProjects: false
arguments: './RawToGold.Worker/ -r $(rid) --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: false
- task: Docker@1
displayName: 'Containerize the micro service'
inputs:
useDefaultContext: false
azureSubscriptionEndpoint: '$(AzureSubscription)'
azureContainerRegistry: '$(ACR)'
dockerFile: 'Dockerfile'
imageName: '$(ACR)/$(ImagePrefix)$(ImageName):$(imageTag)'
- task: Docker@1
displayName: 'Push image'
inputs:
azureSubscriptionEndpoint: '$(AzureSubscription)'
azureContainerRegistry: '$(ACR)'
command: 'Push an image'
imageName: '$(ACR)/$(ImagePrefix)$(ImageName):$(imageTag)'
- task: PublishPipelineArtifact@1
displayName: 'Publish Pipeline Artifact'
inputs:
artifactName: 'k8s'
targetPath: 'k8s'
这是我的docker文件
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-bionic
RUN groupadd --gid 1000 rawtogold \
&& useradd --uid 1000 --gid rawtogold --shell /bin/bash --create-home rawtogold
USER rawtogold
#Use locally
#COPY ./RawToGold.Worker/bin/Release/netcoreapp3.1/publish /home/rawtogold/app/
COPY . /home/rawtogold/app/
RUN ls /home/rawtogold/app/
WORKDIR /home/rawtogold/app/
ENTRYPOINT ["dotnet", "RawToGold.Worker.dll"]
但是编译后的代码没有复制到图像中吗?
我已经尝试过COPY . /home....
和COPY ./RawToGold.Worker/bin/Release/netcoreapp3.1/publish
,将在本地开发计算机上使用它们来构建映像。
但是如何控制dockerfile的buildContext。并添加输入:buildContext到任务中对Docker @ 1没有帮助不
如果我使用powershell(顶部未注释的行)构建它,则实际上可以使用./RawToGold.Worker/bin/Release/netcoreapp3.1/publish
访问文件
但是我想知道如何在docker @ 1
答案 0 :(得分:0)
实际上,我放弃了这一点,开始使用Docker @ 2,它可以正常工作,而Docker @ 1则被弃用了