官术网_书友最值得收藏!

  • Docker on Windows
  • Elton Stoneman
  • 361字
  • 2021-07-02 12:47:55

Doing one thing with a task container

The dockeronwindows/ch02-powershell-env:2e image is an example of a packaged application which is meant to run in a container and perform a single task. The image is based on Microsoft Windows Server Core and is set up to run a simple PowerShell script when it starts, printing details about the current environment. Let's see what happens when I run a container directly from the image:

> docker container run dockeronwindows/ch02-powershell-env:2e

Name Value
---- -----
ALLUSERSPROFILE C:\ProgramData
APPDATA C:\Users\ContainerAdministrator\AppData\Roaming
CommonProgramFiles C:\Program Files\Common Files
CommonProgramFiles(x86) C:\Program Files (x86)\Common Files
CommonProgramW6432 C:\Program Files\Common Files
COMPUTERNAME 8A7D5B9A4021

...

Without any options, the container runs a PowerShell script which is built into the image, and the script prints out some basic information about the operating system environment. I call this a task container because the container performs one task and then exits.

If you run docker container ls, which lists all the active containers, you won't see this container. But if you run docker container ls --all, which shows containers in all states, you'll see it in the Exited status:

> docker container ls --all
CONTAINER ID IMAGE COMMAND CREATED STATUS
8a7d5b9a4021 dockeronwindows/ch02-powershell-env:2e "powershell.exe C:..." 30 seconds ago Exited

Task containers are very useful in automating repetitive tasks, like running scripts to set up an environment, backing up data, or collecting log files. Your container image packages the script to run, along with the exact version of all the requirements that the script needs, so anyone with Docker installed can run the script without having to install pre-requisites.

This is especially useful for PowerShell, where scripts can be dependent on several PowerShell modules. The modules may be publicly available, but your script can be dependent on specific versions. Instead of sharing a script that requires users to install the correct version of many different modules, you build an image that has the modules already installed. Then you only need Docker to run the script task.

Images are self-contained units, but you can also use them as a template. An image may be configured to do one thing, but you can run containers from an image in different ways to do different things.

主站蜘蛛池模板: 利津县| 独山县| 财经| 大冶市| 株洲市| 桂东县| 于田县| 商南县| 奉化市| 西乡县| 都兰县| 汶川县| 高碑店市| 玉山县| 北宁市| 镇巴县| 宁蒗| 酒泉市| 疏勒县| 含山县| 宣城市| 星子县| 合肥市| 芦山县| 明溪县| 东方市| 开阳县| 南漳县| 彭山县| 东光县| 永顺县| 宽甸| 崇阳县| 汉源县| 鸡西市| 威远县| 浮梁县| 沙湾县| 六安市| 晋中市| 璧山县|