Images/css/js files not available on docker container - asp.net

I'm learning microservice concept and using Docker for these purposes.
I have 3 containers:
mssqlserver - my database
asp-net-core:2.0 - for my microservice (only 1 at the moment)
asp-net-core:2.0 - MVC
Connection exists between these so this isn't a cause of the problem.
MVC contains wwwroot directory where images (banners etc.), css and .js files are placed. I've checked they are on my docker container (ran /bin/bash on container and checked).
But somehow my .cshtml files can't see these files.
Dockerfile for MVC project:
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 80/tcp
ENTRYPOINT ["dotnet", "MVC.dll"]
docker-compose:
version: "3.2"
networks:
frontend:
backend:
services:
webmvc:
build:
context: .\src\Web\MVC
dockerfile: Dockerfile
environment:
- ASPNETCORE_ENVIRONMENT=Development
- CatalogUrl=http://catalog
container_name: webshop
ports:
- "5500:80"
networks:
- frontend
depends_on:
- catalog
catalog:
build:
context: .\src\Services\ProductCatalogApi
dockerfile: Dockerfile
image: microservices-v1.0.0
environment:
- DatabaseServer=mssqlserver
- DatabaseName=CatalogDb
- DatabaseUser=sa
- DatabaseUserPassword=ProductApi(!)
container_name: catalogapi
ports:
- "5000:80"
networks:
- backend
- frontend
depends_on:
- mssqlserver
mssqlserver:
image: "microsoft/mssql-server-linux:latest"
ports:
- "2200:1433"
container_name: mssqlcontainer
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=ProductApi(!)
networks:
- backend
Example use of image (in Index.cshtml):
<img src="~/images/banner.jpg" alt="ASP.NET" class="img-responsive" />
I've tried differenet combination of path to image like:
<img src="wwwroot/images/banner.jpg" alt="ASP.NET" class="img-responsive" />
<img src="~/app/wwwroot/images/banner.jpg" alt="ASP.NET" class="img-responsive" />
<img src="app/wwwroot/images/banner.jpg" alt="ASP.NET" class="img-responsive" />
None of these worked.

Most likely you failed to enable the static files middleware in your ASP.NET Core project. In Startup.Configure, you need the line:
app.UseStaticFiles();
That will serve up wwwroot, by default, as the document root of your site, so you would then reference in static files under that via:
<img src="~/images/banner.jpg" />
Which would correspond to the file at wwwroot/images/banner.jpg.

Related

docker-compose doesn't work from Visual Studio

I have three web projects in one solution, they work together on gRPC. I am trying to bring all three projects up with docker-compose, but the problem is when the command
docker-compose up --build
This is how everything works, but when I try to start using the Visual Studio interface with a debugger connected, it does not work
When you run the application via docker-compose in Visual Studio, then when you start the containers themselves, an error appears with the following content:
Can't find a program for debugging in the container
And then it immediately pops out this:
The target process exited without raising an event fired by CoreCLR. Make sure the target process is configured to use .NET Core. This may be necessary if the target process has not started in .NET Core.
This message appears in the container logs:
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
* You intended to execute a .NET program:
The application '/app/bin/Debug/net5.0/Votinger.Gateway.Web.dll' does not exist.
* You intended to execute a .NET SDK command:
It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
https://aka.ms/dotnet-download
This is a Dockerfile which is auto-generated by Visual Studio, it is the same for every project except for the paths to the project
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 5000
EXPOSE 5001
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Votinger.Gateway/Votinger.Gateway.Web/Votinger.Gateway.Web.csproj", "Votinger.Gateway/Votinger.Gateway.Web/"]
RUN dotnet restore "Votinger.Gateway/Votinger.Gateway.Web/Votinger.Gateway.Web.csproj"
COPY . .
WORKDIR "/src/Votinger.Gateway/Votinger.Gateway.Web"
RUN dotnet build "Votinger.Gateway.Web.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Votinger.Gateway.Web.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
FROM mcr.microsoft.com/dotnet/sdk:5.0
ENTRYPOINT ["dotnet", "Votinger.Gateway.Web.dll"]
docker-compose.yml
version: '3.4'
services:
votinger.authserver.db:
image: mysql:8
container_name: Votinger.AuthServer.Db
restart: always
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
votinger.pollserver.db:
image: mysql:8
container_name: Votinger.PollServer.Db
restart: always
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
votinger.authserver.web:
image: ${DOCKER_REGISTRY-}votingerauthserverweb
container_name: Votinger.AuthServer.Web
build:
context: .
dockerfile: Votinger.AuthServer/Votinger.AuthServer.Web/Dockerfile
links:
- votinger.authserver.db:authdb
votinger.gateway.web:
image: ${DOCKER_REGISTRY-}votingergatewayweb
container_name: Votinger.Gateway.Web
build:
context: .
dockerfile: Votinger.Gateway/Votinger.Gateway.Web/Dockerfile
ports:
- 5000:5000
links:
- votinger.authserver.web:authserver
- votinger.pollserver.web:pollserver
votinger.pollserver.web:
image: ${DOCKER_REGISTRY-}votingerpollserverweb
container_name: Votinger.PollServer.Web
build:
context: .
dockerfile: Votinger.PollServer/Votinger.PollServer.Web/Dockerfile
links:
- votinger.pollserver.db:polldb
docker-compose.override.yml
version: '3.4'
services:
votinger.authserver.web:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:5000;http://+:5001
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/https:ro
votinger.gateway.web:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:5000;http://+:5001
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/https:ro
votinger.pollserver.web:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:5000;http://+:5001
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/https:ro
I will also post a link to GitHub where this project is located
(dev branch)
https://github.com/SeanWoo/Votinger
I will forgive your help
I found a solution, the problem was that in the docker-compose.vs.debug.yml file is generated by Visual Studio, full paths to the project and debugger are indicated there, and my path went through a folder named as C #, and Visual Studio decided to calculate the symbol # unnecessary and deleted it, it turned out to be a path with the C folder, which led to a completely different place

