文档章节

phusion 介绍 (英文快读)

百花
 百花
发布于 2017/02/15 14:34
字数 1632
阅读 4
收藏 0
点赞 0
评论 0

You learned about Docker. It's awesome and you're excited. You go and create a Dockerfile:

FROM ubuntu:16.04

RUN apt-get install all_my_dependencies
ADD my_app_files /my_app

CMD ["/my_app/start.sh"]

Cool, it seems to work. Pretty easy, right?

Not so fast.

You just built a container which contains a minimal operating system, and which only runs your app. But the operating system inside the container is not configured correctly. A proper Unix system should run all kinds of important system services. You're not running them, you're only running your app.

"What do you mean? I'm just using Ubuntu in Docker. Doesn't the OS inside the container take care of everything automatically?"

Not quite. You have Ubuntu installed in Docker. The files are there. But that doesn't mean Ubuntu's running as it should.

When your Docker container starts, only the CMD command is run. The only processes that will be running inside the container is the CMD command, and all processes that it spawns. That's why all kinds of important system services are not run automatically – you have to run them yourself.

Furthermore, Ubuntu is not designed to be run inside Docker. Its init system, Upstart, assumes that it's running on either real hardware or virtualized hardware, but not inside a Docker container, which is a locked down environment with e.g. no direct access to many kernel resources. Normally, that's okay: inside a container you don't want to run Upstart anyway. You don't want a full system, you want a minimal system. But configuring that minimal system for use within a container has many strange corner cases that are hard to get right if you are not intimately familiar with the Unix system model. This can cause a lot of strange problems.

"What important system services am I missing?"

correct init process

Main article: Docker and the PID 1 zombie reaping problem

Here's how the Unix process model works. When a system is started, the first process in the system is called the init process, with PID 1. The system halts when this processs halts. If you callCMD ["/my_app/start.sh"] in your Dockerfile, then start.sh is your init process.

But the init process has an extra responsibility. It inherits allorphaned child processes. It is expected that the init process reaps them.

Most likely, your init process is not doing that at all. As a result your container will become filled with zombie processes over time.

Furthermore, docker stop sends SIGTERM to the init process, which is then supposed to stop all services. If your init process is your app, then it'll probably only shut down itself, not all the other processes in the container. The kernel will then forcefully kill those other processes, not giving them a chance to gracefully shut down, potentially resulting in file corruption, stale temporary files, etc. You really want to shut down all your processes gracefully.

syslog

Syslog is the standard Unix logging service. A syslog daemon is necessary so that many services - including the kernel itself - can correctly log to /var/log/syslog. If no syslog daemon is running, a lot of important messages are silently swallowed. You don't want warnings and errors to be silently swallowed, do you?

The syslog daemon is not run automatically. You have to start it yourself.

cron

Many apps use cron services. But cron jobs never get run until the cron daemon is running in your container.

The cron daemon is not run automatically. You have to start it yourself.

SSH daemon (sometimes)

Occasionally, you may want to run a command inside the container for contingency reasons. For example you may want to debug your misbehaving app. docker exec provides a great way of doing this, but unfortunately there are a number of drawbacks. For example, users who run docker exec must have access to the Docker daemon, and that way they essentially have root access over the Docker host.

If that is problematic, then you should use SSH to log into the container instead. SSH has its own issues, like requiring key management, but that way you can prevent people from getting root access on the Docker host.

"Does all this apply too if I'm using CentOS inside the container, or another Linux distribution?"

Yes. The problem exist in those cases too.

"But I thought Docker is about running a single process in a container?"

Absolutely not true. Docker runs fine with multiple processes in a container. In fact, there is no technical reason why you should limit yourself to one process – it only makes things harder for you and breaks all kinds of essential system functionality, e.g. syslog.

We encourage you to use multiple processes.

Managing multiple processes can be painful, but it doesn't have to. We have a solution for that, so read on.

Getting everything right: baseimage-docker

 

Solving all the aforementioned problems is a huge pain. I'm sure you have better things to do than to worry about them. That's wherebaseimage-docker jumps in.

Baseimage-docker is a special Docker image that is configured for correct use within Docker containers. It is Ubuntu, plus:

  • Modifications for Docker-friendliness.
  • Administration tools that are especially useful in the context of Docker.
  • Mechanisms for easily running multiple processes, without violating the Docker philosophy.

Also, every single one of the aforementioned problems are taken care of for you.

You can use it as a base for your own Docker images. That means it's available for pulling from the Docker registry!

Github Docker registry Discussion forum Twitter Blog

Why use baseimage-docker?

You can configure the stock ubuntu image yourself from your Dockerfile, so why bother using baseimage-docker?

What's included?

correct init process

Baseimage-docker comes with an init process /sbin/my_initthat reaps orphaned child processes correctly, and responds to SIGTERM correctly. This way your container won't become filled with zombie processes, and docker stop will work correctly.

Fixes APT incompatibilities with Docker

See Docker issue #1024.

syslog-ng

It runs a syslog daemon so that important system messages don't get lost.

cron daemon

It runs a cron daemon so that cronjobs work.

SSH server

