- Docker on Windows
- Elton Stoneman
- 364字
- 2021-07-02 12:47:55
Keeping a process running in a background container
The last type of container is the one that you'll use most in production, the background container, which keeps a long-running process running in the background. It's a container that behaves like a Windows service. In Docker terminology, it's called a detached container, and it's the Docker Engine that keeps it running in the background. Inside the container, the process runs in the foreground. The process might be a web server or a console application polling a message queue for work, but as long as the process keeps running, Docker will keep the container alive.
I can run a background container from the same image again, specifying the detach option and a command that runs for some minutes:
> docker container run --detach dockeronwindows/ch02-powershell-env:2e `
powershell Test-Connection 'localhost' -Count 100
bb326e5796bf48199a9a6c4569140e9ca989d7d8f77988de7a96ce0a616c88e9
In this case when the container has launched, control returns to the terminal; the long random string is the ID of the new container. You can run docker container ls and see the container running, and the docker container logs command shows you the console output from the container. For commands operating on specific containers, you can reference them by the container name or by part of the container ID - IDs are random, in my case this container ID begins bb3:
> docker container logs bb3
Source Destination IPV4Address IPV6Address
------ ----------- ----------- -----------
BB326E5796BF localhost 127.0.0.1 ::1
BB326E5796BF localhost 127.0.0.1 ::1
The --detach flag detaches the container so that it moves into the background, and the command in this case just pings localhost repeatedly one hundred times. After a few minutes, the PowerShell command completes so there's no process running and the container exits.
Now you've seen that a container is created from an image, but it can run in different ways. So you can use the image exactly as it was prepared, or treat the image as a template with a default startup mode built in. Next, I'll show you how to build that image.
- 鴻蒙生態(tài):開啟萬物互聯(lián)的智慧新時(shí)代
- Linux網(wǎng)絡(luò)操作系統(tǒng)與實(shí)訓(xùn)(第三版)
- Windows Phone 7.5 Data Cookbook
- 新手學(xué)電腦從入門到精通(Windows 10+Office 2016版)
- Linux內(nèi)核觀測(cè)技術(shù)BPF
- 蘋果OS X Mavericks 10.9應(yīng)用大全
- AWS Development Essentials
- Kali Linux 2018:Windows Penetration Testing
- 云原生落地:產(chǎn)品、架構(gòu)與商業(yè)模式
- Troubleshooting Docker
- Linux網(wǎng)絡(luò)配置與安全管理
- Windows Vista終極技巧金典
- Implementing Domain-Specific Languages with Xtext and Xtend(Second Edition)
- 電腦辦公(Windows 7 + Office 2013)入門與提高
- PrimeFaces Beginner's Guide