How to configure nginx proxy inside a docker-compose?

I want to configure client_max_body_size of a dockerized nginx proxy directly inside the docker-compose.yml.
I find this ressources : https://github.com/nginx-proxy/nginx-proxy/issues/690,but it seems none of the solution are adapted.
Here is my docker-compose.yml (version: '3.7') :
web-proxy:
container_name: test-proxy
image: nginxproxy/nginx-proxy
depends_on:
- web
volumes:
- /nginx/conf:/etc/nginx/conf.d
- /nginx/vhost:/etc/nginx/vhost.d
- /nginx/html:/usr/share/nginx/html
- /nginx/dhparam:/etc/nginx/dhparam
- /nginx/certs:/etc/nginx/certs:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
ports:
- 80:80
- 443:443
Alternative way should be to add an aditional configuration file in the volume already mounted, but I would prefer configuring it entirely inside the docker-compose file.
this is from the image docs Custom Nginx Configuration:
Proxy-wide
To add settings on a proxy-wide basis, add your configuration file under /etc/nginx/conf.d using a name ending in .conf.
This can be done in a derived image by creating the file in a RUN command or by COPYing the file into conf.d:
FROM nginxproxy/nginx-proxy
RUN { \
echo 'server_tokens off;'; \
echo 'client_max_body_size 100m;'; \
} > /etc/nginx/conf.d/my_proxy.conf

running dotnet docker container with docker-compose

I have gone through the documentation but running across issues as I'm launching the containers through docker-compose.
I'm using docker-compose because I have more than one containers that directly correlates to each csproj file within the location, also the docs refer to attributes using Dockerfile which itself adds another layer of complexity.
docker-compose.yml
version: '3'
services:
app1:
image: mcr.microsoft.com/dotnet/core/sdk:2.2
container_name: app1
restart: on-failure
working_dir: /service
command: bash -c "dotnet build && dotnet bin/Debug/netcoreapp2.2/App1.dll"
ports:
- 5001:5001
- 5000:5000
volumes:
- "./App1:/service"
app2:
image: mcr.microsoft.com/dotnet/core/sdk:2.2
container_name: app2
restart: on-failure
working_dir: /service
command: bash -c "dotnet build && dotnet bin/Debug/netcoreapp2.2/App2.dll"
ports:
- 5001:5001
- 5000:500
Project Structure
Microservice.sln
App1/App1.csproj
App2/App2.csproj
Issue
My IDE starts to complain as soon as I run the containers for all kinds of syntax errors, and a local build simply fails.
is there a way to be able to compile the app locally as well as in the docker?
Edit

docker is not allowing to mount a directory into a drupal container

I am doing something very simple puting drupal in a docker container
volumes:
- /c/Users/mark/drupalb/sites/all/modules:/var/www/html/sites/all/modules
this directive which should mount home directory of my modules into the containers module directory doesnt work this seems like thing that people do everyday but how to resolves this
Not clear what your problem is. In the meantime here's a working drupal example
Example
The folowing compose file
└── docker-compose.yml
Runs two containers, one for drupal the other for the db:
$ docker volume create --name drupal_sites
$ docker-compose up -d
$ docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------
dockercompose_db_1 docker-entrypoint.sh mysqld Up 3306/tcp
dockercompose_web_1 apache2-foreground Up 0.0.0.0:8080->80/tcp
Note how the volume used to store the drupal sites is created separately, defaults to local storage but can be something more exotic to fit your needs
docker-compose.yml
version: '2'
services:
db:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=letmein
- MYSQL_DATABASE=drupal
- MYSQL_USER=drupal
- MYSQL_PASSWORD=drupal
volumes:
- /var/lib/mysql
web:
image: drupal
depends_on:
- db
ports:
- "8080:80"
volumes:
- drupal_sites:/var/www/html/sites
- /var/www/private
volumes:
drupal_sites:
external: true

Docker - wordpress deployed on Digital Ocean Droplet - where is the wp-content?

Testing the Docker eco-system, I deployed my containers with docker-compose on a Digital Ocean droplet (created with docker-machine..) it's running fine
the docker-compose.yml file is quite simple, using standard images
web:
image: wordpress
links:
- mysql
environment:
- WORDPRESS_DB_PASSWORD=password
ports:
- "80:80"
working_dir: /var/www/html
volumes:
- wp-content/:/var/www/html/wp-content
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=wordpress
I can easily query the droplet url in my browser.
When I ssh into the droplet, I am searching for the wp-content folder in the droplet host, which is mounted as /usr/www/html/wp-content but I cannot find it... also the /var/www/html directory is empty... but the wordpress container is running
Where am I wrong ?
wrong path for volumes wp-content and wrong search in remote host ..
need to run :
docker exec -it bash to lsit files in container ....

Resources