docker基礎:容器生命周期管理命令

来源:https://www.cnblogs.com/Rohn/archive/2020/07/12/13288941.html
-Advertisement-
Play Games

容器是一種清理級、可移植、自包含的軟體打包技術,使應用程式可以在幾乎任何地方以相同的方式運行。 ...


blog:https://www.cnblogs.com/Rohn/

目錄

容器生命周期管理

  • docker run:創建一個新的容器並運行一個命令;
  • docker start/stop/restart:啟停容器;
  • docker kill:殺掉運行中的容器;
  • docker rm:刪除一個或多個容器;
  • docker pause/unpause:暫停或恢復容器中的所有進程;
  • docker create:創建一個新的容器但不啟動它;
  • docker exec:在運行的容器中執行命令;
  • docker update:更新一個或多個容器的配置;

運行容器

語法如下:

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Options:
      --add-host list                         Add a custom host-to-IP mapping (host:ip) (default [])
  -a, --attach list                           Attach to STDIN, STDOUT or STDERR (default [])
      --blkio-weight uint16                   Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
      --blkio-weight-device weighted-device   Block IO weight (relative device weight) (default [])
      --cap-add list                          Add Linux capabilities (default [])
      --cap-drop list                         Drop Linux capabilities (default [])
      --cgroup-parent string                  Optional parent cgroup for the container
      --cidfile string                        Write the container ID to the file
      --cpu-count int                         CPU count (Windows only)
      --cpu-percent int                       CPU percent (Windows only)
      --cpu-period int                        Limit CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int                         Limit CPU CFS (Completely Fair Scheduler) quota
      --cpu-rt-period int                     Limit CPU real-time period in microseconds
      --cpu-rt-runtime int                    Limit CPU real-time runtime in microseconds
  -c, --cpu-shares int                        CPU shares (relative weight)
      --cpus decimal                          Number of CPUs (default 0.000)
      --cpuset-cpus string                    CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string                    MEMs in which to allow execution (0-3, 0,1)
      --credentialspec string                 Credential spec for managed service account (Windows only)
  -d, --detach                                Run container in background and print container ID
      --detach-keys string                    Override the key sequence for detaching a container
      --device list                           Add a host device to the container (default [])
      --device-read-bps throttled-device      Limit read rate (bytes per second) from a device (default [])
      --device-read-iops throttled-device     Limit read rate (IO per second) from a device (default [])
      --device-write-bps throttled-device     Limit write rate (bytes per second) to a device (default [])
      --device-write-iops throttled-device    Limit write rate (IO per second) to a device (default [])
      --disable-content-trust                 Skip image verification (default true)
      --dns list                              Set custom DNS servers (default [])
      --dns-option list                       Set DNS options (default [])
      --dns-search list                       Set custom DNS search domains (default [])
      --entrypoint string                     Overwrite the default ENTRYPOINT of the image
  -e, --env list                              Set environment variables (default [])
      --env-file list                         Read in a file of environment variables (default [])
      --expose list                           Expose a port or a range of ports (default [])
      --group-add list                        Add additional groups to join (default [])
      --health-cmd string                     Command to run to check health
      --health-interval duration              Time between running the check (ns|us|ms|s|m|h) (default 0s)
      --health-retries int                    Consecutive failures needed to report unhealthy
      --health-timeout duration               Maximum time to allow one check to run (ns|us|ms|s|m|h) (default 0s)
      --help                                  Print usage
  -h, --hostname string                       Container host name
      --init                                  Run an init inside the container that forwards signals and reaps processes
      --init-path string                      Path to the docker-init binary
  -i, --interactive                           Keep STDIN open even if not attached
      --io-maxbandwidth string                Maximum IO bandwidth limit for the system drive (Windows only)
      --io-maxiops uint                       Maximum IOps limit for the system drive (Windows only)
      --ip string                             Container IPv4 address (e.g. 172.30.100.104)
      --ip6 string                            Container IPv6 address (e.g. 2001:db8::33)
      --ipc string                            IPC namespace to use
      --isolation string                      Container isolation technology
      --kernel-memory string                  Kernel memory limit
  -l, --label list                            Set meta data on a container (default [])
      --label-file list                       Read in a line delimited file of labels (default [])
      --link list                             Add link to another container (default [])
      --link-local-ip list                    Container IPv4/IPv6 link-local addresses (default [])
      --log-driver string                     Logging driver for the container
      --log-opt list                          Log driver options (default [])
      --mac-address string                    Container MAC address (e.g. 92:d0:c6:0a:29:33)
  -m, --memory string                         Memory limit
      --memory-reservation string             Memory soft limit
      --memory-swap string                    Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --memory-swappiness int                 Tune container memory swappiness (0 to 100) (default -1)
      --name string                           Assign a name to the container
      --network string                        Connect a container to a network (default "default")
      --network-alias list                    Add network-scoped alias for the container (default [])
      --no-healthcheck                        Disable any container-specified HEALTHCHECK
      --oom-kill-disable                      Disable OOM Killer
      --oom-score-adj int                     Tune host's OOM preferences (-1000 to 1000)
      --pid string                            PID namespace to use
      --pids-limit int                        Tune container pids limit (set -1 for unlimited)
      --privileged                            Give extended privileges to this container
  -p, --publish list                          Publish a container's port(s) to the host (default [])
  -P, --publish-all                           Publish all exposed ports to random ports
      --read-only                             Mount the container's root filesystem as read only
      --restart string                        Restart policy to apply when a container exits (default "no")
      --rm                                    Automatically remove the container when it exits
      --runtime string                        Runtime to use for this container
      --security-opt list                     Security Options (default [])
      --shm-size string                       Size of /dev/shm, default value is 64MB
      --sig-proxy                             Proxy received signals to the process (default true)
      --stop-signal string                    Signal to stop a container, SIGTERM by default (default "SIGTERM")
      --stop-timeout int                      Timeout (in seconds) to stop a container
      --storage-opt list                      Storage driver options for the container (default [])
      --sysctl map                            Sysctl options (default map[])
      --tmpfs list                            Mount a tmpfs directory (default [])
  -t, --tty                                   Allocate a pseudo-TTY
      --ulimit ulimit                         Ulimit options (default [])
  -u, --user string                           Username or UID (format: <name|uid>[:<group|gid>])
      --userns string                         User namespace to use
      --uts string                            UTS namespace to use
  -v, --volume list                           Bind mount a volume (default [])
      --volume-driver string                  Optional volume driver for the container
      --volumes-from list                     Mount volumes from the specified container(s) (default [])
  -w, --workdir string                        Working directory inside the container

