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

Building good citizens for Docker

The Docker platform makes very few demands on applications which use it. You're not restricted to certain languages or frameworks, you don't need to use special libraries to communicate between the app and 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. Applications will appear to be running on their own machine, connected to other machines by a normal TCP/IP network.

A good citizen for Docker is an app which makes very few assumptions about the system it's running on, and uses basic mechanisms which 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 starts 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 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. With legacy .NET apps, you won't be able to make them into perfect citizens, but you can take care to package them so that they make good use of the Docker platform.

主站蜘蛛池模板: 莱芜市| 金华市| 榆社县| 舞钢市| 绍兴市| 海兴县| 吴旗县| 英德市| 凉城县| 新竹市| 疏附县| 即墨市| 太谷县| 荔波县| 西城区| 鹿泉市| 临朐县| 怀化市| 茂名市| 南投市| 沽源县| 泗洪县| 隆回县| 富民县| 余庆县| 九寨沟县| 池州市| 建瓯市| 宜阳县| 乌兰浩特市| 邵武市| 太谷县| 手机| 鹿邑县| 谷城县| 新营市| 文昌市| 保康县| 清河县| 鲁甸县| 嘉鱼县|