Allows you to easily login to your container to inspect or administer things.

SSH is only one of the methods provided by baseimage-docker for this purpose. The other method is through `docker exec`. SSH is also provided as an option because `docker exec` has issues.

Password and challenge-response authentication are disabled by default. Only key authentication is allowed.

The SSH daemon is disabled by default.

runit

Used for service supervision and management. Much easier to use than SysV init and supports restarting daemons when they crash. Much easier to use and more lightweight than Upstart.

Baseimage-docker encourages you to run multiple processes through the use of runit.

You might be familiar with supervisord. Runit (written in C) is much lighter weight than supervisord (written in Python).

setuser

A custom tool for running a command as another user. Easier to use than su, has a smaller attack vector than sudo, and unlike chpst this tool sets $HOME correctly. Available as/sbin/setuser.

Despite all these components, baseimage-docker is extremely lightweight: it only consumes 6 MB of memory.

  • Stop reinventing the wheel.
    Configuring the base system for Docker-friendliness is no easy task. As stated before, there are many corner cases. By the time that you've gotten all that right, you've reinvented baseimage-docker. Using baseimage-docker will save you from this effort.
  • Reduce development time.
    It reduces the time needed to write a correct Dockerfile. You won't have to worry about the base system and can focus on your stack and your app.
  • Reduce building time.
    It reduces the time needed to run docker build, allowing you to iterate your Dockerfile more quickly.
  • Reduce deployment time.
    It reduces download time during redeploys. Docker only needs to download the base image once: during the first deploy. On every subsequent deploys, only the changes you make on top of the base image are downloaded.

GETTING STARTED NOW

 

The image is called phusion/baseimage, and is available on the Docker registry.

Example Dockerfile:

# Use phusion/baseimage as base image. To make your builds
# reproducible, make sure you lock down to a specific version, not
# to `latest`! See
# https://github.com/phusion/baseimage-docker/blob/master/Changelog.md
# for a list of version numbers.
FROM phusion/baseimage:<VERSION>

# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]

# ...put your own build instructions here...

# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Adding additional daemons

You can add additional daemons (e.g. your own app) to the image by creating runit entries. You only have to write a small shell script which runs your daemon, and runit will keep it up and running for you, restarting it when it crashes, etc.

The shell script must be called run, must be executable, and is to be placed in the directory /etc/service/<NAME>.

Here's an example showing you how a memcached server runit entry can be made.

### In memcached.sh (make sure this file is chmod +x):
#!/bin/sh
# `/sbin/setuser memcache` runs the given command as the user `memcache`.
# If you omit that part, the command will be run as root.
exec /sbin/setuser memcache /usr/bin/memcached >>/var/log/memcached.log 2>&1

### In Dockerfile:
RUN mkdir /etc/service/memcached
ADD memcached.sh /etc/service/memcached/run

Note that the shell script must run the daemon without letting it daemonize/fork it. Usually, daemons provide a command line flag or a config file option for that.

More documentation

This website only covers the basics. Please refer to the Github repositoryfor more documentation. Topics include:

Having problems? Want to participate in development? Please post a message at the discussion forum.

© 著作权归作者所有

共有 人打赏支持
百花
粉丝 1
博文 65
码字总数 25011
作品 0
海淀
架构师
Ruby 企业版切换至 Ruby 1.8.7

Phusion发布了新的Ruby Enterprise Edition,版本号为1.8.7-20090928。之前的版本都基于Ruby 1.8.6,该版本开始基于Ruby 1.8.7。Ruby 1.8.7发布已经有段时间了,为什么现在才切换到1.8.7呢?...

红薯 ⋅ 2009/10/16 ⋅ 0

自然语言处理之路:前提——英文能力

一个自然语言处理炼丹师的自白 临近毕业,刚交完论文,自转研究室已一年有余。前天参加越南人社群 BBQ 时,去年这个时候 Chien 桑和熊孩子打闹的场景还历历在目。想想如今他都做了快一年CEO...

坂本龙一 ⋅ 05/07 ⋅ 0

简单的使用java短信猫

主要是想用短息猫做一个群发信息的功能 由于没有接触过之前,求各位大神简单的介绍下具体要实现那些接口;怎么去读com端口;如何实现群发~ 简单指点下 或者 介绍下 相关的文章或者网站都行 英文...

Wa_凹 ⋅ 2012/07/16 ⋅ 2

英语学习手机应用推荐

图片发自简书App ✍写在前面 继上次分享了日常生活和学习的app后,有不少人让我推荐一些学习英语的app或是公众号。因为在之前的英语使用app里头我有介绍过我常用的app,所以在这里我就不专门...

lily哩离理力 ⋅ 2017/11/24 ⋅ 0

我需要你马上把这个小问题修改好

“我需要”,“小问题”,“立刻”。你激怒我了。你的每个词都激怒我了。这种情绪很难翻译成英语表达,但在荷兰,有些人就是用这种方式要求你。翻译 成英语,这有点像“你要几分钟内把这个东...

oschina ⋅ 2013/12/06 ⋅ 38

Phusion Passenger 3.0.0 最终版发布

