- Docker on Windows
- Elton Stoneman
- 361字
- 2021-07-02 19:53:18
Doing one thing with a task container
The dockeronwindows/ch02-powershell-env image is an example of a packaged application that is meant to run in a container and perform a single task. The image is based on Microsoft Nano Server 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
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 361CB712CB4B
...
Without any options, the container runs a PowerShell script that is built into the image, and the script prints out some basic information about the operating system environment. I call that 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 PORTS NAMES
361cb712cb4b dockeronwindows/ch02-powershell-env "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 the engine that the script needs, so anyone with Docker installed can run that script without having to install the engine.
This is especially useful for PowerShell, where scripts can be dependent on several PowerShell modules. The modules may be publicly available, but your script is 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 the image in different ways to do different things.
- 數(shù)據(jù)科學(xué)實(shí)戰(zhàn)手冊(cè)(R+Python)
- 多媒體CAI課件設(shè)計(jì)與制作導(dǎo)論(第二版)
- ASP.NET MVC4框架揭秘
- Java系統(tǒng)分析與架構(gòu)設(shè)計(jì)
- Python 深度學(xué)習(xí)
- HoloLens Beginner's Guide
- Java 9 Programming Blueprints
- Silverlight魔幻銀燈
- INSTANT Django 1.5 Application Development Starter
- Advanced Oracle PL/SQL Developer's Guide(Second Edition)
- Python Web數(shù)據(jù)分析可視化:基于Django框架的開發(fā)實(shí)戰(zhàn)
- Learning Laravel's Eloquent
- ASP.NET程序開發(fā)范例寶典
- Creating Data Stories with Tableau Public
- C++從入門到精通(第6版)