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

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 that same Nano Server image by specifying the interactive options and a command to run when the container starts:

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

Windows PowerShell
Copyright (C) 2016 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 dummy 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 on another window on the host will show 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, as you can work through the steps interactively first and verify that everything will work as you expect. They're good exploratory tools too. You'll see as you move further into 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.

主站蜘蛛池模板: 铁岭县| 宁蒗| 饶阳县| 宜兰县| 龙海市| 贵德县| 纳雍县| 叙永县| 平利县| 庆城县| 苍溪县| 磐安县| 漳州市| 策勒县| 长武县| 姚安县| 孝昌县| 承德市| 尼玛县| 黄山市| 松桃| 桐柏县| 祁连县| 上高县| 吉林市| 安塞县| 永兴县| 镇坪县| 富锦市| 宜良县| 东港市| 临沂市| 铜川市| 云霄县| 开封市| 安图县| 遵义县| 安达市| 松滋市| 堆龙德庆县| 隆子县|