Docker
The documentation applies to: v0.8.0
Deployment Model¶
Docker is very popular nowaday, it helps us to create container to ship everywhere. So we strongly recommend you to learn about Docker and Kubernetes and deploy all services on Docker.
In this docs, we only brief How to deploy on Docker on single VM. For deployment on Kubernetes or Docker Swarm, it is out-of-the-box.
Some domain names are below:
- Identity APIs:
lp.identityapi
- Portal APIs:
lp.portalapi
- Service Management APIs:
lp.servicemangement
- Gateway:
lp.gateway
- Chat APIs:
lp.chatapi
- MongoDB:
mongodb
SPA Web and MongoDB
SPA Web is static web that will be served by Nginx, so that you just deploy same as this article.
For MongoDB, if you don't want to host on Docker Container, you can remove it and change some DatabaseOptions on each service
Configuration changes¶
SPA Web¶
Publish Command: npm run docker
Location: src\web-portal\src\environments\environment.docker.ts
Changes:
export const environment = {
production: true,
version: "0.0.5",
configurationEndpoint: "http://{Your_public_domain}:8080/v1.0/api/configurations/Portal/v1.0",
ignoreSendTokenEndpoints: "api/accounts/login;api/accounts/refresh;api/accounts/forgot-password;api/accounts/recovery-password",
chatOptions: {
allowFileTypes: 'jpg;jpeg;gif;png;zip;rar;doc;docx;xls;xlsx;pdf',
maxFileSizeInMb: 16
}
};
Portal Configuration file¶
Location: src\web-apis\LetPortal.ServiceManagementApis\Files\Portal\v1.0\appsettings.Docker.json
Changes:
{
"portalBaseEndpoint": "http://{Your public domain}:8080/v1.0",
"chatBaseEndpoint": "http://{Your public domain}:8082",
"identityBaseEndpoint": "http://{Your public domain}:8081"
}
Portal APIs Configuration file¶
Location: src\web-apis\LetPortal.WebApis\appsettings.Docker.json
Changes:
{
"FileOptions": {
"DownloadableHost": "http://{Your_public_domain}:8080/v1.0/files
}
}
Gateway¶
Location: src\web-apis\LetPortal.Gateway\appsettings.Docker.json
Changes:
{
"GlobalConfiguration": {
"BaseUrl": "http://{Your_public_domain}:8080/"
}
}
Run docker compose¶
By default, all services have Dockerfile
which locates in project folder, you can open and edit if you want to upgrade .NET Core framework.
Now a simplest command to bring all services up is
``` bash tab="Production" docker-compose up
``` bash tab="Production Local"
docker-compose -f docker-compose.local.yml up
Production Local
As we said on Multiple Environments section, Production Local iss using for accessing from Host or intranet.
Then you open a new tab and check
docker ps
The result must be
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
68a82dd76eda lp-identityapi:0.0.5 "dotnet LetPortal.Id…" About a minute ago Up About a minute 0.0.0.0:5143->80/tcp web-apis_lp.identityapi_1
4be21f2b7bdc lp-portalapi:0.0.5 "dotnet LetPortal.Po…" About a minute ago Up About a minute 0.0.0.0:5144->80/tcp web-apis_lp.portalapi_1
c8f8754082b3 lp-gateway:0.0.5 "dotnet LetPortal.Ga…" About a minute ago Up About a minute 0.0.0.0:5142->80/tcp web-apis_lp.gateway_1
14aff59977e2 lp-servicemangement:0.0.5 "dotnet LetPortal.Se…" About a minute ago Up About a minute 0.0.0.0:5141->80/tcp web-apis_lp.servicemangement_1
33ea14e1d71f mongo:latest "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:27117->27017/tcp web-apis_mongodb_1
How to expose with Nginx¶
After you run all services on Docker, you want to change a minor configuration on Nginx to help to expose Gateway and Identity to serve.
If you don't change anything, there are IPs of services that you want to change on nginx.conf
.
- Identity APIs: 5143
- Gateway APIs: 5142
So nginx.conf
must be
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
#access_log /var/log/nginx/access.log;
#error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 8080;
server_name _;
access_log /etc/nginx/logs/api.access.log;
error_log /etc/nginx/logs/api.error.log;
location / {
proxy_pass http://localhost:5142;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection keep-alive;
#proxy_set_header Host $host;
#proxy_cache_bypass $http_upgrade;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 8081;
server_name _;
#access_log /etc/nginx/logs/ids.access.log;
#error_log /etc/nginx/logs/ids.error.log;
location / {
proxy_pass http://localhost:5143;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection keep-alive;
#proxy_set_header Host $host;
#proxy_cache_bypass $http_upgrade;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;
}
}
}