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

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

Connecting to an interactive container

An interactive container is one that has an open connection to the Docker command line, so you work with the container as if you were connected to a remote machine. You can run an interactive container from the same Windows Server Core image by specifying the interactive options and a command to run when the container starts:

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

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\> Write-Output 'This is an interactive container'
This is an interactive container
PS C:\> exit

The --interactive option runs an interactive container, and the --tty flag attaches a terminal connection to the container. The powershell statement after the name of the container image is the command to run when the container starts. By specifying a command you replace the startup command that's been set up in the image. In this case, I start a PowerShell session and that runs instead of the configured command, so the environment printout script doesn't run.

An interactive container keeps running as long as the command inside is running. While you're connected to PowerShell, running docker container ls in another window on the host will show that the container is still running. When you type exit in the container, the PowerShell session ends, so there's no process running and the container exits too.

Interactive containers are useful when you're building your own container images, they let you can work through the steps interactively first and verify that everything will work as you expect. They're good exploratory tools too. You can pull someone else's image from a Docker registry and explore the contents before you run the application.

You'll see as you read through this book that Docker can host complex distributed systems in a virtual network, with each component running in its own container. If you want to examine parts of the system, you can run an interactive container inside the network and check on individual components, without having to make the parts publicly accessible.

主站蜘蛛池模板: 兴文县| 临夏市| 文山县| 夏津县| 甘谷县| 九江市| 江北区| 通许县| 沾益县| 满城县| 韩城市| 利川市| 社旗县| 屯门区| 涞水县| 淮滨县| 大竹县| 凉山| 治县。| 新营市| 青州市| 迁西县| 静宁县| 冷水江市| 泾阳县| 金秀| 乐至县| 韶山市| 孝感市| 涟源市| 兴隆县| 元谋县| 齐齐哈尔市| 蒲城县| 彭州市| 鸡西市| 广德县| 玉龙| 安康市| 寻乌县| 长葛市|