Understanding docker-compose of VS2017 webform application - asp.net

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...

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

Running dotnet watch run in docker container breaks Nuget package references

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"'

I am trying to configure nginx as proxy server but getting an error while composing docker file

I am trying to configure nginx as proxy server but getting an error. I have created below file as part of my work.
DockerFile
FROM nginx:1.10.1-alpine
RUN rm /etc/nginx/conf.d/*
COPY proxy.conf /etc/nginx/conf.d/
Proxy.config
server {
listen 80;
location / {
proxy_pass http://app;
}
}
docker-compose.yml
version: '2'
services:
app:
build: app
proxy:
build: proxy
ports:
- "80:80"
When I build docker-compose file I am getting following error:
Puja:Docker pujadudhat$ docker-compose build
Building app
Step 1/2 : FROM nginx:1.10.1-alpine
---> 2cd900f340dd
Step 2/2 : COPY index.html /usr/share/nginx/html
---> Using cache
---> 9d105a18fb9d
Successfully built 9d105a18fb9d
Building proxy
Step 1/3 : FROM nginx:1.10.1-alpine
---> 2cd900f340dd
Step 2/3 : RUN rm /etc/nginx/conf.d/*
---> Using cache
---> a4e1efc3f050
Step 3/3 : COPY proxy.conf /etc/nginx/conf.d/
ERROR: Service 'proxy' failed to build: lstat proxy.conf: no such file or directory
I am getting this error "Service 'proxy' failed to build: lstat proxy.conf: no such file or directory. Can anyone help me to solve? Thank you.n
Looks like you are missing the proxy.conf in your project where you build the docker container. It looks like you have it named Proxy.conf and it should be named proxy.conf.

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.

Resources