例子:

# 使用鏡像nginx:latest,以後臺模式啟動一個容器,將容器的80埠映射到主機的80埠,主機的目錄/data映射到容器的/data
docker run -p 80:80 -v /data:/data -d nginx:latest

啟停容器

語法如下:

# 啟動已經被停止的容器
docker start [OPTIONS] CONTAINER [CONTAINER...]

Options:
  -a, --attach               Attach STDOUT/STDERR and forward signals
      --detach-keys string   Override the key sequence for detaching a container
  -i, --interactive          Attach container's STDIN

# 停止運行中的容器
docker stop [OPTIONS] CONTAINER [CONTAINER...]

Options:
  -t, --time int   Seconds to wait for stop before killing it (default 10)

# 重啟容器
docker restart [OPTIONS] CONTAINER [CONTAINER...]

Options:
  -t, --time int   Seconds to wait for stop before killing the container (default 10)

殺掉容器

語法如下:

docker kill [OPTIONS] CONTAINER [CONTAINER...]

Options:
  -s, --signal string   Signal to send to the container (default "KILL")

刪除容器

語法如下:

docker rm [OPTIONS] CONTAINER [CONTAINER...]

Options:
  -f, --force     Force the removal of a running container (uses SIGKILL)
  -l, --link      Remove the specified link
  -v, --volumes   Remove the volumes associated with the container

暫停或恢復容器中所有的進程

語法如下:

# 暫停容器中所有的進程
docker pause CONTAINER [CONTAINER...]

# 恢復容器中所有的進程
docker unpause CONTAINER [CONTAINER...]

創建一個新的容器但不啟動它

語法同docker run

在容器中執行命令

語法如下:

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

