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

Building good citizens for Docker

The Docker platform makes very few demands on applications that want to use it. You're not restricted to certain languages or frameworks, and you don't need to use special libraries to communicate from the app to the container and you don't need to structure your application in a certain way.

To support the widest possible range of applications, Docker uses the console to communicate between the application and the container runtime. Application logs and error messages are expected on the console output and error streams. Storage managed by Docker is presented as a normal disk to the operating system, and Docker's networking stack is transparent. The application appears to be running on its own machine, connected to other machines by a normal TCP/IP network.

A good citizen for Docker is an app that makes very few assumptions about the system it's running on and uses basic mechanisms that all operating systems support: the filesystem, environment variables, networking, and the console. Most importantly, the application should only do one thing. As you've seen, when Docker runs a container, it starts the process specified in the Dockerfile or the command line, and it watches that process. When the process ends, the container exits, so ideally, you should build your app to have a single process, which ensures Docker is watching the process that matters.

These are recommendations, though, not requirements. You can start multiple processes in a bootstrap script when a container runs and Docker will run it happily, but it will only monitor the last process that started. Your apps can write log entries to local files instead of the console and Docker will still run them, but you won't see any output if you use Docker to check the container logs.

In .NET, you can easily meet the recommendations by running a console application, which provides a simplified integration between the application and the host, and it's one reason why all .NET Core apps - including websites and web APIs run as console applications. For legacy .NET apps, you won't be able to make them into perfect citizens, but you can extend them to make good use of the Docker platform.

主站蜘蛛池模板: 德化县| 三穗县| 浙江省| 金山区| 本溪| 天等县| 宁国市| 墨脱县| 东台市| 全州县| 布尔津县| 贵港市| 五峰| 泰宁县| 错那县| 禄劝| 靖安县| 贵定县| 芒康县| 丰镇市| 西乌珠穆沁旗| 荔浦县| 贵溪市| 沭阳县| 莱西市| 兴山县| 新丰县| 双流县| 汾阳市| 曲麻莱县| 都江堰市| 盐津县| 岑溪市| 芜湖市| 馆陶县| 正阳县| 吉水县| 社会| 马关县| 巴彦淖尔市| 大同县|