Dockerize asp.net v2
I have an asp.net(web-form) project, which is version 2. Can I make this project Dockerize? If you can, please help
See also questions close to this topic
-
Merge 2 Datatable using Full Outer Join in C#
I need to merge/join datatables on C# with a common column.
I have checked multiple examples but the expected output is not coming. I have created sample dotnet fiddle for the issue which im facing
https://dotnetfiddle.net/WGDL9R
Below is the example
Table1
Account# | Day01 1234 | 11 4567 | 22 4909 | 33
Table2
Account# | DummyColumn 1234 | 12 1234 | 34 4909 | 99
Table3
Account# | DummyColumn 1234 | 13 7777 | 44
Expected Outcome Merged Table
Table1
Account# | Day01 | Day02 | Day03 1234 | 11 | 12 | 13 1234 | 11 | 34 | 13
Note : Rest column are skipped
I can able to take output as per SQL but im getting data separately in datatables for below query
e.g. Datatable1 = select Code from Employeedetail where Id=79603
Datatable2 = select B.Name from EmployeeFamilyDetails where Employeeid=79603I need to merge all datatables into one with Full Outer Join
Example SQL Query :
select Code,Email,B.Name,C.Name from Employeedetail A Full Outer join EmployeeFamilyDetails B on A.ID = B.Employeeid Full Outer join EmployeeNomineeDetail C on A.ID = C.Employeeid where B.Employeeid=79603 and A.Id=79603 and C.Employeeid=79603
-
C# MVC ASP.net ,facing slowness in loop task after time of starting
when i create any function that have to read from excel and then do some algorism on the data then write the result in the database ,
in the start of excitation the loop is working in very fast time ,but after a while it git slow and slow ,
please i need help .
-
how to get all controls of aspx page without running in browser
I have aspx page which may controls. I want get all controls of aspx page without running into browser. Means by taking physical path, I want to get list of all controls from aspx.
for example - I have following aspx page and I want to get all controls(textbox and label) and their attributes.
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %> <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </asp:Content>
-
Dynamic configuration not set for Nginx Plus running in Docker container
I am trying to set my Nginx Plus component into a Docker container and trying to set the Dynamic configuration at the time
Code Snippet of my Nginx Plus config parameters
server { access_log /var/log/nginx/api_access.log main; listen ${NGINX_PORT}; server_name ${NGINX_SERVER};
Code Snippet of environment file
NGINX_PORT=80 NGINX_SERVER=0.0.0.0
Command to run the docker container with the above env. file from my local images
docker run --name container_name -dp 8080:80 --env-file ./.env.example Image_name
Getting the below error and container is getting stopped
2021/03/09 07:04:24 [emerg] 1#1: host not found in "${NGINX_PORT}" of the "listen" directive in /etc/nginx/api_gateway.conf:7 nginx: [emerg] host not found in "${NGINX_PORT}" of the "listen" directive in /etc/nginx/api_gateway.conf:7
-
Dockerfile: Does it matter how I clean my build?
Is there a difference (when it comes to image size) between
RUN make && make clean
and
RUN make RUN make clean
Not sure how Docker works, but will the latter create an unnecessary layer?
-
Run multiple neo4j instances on ubuntu-18.4 machine with different ports
I need to create 3 instances of neo4j on single ubuntu-18.4 machine , with 3 different ports . I tried changing default_database setting in neo4j.conf file but of no use . Can i do it without using docker ? . Thanks in advance
-
Django + Docker - Server Error 500. Long Post
I am currently trying to get my Django application ready for deployment. I am trying to 'dockerize' my application by creating an image of my application using docker, dockerfile and uwsgi. I can do this with the following command:
sudo docker create --name container --network network --network-alias container -t -p 40001:8001 image_name docker build -t image_name .
The image gets built, I can start it and I can access the home page of the containerised application. However, when I try to navigate to other pages within the application, i get a Server Error (500) and in the console (Firefox), i get this error:
The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.
I have this in my base.html:
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <meta content="utf-8">
And every webpage extends this page.
I believe this could be an issue with my static files configuration as I am using WhiteNoise. But I was having issues with my dockerfile and uwsgi.ini file.
settings.py
""" Django settings for LisgreyWebApp_FYP project. Generated by 'django-admin startproject' using Django 3.1.5. For more information on this file, see https://docs.djangoproject.com/en/3.1/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.1/ref/settings/ """ import os import socket from pathlib import Path from whitenoise.storage import CompressedManifestStaticFilesStorage import docker_config # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = docker_config.SECRET_KEY # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'LisgreyWebApp', 'reservations', 'takeaway', 'food_menus', 'crispy_forms', 'bootstrap4', 'corsheaders' ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'corsheaders.middleware.CorsMiddleware', ] ROOT_URLCONF = 'LisgreyWebApp_FYP.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR / 'templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'LisgreyWebApp_FYP.wsgi.application' # Database # https://docs.djangoproject.com/en/3.1/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'lisgrey_database', 'USER': 'postgres', 'PASSWORD': 'password', 'HOST': '127.0.0.1', 'PORT': '25432' } } # Password validation # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] CRISPY_TEMPLATE_PACK = 'bootstrap4' CRISPY_FAIL_SILENTLY = not DEBUG BOOTSTRAP4 = { 'include_jquery': True, } LOGIN_REDIRECT_URL = 'home' LOGOUT_REDIRECT_URL = 'home' # new # Internationalization # https://docs.djangoproject.com/en/3.1/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = False USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.1/howto/static-files/ # Add this line to access static files on templates STATIC_URL = "/static/" STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), ) STATIC_ROOT = os.path.join(BASE_DIR, 'dist') STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' TIME_INPUT_FORMATS = [ '%H:%M %p' ] DATE_INPUT_FORMATS = [ '%d-%m-%Y' ]
Dockerfile
## ## Dockerfile to generate a Docker image from a GeoDjango project ## # Start from an existing image with Python 3.8 installed FROM python:3.8 # Run a series of Linux commands to ensure that # 1. Everything is up-to-date and # 2. Install GDAL RUN apt-get -y update && apt-get -y upgrade && apt-get -y install libgdal-dev # Make a working directoir in the image and set it as working dir. RUN mkdir -p /usr/src/app WORKDIR /usr/src/app # make sure that pip & setuptools are installed and to date RUN pip install --upgrade pip setuptools wheel # Get the following libraries. We caan install them "globally" on the image as it will contain only our project RUN apt-get -y install build-essential python-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info # You should have already exported your Python library reuirements to a "requiremnts.txt" file using pip. # Now copy this to the image and install everything in it. COPY requirements.txt /usr/src/app RUN pip install -r requirements.txt # Copy everything in your Django project to the image. COPY . /usr/src/app # Make sure that static files are up to date and available RUN python manage.py collectstatic --no-input # Expose port 8001 on the image. We'll map a localhost port to this later. EXPOSE 8001 # Run "uwsgi". uWSGI is a Web Server Gateway Interface (WSGI) server implementation that is typically used to run Python # web applications. CMD ["uwsgi", "--ini", "uwsgi.ini"]
uwsgi.ini
[uwsgi] #======================= # DO NOT EDIT THIS FILE #======================= # chdir to the folder of this config file chdir = %d # %d is the dir this configuration file is in #socket = %dapp.sock http = :8001 # load the module from wsgi.py, it is a python path from # the directory above. module = LisgreyWebApp_FYP.wsgi:application # LisgreyWebApp_FYP.wsgi:application # allow anyone to connect to the socket (666). This is very permissive chmod-socket=664 master = true processes = 4 vacuum = true enable-threads = true #harakiri = 30 #threads = 2
Container logs
**
[uWSGI] getting INI configuration from uwsgi.ini *** Starting uWSGI 2.0.19.1 (64bit) on [Fri Mar 5 18:59:51 2021] *** compiled with version: 8.3.0 on 05 March 2021 15:28:29 os: Linux-5.8.0-44-generic #50-Ubuntu SMP Tue Feb 9 06:29:41 UTC 2021 nodename: ebc63a00d1a7 machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 8 current working directory: /usr/src/app detected binary path: /usr/local/bin/uwsgi uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** chdir() to /usr/src/app/ your memory page size is 4096 bytes detected max file descriptor number: 1048576 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uWSGI http bound on :8001 fd 4 uwsgi socket 0 bound to TCP address 127.0.0.1:33037 (port auto-assigned) fd 3 uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** Python version: 3.8.8 (default, Feb 19 2021, 17:55:44) [GCC 8.3.0] Python main interpreter initialized at 0x559f4a88c290 uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** python threads support enabled your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 364600 bytes (356 KB) for 4 cores *** Operational MODE: preforking *** WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x559f4a88c290 pid: 1 (default app) uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** *** uWSGI is running in multiple interpreter mode ***
**
-
How to handle redirection between docker container services?
I'm trying to introduce docker for local development into an existing project.
I have two services A (previously being run on
localhost:5000
) & B (previously being run onlocalhost:5001
). A is a login application whereas B is the main application. A takes the username/password from the user, validates credentials & if valid, redirects the user to appropriate service B's entry point i.e.localhost:5001/<user_role>
from where application B takes over.When running without docker, this redirection between services works fine. But when using docker and running the projects, this redirection breaks (except when I use
host
network driver). I can access service A, login successfully but when the redirection happens, the browser's address bar shows the redirected entry point of service B and the browser says "The site can't be reached" and the request fails.Here are my docker files:
Service A
Run as:
docker run -p 5000:5000 --name service_a_1 service_a
FROM node:10 WORKDIR /home/node/serviceA COPY ./package*.json ./ RUN npm install COPY . . CMD ["npm", "start"] EXPOSE 5000
Service B
Run as:
docker run -p 5001:5001 --name service_b_1 service_b
FROM node:10 WORKDIR /home/node/serviceB COPY ./package*.json ./ RUN npm install COPY . . CMD ["npm", "start"] EXPOSE 5001
But when I use
--network=host
when running these containers, the redirection works fine but it fails with abridge
network driver. I have done my research going through the docker's documentation on networking and some tutorials on docker networking.Questions:
- Can the behavior that I want be achieved using
bridge
network? - Why is it not working for
bridge
network driver but works onhost
?
- Can the behavior that I want be achieved using
-
How to connect docker container .net core 3.1 to container sql server?
I have two containers running in docker, one is a web api .net core 3.1 and the other is a sql server. The two containers are already running. The api container does not connect with the sql one. the two containers are in the same, I tried pinging from one container to another with the ip of each container and if there is a connection.
This is my docker File:
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base WORKDIR /app EXPOSE 80 FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build WORKDIR /src COPY ./*/*.csproj ./ RUN dotnet restore ./ApiDigitalGamesMx.csproj COPY ./*/ApiProducts.Library.csproj ./ RUN dotnet restore ./ApiProducts.Library.csproj COPY . . RUN dotnet build ./*/ApiDigitalGamesMx.csproj -c Release -o /app/build RUN dotnet build ./*/ApiProducts.Library.csproj -c Release -o /app/build FROM build AS publish RUN dotnet publish ./*/ApiDigitalGamesMx.csproj -c Release -o /app/publish RUN dotnet publish ./*/ApiProducts.Library.csproj -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "ApiDigitalGamesMx.dll"]
This is in my appsetting.json of the api:
"CadenaConexion": "Server=172.17.0.3,1433;Database=DigitalGamesMx;User ID=sa;Password=5q1@dw1UMTI3;Trusted_Connection=True;MultipleActiveResultSets=true",
And this is the docker bridge:
"Containers": { "10baecd38b02aac4732443c29344a6c50397c6ee9435935be8314ecb27867338": { "Name": "ApiNetCore", "EndpointID": "7888882053be9ce02cc9c5f5d7e8c9d647b478cd097915e66841bae083ec9e4a", "MacAddress": "02:42:ac:11:00:02", "IPv4Address": "172.17.0.2/16", "IPv6Address": "" }, "6d0c4886376fcf23d4fc50bcf69811a416599e2830200f531256ba25125bea73": { "Name": "MSSQL-Container", "EndpointID": "9d1a4d5fabdc8bf839200a19079cc5d78778aa3695d931847e9b3819b7a2c880", "MacAddress": "02:42:ac:11:00:03", "IPv4Address": "172.17.0.3/16", "IPv6Address": "" }