Options:
  -d, --detach               Detached mode: run command in the background
      --detach-keys string   Override the key sequence for detaching a container
  -e, --env list             Set environment variables (default [])
      --help                 Print usage
  -i, --interactive          Keep STDIN open even if not attached
      --privileged           Give extended privileges to the command
  -t, --tty                  Allocate a pseudo-TTY
  -u, --user string          Username or UID (format: <name|uid>[:<group|gid>])

更新一個或多個容器的配置

語法如下:

docker update [OPTIONS] CONTAINER [CONTAINER...]

Options:
      --blkio-weight uint16         Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
      --cpu-period int              Limit CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int               Limit CPU CFS (Completely Fair Scheduler) quota
      --cpu-rt-period int           Limit the CPU real-time period in microseconds
      --cpu-rt-runtime int          Limit the CPU real-time runtime in microseconds
  -c, --cpu-shares int              CPU shares (relative weight)
      --cpuset-cpus string          CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string          MEMs in which to allow execution (0-3, 0,1)
      --help                        Print usage
      --kernel-memory string        Kernel memory limit
  -m, --memory string               Memory limit
      --memory-reservation string   Memory soft limit
      --memory-swap string          Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --restart string              Restart policy to apply when a container exits

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 最近兩天在Linux中調試.NET Core應用程式,同時我發現在Linux中調試.NET Core應用程式並不容易。一直習慣在Visual Studio中進行編碼和調試。現在我想的是可以簡單快速的測試.NET Core應用在Linux。所以通過本篇文章我們能瞭解到如何在Windows中使用Visu ...
  • DirectX與WPF DirectX DirectX(Direct eXtension,簡稱DX)是由微軟公司創建的多媒體編程介面,是一種應用程式介面(API)。DirectX可以讓以windows為平臺的游戲或多媒體程式獲得更高的執行效率,加強3D圖形和聲音效果,並提供設計人員一個共同的硬體驅動 ...
  • 頭文件添加方法:工程 屬性 配置屬性 c/c++ 常規 附加包含目錄(Additional Include Directories):加上頭文件存放目錄。註意:(1)路徑必須指向頭文件所在的子文件夾,而不能直到父文件夾就結束(2)每個路徑不需要加上雙引號,輸入了之後,vs會自動加上雙引號,如果自己加 ...
  • 動態引入技術的設計,對我們來說非常重要。 同時也說明動態語言的使用對我們來說也是非常重要。 沒有動態語言的支撐,有些想法可能不容易實現,或者有替代方案,可能會花更大的代價。 前端開發框架我們規劃設計了 apis文件夾 這個文件夾是用來存放所有的api定義的 規範要求 所有的api定義都是名動詞 同時 ...
  • 最近GRPC很火,感覺整RPC不用GRPC都快跟不上時髦了。 gRPC設計 gRPC是一種與語言無關的高性能遠程過程調用 (RPC) 框架。剛好需要使用一個的RPC應用系統,自然而然就盯上了它,但是它真能夠解決所有問題嗎?不見得,先看看他的優點: gRPC的主要優點: 現代高性能輕量級 RPC 框架 ...
  • 瞭解到了OrchardCore主要由兩個中間件(ModularTenantContainerMiddleware和ModularTenantRouterMiddleware)構成,下麵開始瞭解ModularTenantContainerMiddleware中間件第一行代碼。 瞭解asp.net co ...
  • 什麼是設計模式 ​ 要瞭解設計模式,首先得清楚什麼是模式。什麼是模式?模式即解決一類問題的方法論,簡單得來說,就是將解決某類問題的方法歸納總結到理論高度,就形成了模式。 ​ 設計模式就是將代碼設計經驗歸納總結到理論高度而形成的。其目的就在於:1)可重用代碼,2)讓代碼更容易為他人理解,3)保證代碼的 ...
  • [ 導讀] 本文通過閱讀內核代碼,來梳理一下I2C子系統的整體視圖。在開發I2C設備驅動程式時,往往缺乏對於系統整體的認識,導致沒有一個清晰的思路。所以從高層級來分析一下I2C系統的設計思路,將有助於設計調試具體的驅動程式。 I2C/SMBUS基礎 I2C是一種晶元間通訊匯流排技術,最早由Philip ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...