Dockerfile does not work on Azure but works on local machine

Sam Wheat 406 Reputation points
2024-09-30T00:07:23.0333333+00:00

The problem I am having is that when I open a bash shell in the container my app is not there (the app folder does not exist).

Exact same Dockerfile works fine on my local machine as specified below.

Generally, I've followed instructions from this link - [https://www.perplexity.ai/search/how-to-write-a-dockerfile-and-ov8Boi2fQdaFJfKI6NAD0g].

I have carefully followed all the steps on this link [https://www.perplexity.ai/search/how-to-give-an-azure-web-servi-OfrBuhWUQlyGf98hdSMI5Q].

From App Service -> Identity -> Azure role assignments I see AcrPull and AcrPush with Resource name being my container repo.

Two steps I am unable to follow are:

Under "General settings", set "Stack settings" to "Docker"

Specify your container image: yourregistry.azurecr.io/your-image:tag

Under "Stack settings" my web app does not allow changing any setting to docker. However, it shows the startup command which is correctly set from my .yml file to docker myapp.dll.

Also in Overview -> Properties I see Publishing Model as "Container" and Container Image is correctly set to myRepo.azurecr.io/myapp:2284.

Dockerfile and azure-pipelines.yml are shown below. This Dockerfile works just fine on my local machine when I run these two docker commands:

docker build -t myApp .

docker run -it --rm -p 8080:8080 --name myApp-container myApp

When I run a bash shell in the container on my local machine I see the app folder and my app is there. On Azure the app folder does not exist.

Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base

WORKDIR /app

EXPOSE 8080

EXPOSE 4430

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

WORKDIR /src

COPY ["myApp.csproj", "./"]

RUN dotnet restore "myApp.csproj"

COPY . .

RUN dotnet build "myApp.csproj" -c Release -o /app/build

FROM build AS publish

RUN dotnet publish "myApp.csproj" -c Release -o /app/publish

FROM base AS final

WORKDIR /app

COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "myApp.dll"]

azure-pipeline.yml:

# Docker

# Build and push an image to Azure Container Registry

# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

trigger:

- master

resources:

- repo: self

variables:

  # Container registry service connection established during pipeline creation

  azureSubscription: 'All Azure Services'

  appName: 'myApp'

  dockerRegistryServiceConnection: '12345'

  imageRepository: 'pipelinesdotnetcoredocker'

  containerRegistry: 'myRepo.azurecr.io'

  dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'

  tag: '$(Build.BuildId)'

  # Agent VM image name

  vmImageName: 'ubuntu-latest'

stages:

- stage: Build

  displayName: Build and push stage

  jobs:

  - job: Build

	displayName: Build

	pool:

	  vmImage: $(vmImageName)

	steps:

	- task: Docker@2

	  displayName: Build and push an image to container registry

	  inputs:

		command: buildAndPush

		repository: $(imageRepository)

		dockerfile: $(dockerfilePath)

		containerRegistry: $(dockerRegistryServiceConnection)

		tags: |

		  $(tag)

		  latest

# - stage: Deploy

#   displayName: Deploy stage

#   dependsOn: Build

#   jobs:

#   - deployment: Deploy

#     displayName: Deploy job

#     pool:

#       vmImage: 'ubuntu-latest'

#     environment: 'production'

#     strategy:

#       runOnce:

#         deploy:

#           steps:

	- task: AzureWebAppContainer@1

	  displayName: 'Azure Web App on Container Deploy'

	  inputs:

		azureSubscription: $(azureSubscription)

		appName: $(appName)

		containers: $(containerRegistry)/$(imageRepository):$(tag)

		containerCommand: 'dotnet myApp.dll'
Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
716 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.