近日,Phusion Passenger 3.0.0最终版发布了! Phusion Passenger是一个Apache和Nginx模块,在Apache/nginx上安装好以后部署Rails应用也可以简单得像PHP一样:直接上传文件到某个目录就好了。...

鉴客 ⋅ 2010/10/21 ⋅ 0

Rails 支持模块--Phusion Passenger

Phusion Passenger,原名 mod_rails ,是一个旨在从Apache和Nginx网页服务器上更便捷的部署Ruby on Rails项目的Apache模块。 该项目的创始人如此介绍这个东西: Phusion是我们公司的名字,然...

匿名 ⋅ 2009/01/27 ⋅ 1

如何在六个月内学会一门外语

我对中国人学习英语的方法感到很惊讶。特别是现在中小学的英语教育方式。 在学校,我的英语一直都很差。因为我觉得为了考试去学,而且学习方式,我认为太没意思。现在我的英语说与写的能力依...

翟志军 ⋅ 2014/04/17 ⋅ 13

Phusion Passenger 4.0 beta 1 发布

Phusion Passenger,原名 modrails ,是一个旨在从Apache和Nginx网页服务器上更便捷的部署Ruby on Rails项目的Apache模块。更详细介绍请看这里。 Phusion Passenger 4.0 beta 1 主要改进内容...

oschina ⋅ 2012/10/25 ⋅ 1

英文文档翻译

对于前几天翻译的两篇 Lua1.1 英文文档的一个总结。虽然这两篇发出来是一天一篇,翻译的时候却没有那么快。是用业余时间,一点一点的攒出来的。 以前虽然读英文文档,但都是看明白意思即可,...

晓寒 ⋅ 2014/09/05 ⋅ 1

没有更多内容

加载失败,请刷新页面

加载更多

下一页

Spring Boot整合模板引擎thymeleaf

项目结构 引入依赖pom.xml <!-- 引入 thymeleaf 模板依赖 --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId......

yysue ⋅ 7分钟前 ⋅ 0

ConstraintLayout使用解析

AndroidStudio3.0创建Project默认的布局就是ConstraintLayout。 AndroidStudio3.0前的可以自己修改,使用ConstraintLayout。 为了要使用ConstraintLayout,我们需要在app/build.gradle文件中...

_OUTMAN_ ⋅ 19分钟前 ⋅ 0

OSChina 周三乱弹 —— 这样的女人私生活太混乱了

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @ 胖达panda :你经历过体验到人生的大起大落吗?我一朋友在10秒内体验了,哈哈。@小小编辑 请点一首《almost lover》送给他。 《almost love...

小小编辑 ⋅ 52分钟前 ⋅ 8

自己动手写一个单链表

文章有不当之处,欢迎指正,如果喜欢微信阅读,你也可以关注我的微信公众号:好好学java,获取优质学习资源。 一、概述 单向链表(单链表)是链表的一种,其特点是链表的链接方向是单向的,对...

公众号_好好学java ⋅ 57分钟前 ⋅ 0

Centos7重置Mysql 8.0.1 root 密码

问题产生背景: 安装完 最新版的 mysql8.0.1后忘记了密码,向重置root密码;找了网上好多资料都不尽相同,根据自己的问题总结如下: 第一步:修改配置文件免密码登录mysql vim /etc/my.cnf 1...

豆花饭烧土豆 ⋅ 今天 ⋅ 0

熊掌号收录比例对于网站原创数据排名的影响[图]

从去年下半年开始,我在写博客了,因为我觉得业余写写博客也还是很不错的,但是从2017年下半年开始,百度已经推出了原创保护功能和熊掌号平台,为此,我也提交了不少以前的老数据,而这些历史...

原创小博客 ⋅ 今天 ⋅ 0

LVM讲解、磁盘故障小案例

LVM LVM就是动态卷管理,可以将多个硬盘和硬盘分区做成一个逻辑卷,并把这个逻辑卷作为一个整体来统一管理,动态对分区进行扩缩空间大小,安全快捷方便管理。 1.新建分区,更改类型为8e 即L...

蛋黄Yolks ⋅ 今天 ⋅ 0

Hadoop Yarn调度器的选择和使用

一、引言 Yarn在Hadoop的生态系统中担任了资源管理和任务调度的角色。在讨论其构造器之前先简单了解一下Yarn的架构。 上图是Yarn的基本架构,其中ResourceManager是整个架构的核心组件,它负...

p柯西 ⋅ 今天 ⋅ 0

uWSGI + Django @ Ubuntu

创建 Django App Project 创建后, 可以看到路径下有一个wsgi.py的问题 uWSGI运行 直接命令行运行 利用如下命令, 可直接访问 uwsgi --http :8080 --wsgi-file dj/wsgi.py 配置文件 & 运行 [u...

袁祾 ⋅ 今天 ⋅ 0

JVM堆的理解

在JVM中,我们经常提到的就是堆了,堆确实很重要,其实,除了堆之外,还有几个重要的模块,看下图: 大 多数情况下,我们并不需要关心JVM的底层,但是如果了解它的话,对于我们系统调优是非常...

不羁之后 ⋅ 昨天 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部