Azure DevOps - Azure Pipeline with Docker (dotnet)

Build a Docker Image 1. Create an Azure Container registry (say myreg101). 2. Create a Dotnet app (I am using webapp aspnet core 6.0) 3. Pub...

Build a Docker Image

1. Create an Azure Container registry (say myreg101).

2. Create a Dotnet app (I am using webapp aspnet core 6.0)

3. Publish the code on your local system.

4. Create an azure ubuntu vm and copy-publish code on this machine.

5. Install Docker on ubuntu VM (apt install -y)

6. Create a Dockerfile in the publish folder with the following code


COPY . .
ENTRYPOINT ["dotnet", "DotNetApp.dll" ]

7. Build a docker image(webimg) with the following command

    docker build . -t webimg

8. Once the image is built successfully then create a container with this image with port forwarding of port number 80.

    docker container run -it --name web -p 80:80 -d webimg

9. On the browser with the public IP address of the ubuntu VM you can see the output of the application.

10. Push the docker image to the container registry with the following commands ( is the azure container registry server in my case)

        docker login

        docker image tag webimg

        docker push

11. In VS project add a Docker file

12. Create an Azure Pipeline with above project and add below pipeline

# Docker
# Build and push an image to Azure Container Registry

- master

- repo: self

  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: 'dd082128-b9c9-4f1e-9f55-6035ec616d54'
  imageRepository: 'testproj'
  containerRegistry: ''
  dockerfilePath: '$(Build.SourcesDirectory)/DotNetApp/Dockerfile'
  tag: '$(Build.BuildId)'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

- stage: Build
  displayName: Build and push stage
  - job: Build
    displayName: Build
      vmImage: $(vmImageName)
    - task: UseDotNet@2
        packageType: sdk
        version: '6.x'
    - task: DotNetCoreCLI@2
        command: 'build'
        projects: '**/*.csproj'
        arguments: '--configuration $(buildConfiguration)'

    - task: DotNetCoreCLI@2
        command: 'publish'
        publishWebProjects: true
        arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'    
    - task: Docker@2
      displayName: Build and push an image to container registry
        command: buildAndPush
        buildContext: $(Build.Repository.LocalPath)
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: |

13.Run the pipeline and a docker image should be created in Azure container registry.

14. Create a release pipeline for docker container.

     In the Agent job Use Azure CLI and write an Inline script

     az container create -g MyRG --name appinstance200130 --cpu 1 --memory 1 --port 80 --ip-address Public --image --registry-username myreg101 --registry-password waJ3dncLQE4jDLolaa9hVvUmeoSMwIS/

15. Container instance should be created



Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
DevOpsWorld: Azure DevOps - Azure Pipeline with Docker (dotnet)
Azure DevOps - Azure Pipeline with Docker (dotnet)
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content