Running dotnet watch run in docker container breaks Nuget package references - asp.net

I have a docker-compose file where I start the database and the asp.net server with dotnet watch run like this:
backend:
image: mcr.microsoft.com/dotnet/sdk:6.0
depends_on:
- db
environment:
DB_HOST: db
DB_NAME: db
DB_USERNAME: ${DB_USER}
DB_PASSWORD: ${DB_PW}
ASPNETCORE_ENVIRONMENT: Development
ports:
- 7293:7293
volumes:
- ./:/app
working_dir: /app
command: 'dotnet watch run --urls "http://0.0.0.0:7293"'
As you can see I mount the entire project directory in the container.
Now this runs fine and reloads on changes.
But as soon as the container starts in Visual Studio all the references to Nuget packages get marked red and can't be resolved anymore.
There is a .dockerignore file but I don't think anything in here is really relevant. But here is it anyways:
.dockerignore:
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
I know this has something to do with project restore but nothing I tried helped. --no-restore made it just not run at all with an exception that it couldn't find the reference to one of the packages.
Any ideas how to avoid this?

Ok I figured it out. Mounting Apperently doesn't care about .dockerignore. I have to exclude the obj directory in the mount. So I just mount a empty directory like this.
backend:
...
volumes:
- ./:/app
- /app/obj # <- directory won't be mounted
working_dir: /app
command: 'dotnet watch run --urls "http://0.0.0.0:7293"'

Related

Using Github Action to build Docker image with ASP.Net Framework 4.8 application throws "Windows does not support privileged mode"

I need to build a Docker image for Windows platform containing an ASP.Net Framework 4.8 application using Github Action.
In build step, it throws an error
Building Docker image *** with tags latest...
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
#1 [internal] booting buildkit
#1 pulling image moby/buildkit:buildx-stable-1
#1 pulling image moby/buildkit:buildx-stable-1 0.2s done
#1 creating container buildx_buildkit_builder-b7ba0de1-52b2-435b-aa7d-8311039928160 done
#1 ERROR: Error response from daemon: Windows does not support privileged mode
------
> [internal] booting buildkit:
------
ERROR: Error response from daemon: Windows does not support privileged mode
In the post
Github Action for Windows platform "Windows does not support privileged mode"
the author says he solved the problem by changing the build action to mr-smithers-excellent/docker-build-push#v5 but it didn't work for me.
My script:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v3
- name: Setup MSBuild
uses: microsoft/setup-msbuild#v1
- name: Docker Setup Buildx
uses: docker/setup-buildx-action#v2.0.0
with:
install: true
- name: Build Docker images
uses: mr-smithers-excellent/docker-build-push#v5.8
with:
image: ******
tags: latest
registry: *****
dockerfile: *****
My Dockerfile
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
cmd

Understanding docker-compose of VS2017 webform application

I'm creating a Webform application that I try to containerize.
I use VS2017, create the default webform app, and add docker support.
If I F5 the application, it's working (hopefully)
The "add docker support" adds many files :
1) a Dockerfile, with
FROM microsoft/aspnet:4.6.2
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
I understand it's based on the aspnet:4.6.2 image and that it copy the files from obj/docker/publish to put them in the container.
My problem is that I have no files published on this directory. Of course if I docker build, I have an error (it can't find files in obj/docker/publish). Remember, with F5 it's working.
But there's additionnal files.
2) Docker-compose.yml :
version: '3'
services:
legacywebapp:
image: legacywebapp
build:
context: .\LegacyWebApp
dockerfile: Dockerfile
If I understand well, it creates a legacywebapp services based on the dockerfile. The one that is not working, and still no "obj/docker/publish"
3) docker-compose.override.yml with :
version: '3'
services:
legacywebapp:
ports:
- "80"
networks:
default:
external:
name: nat
Ok, I assume it exposes the port 80 (why not in the first file ? but anyway, for modularity it's better I suppose).
If I try
docker-compose -f .\docker-compose.yml -f .\docker-compose.override.yml build
of course I have an error :
Step 4/4 : COPY ${source:-obj/Docker/publish} .
ERROR: Service 'legacywebapp' failed to build: COPY failed: GetFileAttributesEx \\?\C:\windows\TEMP\docker-builder798755009\obj\Docker\publish: The system cannot find the file specified.
Why is it working when I F5 in visual studio ? Let's look in the build output of VS, I can see the command line :
docker-compose -f "C:\Users\...\docker-compose.yml" -f "C:\Users\...\docker-compose.override.yml" -f "C:\Users\...\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose15539612722162891187 up -d --build
So, there's another file, I suppose for debugging :
4) docker-compose.vs.debug.g.yml
version: '3'
services:
legacywebapp:
image: legacywebapp:dev
build:
args:
source: obj/Docker/empty/
volumes:
- C:\Users\...\LegacyWebApp:C:\inetpub\wwwroot
- C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Remote Debugger:C:\remote_debugger:ro
labels:
com.microsoft.visualstudio.debuggee.program: "C:\\app\\bin/LegacyWebApp.dll"
com.microsoft.visualstudio.debuggee.workingdirectory: "C:\\app"
And again, no obj/docker/publish. What is the obj/Docker/empty/ ?
How can I build correctly the image ? For example if I want to publish it in a private repository...

