使用 Docker 在 Linux 上托管 ASP.NET Core 应用程序
說在前面
在閱讀本文之前,您必須對?Docker?的中涉及的基本概念以及常見命令有一定了解,本文側(cè)重實(shí)戰(zhàn),不會對相關(guān)概念詳述。
同時(shí)請確保您本地開發(fā)機(jī)器已完成如下安裝:
Docker 18.06?或更高版本的 Docker 客戶端
.NET Core SDK 2.2?或更高版本
Visual Studio Code?代碼編輯器,以及?C#?語法插件 1.17.1 或更高版本
注:本文實(shí)驗(yàn)環(huán)境是 Ubuntu 18.04 LTS。如果您的機(jī)器是 Window,也可以把 Docker 裝在虛擬機(jī)或服務(wù)器上。
創(chuàng)建演示項(xiàng)目
開始之前要先準(zhǔn)備一個(gè)需要 Docker 容器化的 ASP.NET Core 應(yīng)用程序,用于下面的操作演示。這里我用?.NET Core CLI?快速搭建一個(gè)全新的 Web API 項(xiàng)目。
啟動 VS Code,打開集成終端,輸入如下命令:
dotnet new webapi -o TodoApicode -r TodoApi
以上便創(chuàng)建了一個(gè)名為TodoApi的 Web API 樣板項(xiàng)目。
打開集成終端,輸入dotnet run命令編譯運(yùn)行程序,然后打開瀏覽器跳轉(zhuǎn)到 URL?http://localhost:5000/api/values,如正常返回如下 JSON 數(shù)據(jù),說明應(yīng)用程序本地成功運(yùn)行。
["value1","value2"]現(xiàn)在讓我們更進(jìn)一步,在 Docker 中構(gòu)建并運(yùn)行該應(yīng)用程序。
創(chuàng)建 Dockerfile 文件
Dockerfile 是一個(gè)文本文件,其用來定義單個(gè)容器的內(nèi)容和啟動行為,按順序包含構(gòu)建鏡像所需的所有指令。Docker 會通過讀取 Dockerfile 中的指令自動構(gòu)建鏡像。
在項(xiàng)目TodoApi根目錄中,創(chuàng)建一個(gè)名為Dockerfile的文件,并粘貼以下內(nèi)容:
FROM microsoft/dotnet:2.2-sdk AS build-envWORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM microsoft/dotnet:2.2-aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "TodoApi.dll"]
FROM指令必須放在第一位,用于初始化鏡像,為后面的指令設(shè)置基礎(chǔ)鏡像。
WORKDIR?指令為其他指令設(shè)置工作目錄,如果不存在,則會創(chuàng)建該目錄。
COPY指令會從源路徑復(fù)制新文件或目錄,并將它們添加到路徑目標(biāo)容器的文件系統(tǒng)中。
RUN指令可以在當(dāng)前鏡像之上的新?層?中執(zhí)行任何命令并提交結(jié)果,生成的已提交鏡像將用于 Dockerfile 中的下一步。
ENTRYPOINT指令支持以可執(zhí)行文件的形式運(yùn)行容器。
有關(guān) Dockerfile 中指令用法的更多信息請參閱?Dockerfile reference。
同時(shí),為了避免構(gòu)建項(xiàng)目中的一些調(diào)試生成文件,可以在項(xiàng)目文件夾中新增.dockerignore文件,并粘貼如下內(nèi)容:
bin\obj\
構(gòu)建應(yīng)用容器鏡像
在項(xiàng)目TodoApi根目錄中,打開集成終端,執(zhí)行如下命令構(gòu)建容器鏡像:
docker build -t todoapi .-t參數(shù)用來指定鏡像的名字及標(biāo)簽,通常是name:tag或者name格式。本例todoapi便是我們給鏡像起的名字,沒有設(shè)置標(biāo)簽即使用默認(rèn)標(biāo)簽latest。
如命令執(zhí)行成功,終端會有類似如下輸出:
$ docker build -t todoapi .Sending build context to Docker daemon 1.137MB
Step 1/10 : FROM microsoft/dotnet:2.2-sdk AS build-env
2.2-sdk: Pulling from microsoft/dotnet
e79bb959ec00: Pull complete
d4b7902036fe: Pull complete
1b2a72d4e030: Pull complete
d54db43011fd: Pull complete
b3ae1535ac68: Pull complete
f04cf82b07ad: Pull complete
6f91a9d92092: Pull complete
Digest: sha256:c443ff79311dde76cb1acf625ae47581da45aad4fd66f84ab6ebf418016cc008
Status: Downloaded newer image for microsoft/dotnet:2.2-sdk
---> e268893be733
Step 2/10 : WORKDIR /app
---> Running in c7f62130f331
Removing intermediate container c7f62130f331
---> e8b6a73d3d84
Step 3/10 : COPY *.csproj ./
---> cfa03afa6003
Step 4/10 : RUN dotnet restore
---> Running in d96a9b89e4a9
Restore completed in 924.67 ms for /app/TodoApi.csproj.
Removing intermediate container d96a9b89e4a9
---> 14d5d32d40b6
Step 5/10 : COPY . ./
---> b1242ea0b0b8
Step 6/10 : RUN dotnet publish -c Release -o out
---> Running in 37c8eb07c86e
Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 663.74 ms for /app/TodoApi.csproj.
TodoApi -> /app/bin/Release/netcoreapp2.2/TodoApi.dll
TodoApi -> /app/out/
Removing intermediate container 37c8eb07c86e
---> 6238f4c1cf07
Step 7/10 : FROM microsoft/dotnet:2.2-aspnetcore-runtime
2.2-aspnetcore-runtime: Pulling from microsoft/dotnet
27833a3ba0a5: Pull complete
25dbf7dc93e5: Pull complete
0ed9cb15d3b8: Pull complete
874ea13b7488: Pull complete
Digest: sha256:ffd756d34bb0f976ba5586f6c88597765405af8014ae51b34811992b46ba40e8
Status: Downloaded newer image for microsoft/dotnet:2.2-aspnetcore-runtime
---> cb2dd04458bc
Step 8/10 : WORKDIR /app
---> Running in b0a3826d346b
Removing intermediate container b0a3826d346b
---> 4218db4cc2f5
Step 9/10 : COPY --from=build-env /app/out .
---> 765168aa2c7a
Step 10/10 : ENTRYPOINT ["dotnet", "TodoApi.dll"]
---> Running in f93bcaf5591f
Removing intermediate container f93bcaf5591f
---> 046226f5e9cb
Successfully built 046226f5e9cb
Successfully tagged todoapi:latest
如果您的機(jī)器是第一次構(gòu)建,速度可能會有些慢,因?yàn)橐獜?Docker Hub 上拉取應(yīng)用依賴的dotnet-sdk和aspnetcore-runtime基礎(chǔ)鏡像。
構(gòu)建完成后,我們可以通過docker images命令確認(rèn)本地鏡像倉庫是否存在我們構(gòu)建的鏡像todoapi。
REPOSITORY TAG IMAGE ID CREATED SIZEtodoapi latest c92a82f0efaa 19 hours ago 260MB
microsoft/dotnet 2.2-sdk 5e09f77009fa 26 hours ago 1.74GB
microsoft/dotnet 2.2-aspnetcore-runtime 08ed21b5758c 26 hours ago 260MB
...
運(yùn)行應(yīng)用容器
容器鏡像構(gòu)建完成后,就可以使用docker run命令運(yùn)行容器了,有關(guān)該命令參數(shù)的更多信息請參閱?Reference - docker run?。
開發(fā)環(huán)境下,通常會通過docker run --rm -it命令運(yùn)行應(yīng)用容器,具體命令如下:
docker run --rm -it -p 5000:80 todoapi-it參數(shù)表示以交互模式運(yùn)行容器并為容器重新分配一個(gè)偽輸入終端,方便查看輸出調(diào)試程序。
--rm參數(shù)表示將會在容器退出后自動刪除當(dāng)前容器,開發(fā)模式下常用參數(shù)。
-p參數(shù)表示會將本地計(jì)算機(jī)上的5000端口映射到容器中的默認(rèn)80端口,端口映射的關(guān)系為host:container。
todoapi便是我們要啟動的本地鏡像名稱。
如命令執(zhí)行成功,終端會有類似如下輸出:
$ docker run -it --rm -p 5000:80 todoapiwarn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {1a78d899-738b-4aea-a7d6-777302933f38} may be persisted to storage in unencrypted form.
Hosting environment: Production
Content root path: /app
Now listening on: http:
Application started. Press Ctrl+C to shut down.
生產(chǎn)環(huán)境下,通常會通過docker run -d命令運(yùn)行應(yīng)用容器,具體命令如下:
docker run -d --restart=always --name myapp -p 5000:80 todoapi-d參數(shù)表示會將容器作為服務(wù)啟動,不需要終端交互。
--name參數(shù)用來指定容器名稱,本例指定容器名稱為myapp。
--restart是一個(gè)面向生產(chǎn)環(huán)境的參數(shù),用來指定容器非正常退出時(shí)的重啟策略,本例always表示始終重新啟動容器,其他可選策略請參考?Restart policies (--restart)。
如命令執(zhí)行成功,終端會有類似如下輸出:
$ docker run -d --restart=always --name myapp -p 5000:80 todoapie3d747d9d2b4cd14b2acb24f81bea9312f89c4eb689dba5f6559950c91db1600
容器啟動后,在 Web 瀏覽器中再次訪問http://localhost:5000/api/values,應(yīng)該會和本地測試一樣返回如下 JSON 數(shù)據(jù):
["value1","value2"]至此,我們的 ASP.NET Core 應(yīng)用就成功運(yùn)行在 Docker 容器中了。
多容器應(yīng)用部署
目前我們創(chuàng)建的演示項(xiàng)目TodoApi過于簡單,真實(shí)的生產(chǎn)項(xiàng)目肯定會涉及更多其他的依賴。例如:關(guān)系數(shù)據(jù)庫 Mysql、文檔數(shù)據(jù)庫 MongoDB、分布式緩存 Redis、消息隊(duì)列 RabbitMQ 等各種服務(wù)。
還有就是,生產(chǎn)環(huán)境我們一般不會將 ASP.NET Core 應(yīng)用程序的宿主服務(wù)器 Kestrel 直接暴露給用戶,通常是在前面加一個(gè)反向代理服務(wù) Nginx。
這些依賴服務(wù)還要像傳統(tǒng)部署方式那樣,一個(gè)一個(gè)單獨(dú)配置部署嗎?不用的,因?yàn)樗鼈儽旧硪彩强梢员蝗萜骰?#xff0c;所以我們只要考慮如何把各個(gè)相互依賴的容器聯(lián)系到一起,這就涉及到容器編排,而 Docker Compose 正是用來解決這一問題的,最終可以實(shí)現(xiàn)多容器應(yīng)用的一鍵部署。
Docker Compose?是一個(gè)用于定義和運(yùn)行多容器的 Docker 工具。其使用YAML文件來配置應(yīng)用程序的服務(wù),最終您只要使用一個(gè)命令就可以從配置中創(chuàng)建并啟動所有服務(wù)。
安裝 Docker Compose
Linux 系統(tǒng)下的安裝過程大致分為以下幾步:
Step1:運(yùn)行如下命令下載 Compose 最新穩(wěn)定版本,截止發(fā)稿前最新版本為1.24.0。
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-composeStep2:對下載完成的二進(jìn)制程序添加可執(zhí)行權(quán)限。
sudo chmod +x /usr/local/bin/docker-composeStep3:測試安裝是否成功。
docker-compose --versiondocker-compose version 1.24.0, build 0aa59064
若您在安裝過程中遇到問題,或是其他系統(tǒng)安裝請參閱?Install Docker Compose。
改造演示項(xiàng)目
現(xiàn)在來改造一下我們的演示項(xiàng)目TodoApi,添加 Redis 分布式緩存、使用 Nginx 做反向代理,準(zhǔn)備構(gòu)建一個(gè)具如下圖所示架構(gòu)的多容器應(yīng)用。
在TodoApi項(xiàng)目根目錄下,打開集成終端,輸入如下命令新增 Redis 依賴包。
dotnet add package Microsoft.Extensions.Caching.StackExchangeRedis --version 2.2.0修改應(yīng)用啟動配置文件Startup.cs中的ConfigureServices方法:
public void ConfigureServices(IServiceCollection services)
{
services.AddStackExchangeRedisCache(options =>
{
options.Configuration = Configuration.GetConnectionString("Redis");
});
services.AddHttpContextAccessor();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
在TodoApi項(xiàng)目Controllers目錄下新建控制器HelloController,具體代碼如下所示:
using System;using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
namespace TodoApi.Controllers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
namespace TodoApi.Controllers
{
[]
[]
public class HelloController : ControllerBase
{
private readonly IDistributedCache _distributedCache;
private readonly IHttpContextAccessor _httpContextAccessor;
public HelloController(
IDistributedCache distributedCache,
IHttpContextAccessor httpContextAccessor)
{
_distributedCache = distributedCache;
_httpContextAccessor = httpContextAccessor;
}
[]
public ActionResult<string> Get()
{
var connection = _httpContextAccessor.HttpContext.Connection;
var ipv4 = connection.LocalIpAddress.MapToIPv4().ToString();
var message = $"Hello from Docker Container:{ipv4}";
return message;
}
[]
public ActionResult<string> Get(string name)
{
var defaultKey = $"hello:{name}";
_distributedCache.SetString(defaultKey, $"Hello {name} form Redis");
var message = _distributedCache.GetString(defaultKey);
return message;
}
}
}
以上控制器,提供了兩個(gè)接口/api/hello和/api/hello/{name},分別用來測試 Nginx 負(fù)載均衡和 Redis 的聯(lián)通性。
創(chuàng)建 docker-compose.yml
準(zhǔn)備工作就緒,下面我們就可以使用 Docker Compose 來編排容器。
同樣是在TodoApi項(xiàng)目根目錄中,創(chuàng)建一個(gè)名為docker-compose.yml的文件,并粘貼以下內(nèi)容:
version: "3.7"services:
myproject-todoapi-1:
container_name: my-todoapi-1
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- "5001:80"
volumes:
- ./appsettings.json:/app/appsettings.json
myproject-todoapi-2:
container_name: my-todoapi-2
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- "5002:80"
volumes:
- ./appsettings.json:/app/appsettings.json
myproject-todoapi-3:
container_name: my-todoapi-3
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- "5003:80"
volumes:
- ./appsettings.json:/app/appsettings.json
myproject-nginx:
container_name: my-nginx
image: nginx
restart: always
ports:
- "80:80"
volumes:
- ./conf/nginx.conf:/etc/nginx/conf.d/default.conf
myproject-redis:
container_name: my-redis
image: redis
restart: always
ports:
- "6379:80"
volumes:
- ./conf/redis.conf:/etc/redis/redis.conf
其中version?用來指定 Compose 文件版本號,3.7是目前最新版本,具體哪些版本對應(yīng)哪些特定的 Docker 引擎版本請參閱?Compose file versions and upgrading。
Compose 中強(qiáng)化了服務(wù)的概念,簡單地理解就是, 服務(wù)是一種用于生產(chǎn)環(huán)境的容器。一個(gè)多容器 Docker 應(yīng)用由若干個(gè)服務(wù)組成,如上文件即定義了 5 個(gè)服務(wù):
3 個(gè)應(yīng)用服務(wù)myproject-todoapi-1、myproject-todoapi-2和myproject-todoapi-3
1 個(gè) Nginx 服務(wù)myproject-reverse-proxy
1 個(gè) Redis 服務(wù)myproject-redis
以上 5 個(gè)服務(wù)的配置參數(shù)相差無幾、也很簡單,我就不展開敘述,不清楚的可以參閱?Compose file reference。
這里只講一個(gè)配置參數(shù)volumes:
我們知道,容器中的文件在宿主機(jī)上存在形式復(fù)雜,修改文件需要先通過如下命令進(jìn)入容器后操作。
docker exec -it <CONTAINER ID/NAMES> /bin/bash容器一旦刪除,其內(nèi)部配置以及產(chǎn)生的數(shù)據(jù)也會丟失。
為了解決這些問題,Docker 引入了數(shù)據(jù)卷?volumes?機(jī)制。即 Compose 中?volumes?參數(shù)用來將宿主機(jī)的某個(gè)目錄或文件映射掛載到 Docker 容器內(nèi)部的對應(yīng)的目錄或文件,通常被用來靈活掛載配置文件或持久化容器產(chǎn)生的數(shù)據(jù)。
創(chuàng)建相關(guān)配置文件
接下來,需要根據(jù)如上docker-compose.yml文件中涉及的volumes配置創(chuàng)建三個(gè)配置文件。要知道,它們最終是需要被注入到 Docker 容器中的。
首先,在TodoApi項(xiàng)目根目錄中,創(chuàng)建三個(gè)應(yīng)用服務(wù)myproject-todoapi-*需要的程序配置文件appsettings.json,具體內(nèi)容如下:
"ConnectionStrings": {"Redis": "myproject-redis:6379,password=todoapi@2019"
},
以上配置,指定了 Redis 服務(wù)myproject-redis的連接字符串,其中myproject-redis可以看到是 Redis 服務(wù)的服務(wù)名稱,當(dāng)該配置文件注入到 Docker 容器中后,會自動解析為容器內(nèi)部 IP,同時(shí)考慮到 Redis 服務(wù)的安全性,為其指定了密碼,即password=todoapi@2019。
然后,在TodoApi項(xiàng)目根目錄中創(chuàng)建一個(gè)子目錄conf,用來存放 Nginx 和 Redis 的配置文件。
mkdir conf && cd conf先來創(chuàng)建 Redis 服務(wù)myproject-redis的配置文件。
可以通過如下命令,下載一個(gè) Redis 官方提供的標(biāo)準(zhǔn)配置文件redis.conf:
wget http:然后打開下載后的redis.conf文件,找到SECURITY節(jié)點(diǎn),根據(jù)如上應(yīng)用服務(wù)的 Redis 連接字符串信息,啟用并改下密碼:
requirepass todoapi@2019再來創(chuàng)建 Nginx 服務(wù)myproject-nginx的配置文件。
在conf目錄中,創(chuàng)建一個(gè)名為nginx.conf的配置文件,并粘貼如下內(nèi)容:
upstream todoapi {server myproject-todoapi-1:80;
server myproject-todoapi-2:80;
server myproject-todoapi-3:80;
}
server {
listen 80;
location / {
proxy_pass http://todoapi;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
以上配置,是一個(gè) Nginx 中具備負(fù)載均衡的代理配置,其默認(rèn)采用輪循策略將請求轉(zhuǎn)發(fā)給 Docker 服務(wù)myproject-todoapi-1、myproject-todoapi-2和myproject-todoapi-3。
運(yùn)行并測試多容器應(yīng)用
經(jīng)過以上幾個(gè)小節(jié),容器編排的過程就完成了,接下來就可以直接定義并啟動我們創(chuàng)建的多容器應(yīng)用實(shí)例了。
切換到docker-compose.yml文件所在的目錄,也就是TodoApi項(xiàng)目的根目錄,執(zhí)行如下命令:
docker-compose up -d如命令執(zhí)行成功,終端最后會有類似如下輸出:
......Creating my-todoapi-1 ... done
Creating my-redis ... done
Creating my-todoapi-3 ... done
Creating my-nginx ... done
Creating my-todoapi-2 ... done
至此,我們的多容器應(yīng)用就已經(jīng)在運(yùn)行了,可以通過docker-compose ps命令來確認(rèn)下。
$ docker-compose psName Command State Ports
my-nginx nginx -g daemon off; Up 0.0.0.0:80->80/tcp
my-redis docker-entrypoint.sh redis ... Up 6379/tcp, 0.0.0.0:6379->80/tcp
my-todoapi-1 dotnet TodoApi.dll Up 0.0.0.0:5001->80/tcp
my-todoapi-2 dotnet TodoApi.dll Up 0.0.0.0:5002->80/tcp
my-todoapi-3 dotnet TodoApi.dll Up 0.0.0.0:5003->80/tcp
可以通過連續(xù)三次請求/api/hello接口測試應(yīng)用的負(fù)載均衡。
curl http:curl http:
curl http:
Hello from Docker Container:172.30.0.2
Hello from Docker Container:172.30.0.4
Hello from Docker Container:172.30.0.5
三個(gè)應(yīng)用服務(wù)分別部署在不同容器中,所以理論上來講,他們的容器內(nèi)部 IP 也是不同的,所以/api/hello接口每次輸出信息不會相同。
請求/api/hello/{name}接口測試 Redis 服務(wù)連通性。
curl http:Hello esofar form Redis
小結(jié)
本文從零構(gòu)建了一個(gè) ASP.NET Core 應(yīng)用,并通過 Docker 部署,然后由淺入深,引入 Docker Compose 演示了多容器應(yīng)用的部署過程。通過本文的實(shí)戰(zhàn)您可以更深入地了解 Docker。本文涉及的代碼已托管到以下地址,您在實(shí)驗(yàn)過程中遇到問題可以參考。
https://github.com/esofar/dockerize-aspnetcore-samples
Docker 命令附錄
$ docker --helpUsage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/root/.docker")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
builder Manage builds
config Manage Docker configs
container Manage containers
engine Manage the docker engine
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container
events Get real time events from the server
exec Run a command in a running container
export Export a container
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Docker Compose 命令附錄
$ docker-composeDefine and run multi-container applications with Docker.
Usage:
docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
docker-compose -h|
Options:
-f,
(default: docker-compose.yml)
-p,
(default: directory name)
-v,
-H,
name specified in the client certificate
(default: the path of the Compose file)
in v3 files to their non-Swarm equivalent
Commands:
build Build or rebuild services
bundle Generate a Docker bundle from the Compose file
config Validate and view the Compose file
create Create services
down Stop and remove containers, networks, images, and volumes
events Receive real time events from containers
exec Execute a command in a running container
help Get help on a command
images List images
kill Kill containers
logs View output from containers
pause Pause services
port Print the public port for a port binding
ps List containers
pull Pull service images
push Push service images
restart Restart services
rm Remove stopped containers
run Run a one-off command
scale Set number of containers for a service
start Start services
stop Stop services
top Display the running processes
unpause Unpause services
up Create and start containers
version Show the Docker-Compose version information
相關(guān)閱讀
ASP.NET Core Docker Sample
Dockerize a .NET Core application
Best practices for writing Dockerfiles
Fun With Docker-Compose Using .NET Core And NGINX
ASP.NET Core 2.2: implementando Load Balancing com Nginx, Docker e Docker Compose
原文地址:https://www.cnblogs.com/esofar/p/10694319.html
.NET社區(qū)新聞,深度好文,歡迎訪問公眾號文章匯總?http://www.csharpkit.com?
總結(jié)
以上是生活随笔為你收集整理的使用 Docker 在 Linux 上托管 ASP.NET Core 应用程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VS Code Remote 发布!开启
- 下一篇: 微软全都要!Win10引入真Linux内