Oci runtime error docker-compose not a directory

I am new to docker and currently struggling with the following problem:
After starting the command in the docker terminal:
OAUTH_CLIENT_ID=<...> OAUTH_CLIENT_SECRET=<...>
OAUTH_URL_CALLBACK=http://192.168.99.100/api/v1/auth/login docker-compose --
file test/docker-compose.yml up
I get the following error message:
ERROR: for platform Cannot start service platform: invalid header field
value "oci runtime error: container_linux.go:247: starting container process
caused \"process_linux.go:359: container init caused \\\"rootfs_linux.go:53:
mounting \\\\\\\"/c/users/m_konk01/documents/GitHub/o2r-
platform/test/nginx.conf\\\\\\\" to rootfs
\\\\\\\"/mnt/sda1/var/lib/docker/aufs/mnt/29c14c514916cf09070c6dd084bee55fa899d9
79b3f7b9521f1ab25e3a8232a0\\\\\\\" at
\\\\\\\"/mnt/sda1/var/lib/docker/aufs/mnt/29c14c514916cf09070c6dd084bee55fa899d9
79b3f7b9521f1ab25e3a8232a0/etc/nginx/nginx.conf\\\\\\\" caused \\\\\\\"not
a directory\\\\\\\"\\\"\"\n" [31mERROR[0m: Encountered errors while bringing up the project.
The docker-compose.yml starts several docker containers and contains the following platform settings:
platform:
image: nginx:latest
depends_on:
- container1
- container2
- container3
- container4
volumes:
- "./nginx.conf:/etc/nginx/nginx.conf:ro"
- "../client:/etc/nginx/html"
ports:
- "80:80"
Docker version
$ docker version
Client:
Version: 1.12.3
API version: 1.24
Go version: go1.6.3
Git commit: 6b644ec
Built: Wed Oct 26 23:26:11 2016
OS/Arch: windows/amd64
Server:
Version: 1.12.3
API version: 1.24
Go version: go1.6.3
Git commit: 6b644ec
Built: Wed Oct 26 23:26:11 2016
OS/Arch: linux/amd64
Would be happy for any ideas. My search was not successful so far.
it seems like you want to mount a file to a file. i remember on your docker-version its not allowed. you have to move your nginx.conf inside of your Dockerfile
Dockerfile:
....
ADD nginx.conf /tmp/
RUN mv /tmp/nginx.conf /etc/nginx/nginx.conf && \
....
this should work for you. if not show me your next error code
I faced similar issue due to volume mount was not worked properly.
So docker default behavior consider this /nginx.conf as directory and gives this error.
To confirm this, you can ssh into your image and go to shared directory and check the files exist or not.
Example: docker exec -it nginx sh and go to /etc/nginx/html you won't see your local files. Then you can confirm volume share was not working. you need to fix that.
If you are using windows 10 (hyper-v), first you need to share your drive and check.
However you need to find the solution to mound your shared directory first.

Container command could not be invoked

Just encountered this error message while trying to bring up a docker-compose stack on my local machine. I have a Dockerfile which is identical to the official Wordpress image. My docker-compose file looks like this:
wordpress:
image: joystick/wp
ports:
- "8000:80"
links:
- wordpress_db:mysql
environment:
- WORDPRESS_DB_HOST=mysql
- WORDPRESS_DB_NAME=wordpress
- WORDPRESS_DB_USER=admin
- WORDPRESS_DB_PASSWORD=password
wordpress_db:
image: tutum/mysql
environment:
- ON_CREATE_DB=wordpress
- MYSQL_PASS=password
When I change the "image" part at the beginning of this to "wordpress" and use the official image, everything comes up as I'd expect. But when I try to build my own image first, and then use it in this docker-compose file, I get the error message "Container command could not be invoked".
I tried adding a "command" node into the "wordpress" section of this docker-compose, but that did not work.
If you're building from official images, e.g. https://github.com/docker-library/wordpress/tree/master/apache, note the file docker-entrypoint.sh. It must be executable, I set 755 and managed to build the image and run the container.

Lucee 5, Nginx, and Docker Compose not finding sample index.cfm file

I have set up a fairly vanilla Dockerfile to start with, just to see if I can get the sample index.cfm to run:
FROM lucee/lucee-nginx:preview
And the related docker-compose.yml file:
web:
build: .
ports:
- "80:80"
When I run this, I get an Nginx 403 Forbidden error. If I change the ports setting to 80:8080, I get a Tomcat 404 Not Found error.
I'm lost as to how to get this working with Docker Compose. How can I debug this, or is there a different way that I can configure Docker Compose to get it running?
The newer builds of Lucee 5 work (release candidates especially), so this problem has since "sorted itself out."
See the section of the lucee-dockerfiles project for Lucee 5 on Tomcat-8-jre with Nginx.

Resources