mirror of
/repos/baseimage-docker.git
synced 2025-12-30 08:01:31 +01:00
Merge tag 'rel-0.9.18' into rasberrypi-0.9.18
This commit is contained in:
commit
f279a80a2c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.vagrant
|
.vagrant
|
||||||
|
*.swp
|
||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
|
|||||||
17
Changelog.md
17
Changelog.md
@ -1,3 +1,20 @@
|
|||||||
|
## 0.9.18 (release date: 2015-12-08)
|
||||||
|
|
||||||
|
* The latest OpenSSL updates have been pulled in. This fixes [CVE-2015-3193](https://www.openssl.org/news/secadv/20151203.txt) and a few others. Upgrading is strongly recommended.
|
||||||
|
|
||||||
|
|
||||||
|
## 0.9.17 (release date: 2015-07-15)
|
||||||
|
|
||||||
|
* The latest OpenSSL updates have been pulled in. This fixes [CVE-2015-1793](http://openssl.org/news/secadv_20150709.txt). Upgrading is strongly recommended.
|
||||||
|
* Removed nano and replaced vim with vim-tiny. This reduces Baseimage-docker's virtual size by 42 MB.
|
||||||
|
* Fixed an issue in `my_init` which could cause it to hang during shutdown. Thanks to Joe "SAPikachu" Hu for contributing the fix. Closes GH-151.
|
||||||
|
* When `my_init` generates `/etc/container_environment.sh`, it now ensures that environment variable names do not include any characters unsupported by Bash. Unsupported characters are now replaced with underscores. This fixes compatibility issues with Docker Compose. Closes GH-230.
|
||||||
|
* `my_init` no longer reads from and writes to `/etc/container_environment` if that directory does not exist. Previously it would abort with an error. This change makes it easier to reuse `my_init` in other (non-Baseimage-docker-based) projects without having to modify it.
|
||||||
|
* Baseimage-docker no longer sets the HOME environment variable by default. We used to set HOME by default to work around [Docker issue 2968](https://github.com/docker/docker/issues/2968) where HOME defaults to /, but this issue is now fixed. Furthermore, the fact that we set HOME interfered with the USER stanza: USER would no longer set HOME. So we got rid of our HOME variable. Closes GH-231.
|
||||||
|
* Some unnecessary Ubuntu cron jobs have been removed. Closes GH-205.
|
||||||
|
* Syslog-ng no longer forwards messages to /dev/tty10. Closes GH-222.
|
||||||
|
* It is now possible to build your own Baseimage-docker variant that has cron, syslog or sshd disabled. Thanks to Enderson Tadeu S. Maia. Closes GH-182.
|
||||||
|
|
||||||
## 0.9.16 (release date: 2015-01-20)
|
## 0.9.16 (release date: 2015-01-20)
|
||||||
|
|
||||||
* `docker exec` is now the default and recommended mechanism for running commands in the container. SSH is now disabled by default, but is still supported for those cases where "docker exec" is not appropriate. Closes GH-168.
|
* `docker exec` is now the default and recommended mechanism for running commands in the container. SSH is now disabled by default, but is still supported for those cases where "docker exec" is not appropriate. Closes GH-168.
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2013-2014 Phusion
|
Copyright (c) 2013-2015 Phusion Holding B.V.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
6
Makefile
6
Makefile
@ -1,5 +1,5 @@
|
|||||||
NAME = aiko/baseimage-pi
|
NAME = aiko/baseimage-pi
|
||||||
VERSION = 0.9.16
|
VERSION = 0.9.18
|
||||||
|
|
||||||
.PHONY: all build test tag_latest release ssh
|
.PHONY: all build test tag_latest release ssh
|
||||||
|
|
||||||
@ -21,9 +21,9 @@ release: test tag_latest
|
|||||||
@echo "*** Don't forget to create a tag. git tag rel-$(VERSION) && git push origin rel-$(VERSION)"
|
@echo "*** Don't forget to create a tag. git tag rel-$(VERSION) && git push origin rel-$(VERSION)"
|
||||||
|
|
||||||
ssh:
|
ssh:
|
||||||
chmod 600 image/insecure_key
|
chmod 600 image/services/sshd/keys/insecure_key
|
||||||
@ID=$$(docker ps | grep -F "$(NAME):$(VERSION)" | awk '{ print $$1 }') && \
|
@ID=$$(docker ps | grep -F "$(NAME):$(VERSION)" | awk '{ print $$1 }') && \
|
||||||
if test "$$ID" = ""; then echo "Container is not running."; exit 1; fi && \
|
if test "$$ID" = ""; then echo "Container is not running."; exit 1; fi && \
|
||||||
IP=$$(docker inspect $$ID | grep IPAddr | sed 's/.*: "//; s/".*//') && \
|
IP=$$(docker inspect $$ID | grep IPAddr | sed 's/.*: "//; s/".*//') && \
|
||||||
echo "SSHing into $$IP" && \
|
echo "SSHing into $$IP" && \
|
||||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i image/insecure_key root@$$IP
|
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i image/services/sshd/keys/insecure_key root@$$IP
|
||||||
|
|||||||
57
README.md
57
README.md
@ -1,5 +1,7 @@
|
|||||||
# A minimal Ubuntu base image modified for Docker-friendliness
|
# A minimal Ubuntu base image modified for Docker-friendliness
|
||||||
|
|
||||||
|
[](https://imagelayers.io/?images=phusion/baseimage:latest 'Get your own badge on imagelayers.io')
|
||||||
|
|
||||||
Baseimage-docker is a special [Docker](https://www.docker.com) image that is configured for correct use within Docker containers. It is Ubuntu, plus:
|
Baseimage-docker is a special [Docker](https://www.docker.com) image that is configured for correct use within Docker containers. It is Ubuntu, plus:
|
||||||
|
|
||||||
* Modifications for Docker-friendliness.
|
* Modifications for Docker-friendliness.
|
||||||
@ -52,6 +54,7 @@ You can configure the stock `ubuntu` image yourself from your Dockerfile, so why
|
|||||||
* [Environment variable dumps](#envvar_dumps)
|
* [Environment variable dumps](#envvar_dumps)
|
||||||
* [Modifying environment variables](#modifying_envvars)
|
* [Modifying environment variables](#modifying_envvars)
|
||||||
* [Security](#envvar_security)
|
* [Security](#envvar_security)
|
||||||
|
* [Upgrading the operating system inside the container](#upgrading_os)
|
||||||
* [Container administration](#container_administration)
|
* [Container administration](#container_administration)
|
||||||
* [Running a one-shot command in a new container](#oneshot)
|
* [Running a one-shot command in a new container](#oneshot)
|
||||||
* [Running a command in an existing, running container](#run_inside_existing_container)
|
* [Running a command in an existing, running container](#run_inside_existing_container)
|
||||||
@ -65,6 +68,7 @@ You can configure the stock `ubuntu` image yourself from your Dockerfile, so why
|
|||||||
* [Using your own key](#using_your_own_key)
|
* [Using your own key](#using_your_own_key)
|
||||||
* [The `docker-ssh` tool](#docker_ssh)
|
* [The `docker-ssh` tool](#docker_ssh)
|
||||||
* [Building the image yourself](#building)
|
* [Building the image yourself](#building)
|
||||||
|
* [Removing optional services](#removing_optional_services)
|
||||||
* [Conclusion](#conclusion)
|
* [Conclusion](#conclusion)
|
||||||
|
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
@ -135,12 +139,12 @@ The image is called `phusion/baseimage`, and is available on the Docker registry
|
|||||||
# See https://github.com/phusion/baseimage-docker/blob/master/Changelog.md for
|
# See https://github.com/phusion/baseimage-docker/blob/master/Changelog.md for
|
||||||
# a list of version numbers.
|
# a list of version numbers.
|
||||||
FROM phusion/baseimage:<VERSION>
|
FROM phusion/baseimage:<VERSION>
|
||||||
|
|
||||||
# Use baseimage-docker's init system.
|
# Use baseimage-docker's init system.
|
||||||
CMD ["/sbin/my_init"]
|
CMD ["/sbin/my_init"]
|
||||||
|
|
||||||
# ...put your own build instructions here...
|
# ...put your own build instructions here...
|
||||||
|
|
||||||
# Clean up APT when done.
|
# Clean up APT when done.
|
||||||
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
@ -153,13 +157,15 @@ The shell script must be called `run`, must be executable, and is to be placed i
|
|||||||
|
|
||||||
Here's an example showing you how a memcached server runit entry can be made.
|
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):
|
In `memcached.sh` (make sure this file is chmod +x):
|
||||||
|
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# `/sbin/setuser memcache` runs the given command as the user `memcache`.
|
# `/sbin/setuser memcache` runs the given command as the user `memcache`.
|
||||||
# If you omit that part, the command will be run as root.
|
# 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
|
exec /sbin/setuser memcache /usr/bin/memcached >>/var/log/memcached.log 2>&1
|
||||||
|
|
||||||
### In Dockerfile:
|
In `Dockerfile`:
|
||||||
|
|
||||||
RUN mkdir /etc/service/memcached
|
RUN mkdir /etc/service/memcached
|
||||||
ADD memcached.sh /etc/service/memcached/run
|
ADD memcached.sh /etc/service/memcached/run
|
||||||
|
|
||||||
@ -177,11 +183,13 @@ All scripts must exit correctly, e.g. with exit code 0. If any script exits with
|
|||||||
|
|
||||||
The following example shows how you can add a startup script. This script simply logs the time of boot to the file /tmp/boottime.txt.
|
The following example shows how you can add a startup script. This script simply logs the time of boot to the file /tmp/boottime.txt.
|
||||||
|
|
||||||
### In logtime.sh (make sure this file is chmod +x):
|
In `logtime.sh` (make sure this file is chmod +x):
|
||||||
|
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
date > /tmp/boottime.txt
|
date > /tmp/boottime.txt
|
||||||
|
|
||||||
### In Dockerfile:
|
In `Dockerfile`:
|
||||||
|
|
||||||
RUN mkdir -p /etc/my_init.d
|
RUN mkdir -p /etc/my_init.d
|
||||||
ADD logtime.sh /etc/my_init.d/logtime.sh
|
ADD logtime.sh /etc/my_init.d/logtime.sh
|
||||||
|
|
||||||
@ -270,6 +278,17 @@ If you are sure that your environment variables don't contain sensitive data, th
|
|||||||
RUN chmod 755 /etc/container_environment
|
RUN chmod 755 /etc/container_environment
|
||||||
RUN chmod 644 /etc/container_environment.sh /etc/container_environment.json
|
RUN chmod 644 /etc/container_environment.sh /etc/container_environment.json
|
||||||
|
|
||||||
|
<a name="upgrading_os"></a>
|
||||||
|
### Upgrading the operating system inside the container
|
||||||
|
|
||||||
|
Baseimage-docker images contain an Ubuntu 14.04 operating system. You may want to update this OS from time to time, for example to pull in the latest security updates. OpenSSL is a notorious example. Vulnerabilities are discovered in OpenSSL on a regular basis, so you should keep OpenSSL up-to-date as much as you can.
|
||||||
|
|
||||||
|
While we release Baseimage-docker images with the latest OS updates from time to time, you do not have to rely on us. You can update the OS inside Baseimage-docker images yourself, and it is recommend that you do this instead of waiting for us.
|
||||||
|
|
||||||
|
To upgrade the OS in the image, run this in your Dockerfile:
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get upgrade -y -o Dpkg::Options::="--force-confold"
|
||||||
|
|
||||||
<a name="container_administration"></a>
|
<a name="container_administration"></a>
|
||||||
## Container administration
|
## Container administration
|
||||||
|
|
||||||
@ -380,7 +399,7 @@ Here's how it compares to [using `docker exec` to login to the container or to r
|
|||||||
Baseimage-docker disables the SSH server by default. Add the following to your Dockerfile to enable it:
|
Baseimage-docker disables the SSH server by default. Add the following to your Dockerfile to enable it:
|
||||||
|
|
||||||
RUN rm -f /etc/service/sshd/down
|
RUN rm -f /etc/service/sshd/down
|
||||||
|
|
||||||
# Regenerate SSH host keys. baseimage-docker does not contain any, so you
|
# Regenerate SSH host keys. baseimage-docker does not contain any, so you
|
||||||
# have to do that yourself. You may also comment out this instruction; the
|
# have to do that yourself. You may also comment out this instruction; the
|
||||||
# init system will auto-generate one during boot.
|
# init system will auto-generate one during boot.
|
||||||
@ -389,7 +408,7 @@ Baseimage-docker disables the SSH server by default. Add the following to your D
|
|||||||
<a name="ssh_keys"></a>
|
<a name="ssh_keys"></a>
|
||||||
#### About SSH keys
|
#### About SSH keys
|
||||||
|
|
||||||
First, you must ensure that you have the right SSH keys installed inside the container. By default, no keys are installed, so nobody can login. For convenience reasons, we provide [a pregenerated, insecure key](https://github.com/phusion/baseimage-docker/blob/master/image/insecure_key) [(PuTTY format)](https://github.com/phusion/baseimage-docker/blob/master/image/insecure_key.ppk) that you can easily enable. However, please be aware that using this key is for convenience only. It does not provide any security because this key (both the public and the private side) is publicly available. **In production environments, you should use your own keys**.
|
First, you must ensure that you have the right SSH keys installed inside the container. By default, no keys are installed, so nobody can login. For convenience reasons, we provide [a pregenerated, insecure key](https://github.com/phusion/baseimage-docker/blob/master/image/services/sshd/keys/insecure_key) [(PuTTY format)](https://github.com/phusion/baseimage-docker/blob/master/image/services/sshd/keys/insecure_key.ppk) that you can easily enable. However, please be aware that using this key is for convenience only. It does not provide any security because this key (both the public and the private side) is publicly available. **In production environments, you should use your own keys**.
|
||||||
|
|
||||||
<a name="using_the_insecure_key_for_one_container_only"></a>
|
<a name="using_the_insecure_key_for_one_container_only"></a>
|
||||||
#### Using the insecure key for one container only
|
#### Using the insecure key for one container only
|
||||||
@ -411,7 +430,7 @@ Once you have the ID, look for its IP address with:
|
|||||||
Now that you have the IP address, you can use SSH to login to the container, or to execute a command inside it:
|
Now that you have the IP address, you can use SSH to login to the container, or to execute a command inside it:
|
||||||
|
|
||||||
# Download the insecure private key
|
# Download the insecure private key
|
||||||
curl -o insecure_key -fSL https://github.com/phusion/baseimage-docker/raw/master/image/insecure_key
|
curl -o insecure_key -fSL https://github.com/phusion/baseimage-docker/raw/master/image/services/sshd/keys/insecure_key
|
||||||
chmod 600 insecure_key
|
chmod 600 insecure_key
|
||||||
|
|
||||||
# Login to the container
|
# Login to the container
|
||||||
@ -506,6 +525,24 @@ If you want to call the resulting image something else, pass the NAME variable,
|
|||||||
|
|
||||||
make build NAME=joe/baseimage
|
make build NAME=joe/baseimage
|
||||||
|
|
||||||
|
<a name="removing_optional_services"></a>
|
||||||
|
### Removing optional services
|
||||||
|
|
||||||
|
The default baseimage-docker installs `syslog-ng`, `cron` and `sshd` services during the build process.
|
||||||
|
|
||||||
|
In case you don't need one or more of these services in your image, you can disable its installation.
|
||||||
|
|
||||||
|
As shown in the following example, to prevent `sshd` from being installed into your image, set `1` to the `DISABLE_SSH` variable in the `./image/buildconfig` file.
|
||||||
|
|
||||||
|
### In ./image/buildconfig
|
||||||
|
# ...
|
||||||
|
# Default services
|
||||||
|
# Set 1 to the service you want to disable
|
||||||
|
export DISABLE_SYSLOG=0
|
||||||
|
export DISABLE_SSH=1
|
||||||
|
export DISABLE_CRON=0
|
||||||
|
|
||||||
|
Then you can proceed with `make build` command.
|
||||||
|
|
||||||
<a name="conclusion"></a>
|
<a name="conclusion"></a>
|
||||||
## Conclusion
|
## Conclusion
|
||||||
|
|||||||
113
README_ZH_cn_.md
113
README_ZH_cn_.md
@ -1,100 +1,97 @@
|
|||||||
# 小巧玲珑的ubuntu镜像
|
<a name="a-minimal-ubuntu-base-image-modified-for-docker-friendliness"></a>
|
||||||
|
# Docker友好的,最小的Ubuntu基础镜像
|
||||||
|
|
||||||
**This translation was last updated October 24, 2014.**
|
Baseimage-docker是一个特殊的[Docker](http://www.docker.io)镜像,在Docker容器内做了配置,并且可以正确使用。它确实是一个Ubuntu系统, 除此之外进行了如下修订:
|
||||||
|
|
||||||
Baseimage-docker是一个特殊的 [Docker](https://www.docker.com) 镜像,可以很优雅的将它用于docker镜像。相对于 Ubuntu, 有这些新增:
|
* 为更加友好的支持Docker,做了修订。
|
||||||
|
* 在Docker环境下,作为管理工具特别有用。
|
||||||
|
* 在[不违反Docker哲学](#docker_single_process)的前提下,能够很容易的运行多进程的机制。
|
||||||
|
|
||||||
* 修改之后,可以很友好的使用docker
|
可以把它作为自己的基础Docker镜像。
|
||||||
* 修复了一些docker的bug [some Docker bugs](#workaroud_modifying_etc_hosts).
|
|
||||||
* 很有用的管理员工具
|
|
||||||
|
|
||||||
你可以用它作为你自己的基础docker镜像。
|
Baseimage-docker项目可以直接从Docker的[registry](https://index.docker.io/u/phusion/baseimage/)获取!
|
||||||
|
|
||||||
|
<a name="what-are-the-problems-with-the-stock-ubuntu-base-image"></a>
|
||||||
|
### 原生的Ubuntu基础镜像有什么问题呢?
|
||||||
|
|
||||||
|
原生Ubuntu不是为了在Docker内运行而设计的。它的初始化系统Upstart,假定运行的环境要么是真实的硬件,要么是虚拟的硬件,而不是在Docker容器内。但是在一个Docker的容器内,并不需要一个完整的系统,你需要的只是一个很小的系统。但是如果你不是非常熟悉Unix的系统模型,想要在Docker容器内裁减出最小的系统,会碰到很多难以正确解决的陌生的技术坑。这些坑会引起很多莫名其妙的问题。
|
||||||
|
|
||||||
Baseimage-docker 可以从[the Docker registry](https://registry.hub.docker.com/u/phusion/baseimage/)获取到!
|
Baseimage-docker让这一切完美。在"内容"部分描述了所有这些修改。
|
||||||
|
|
||||||
### 原生的ubuntu基础镜像有什么问题呢?
|
<a name="why-use-baseimage-docker"></a>
|
||||||
|
### 为什么使用baseimage-docker?
|
||||||
|
|
||||||
原生ubuntu不是设计为运行docker的。它是假设运行到真实硬件或者虚拟硬件上的,但不是docker容器。你运行docker容器,不需要一个完整的系统,你需要一个小巧的系统。如果你不熟悉unix系统,那么配制出来的精简系统会有很奇怪的问题。这样就可以导致很多奇奇怪怪的问题。
|
你自己可以从Dockerfile配置一个原生`ubuntu`镜像,为什么还要多此一举的使用baseimage-docker呢?
|
||||||
|
|
||||||
Baseimage-docker 将错误都修正了。在"内容"部分,可以看到哪些内容修改过了.
|
* 配置一个Docker友好的基础系统并不是一个简单的任务。如前所述,过程中会碰到很多坑。当你搞定这些坑之后,只不过是又重新发明了一个baseimage-docker而已。使用baseimage-docker可以免去你这方面需要做的努力。
|
||||||
|
* 减少需要正确编写Dockerfile文件的时间。你不用再担心基础系统,可以专注于你自己的技术栈和你的项目。
|
||||||
<a name="why_use"></a>
|
* 减少需要运行`docker build`的时间,让你更快的迭代Dockerfile。
|
||||||
### 为什么使用 baseimage-docker?
|
* 减少了重新部署的时的下载时间。Docker只需要在第一次部署的时候下载一次基础镜像。在随后的部署中,只需要改变你下载之后对基础镜像进行修改的部分。
|
||||||
|
|
||||||
你可以用原生`ubuntu`镜像作为你的Dockerfile,那为什么又麻烦的使用baseimage-docker呢?
|
|
||||||
|
|
||||||
* 配置一个友好的基础镜像不是一个简单的任务.正如之前提到的,会很有的坑在里面.当你处理那些坑之后,你又重复造了一个baseimage-docker.使用baseimage-docker会拯救你的努力.
|
|
||||||
* 它减少了一个写正确Dockerfile文件的时间.你不用担心基础系统,你可以专注你的业务和你的项目.
|
|
||||||
* 它减少了运行`docker build`的时间,让你更快的迭代Dockerfile.
|
|
||||||
* 它减少了多次下载的时间.Docker只需要下载一次基础镜像:在第一次部署的时候.在之后的部署中,只需要对你最近的基础镜像进行修改.
|
|
||||||
|
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
**相关资源**
|
**相关资源**
|
||||||
|
|
||||||
[Website](http://phusion.github.io/baseimage-docker/) |
|
[网站](http://phusion.github.io/baseimage-docker/) |
|
||||||
[Github](https://github.com/phusion/baseimage-docker) |
|
[Github](https://github.com/phusion/baseimage-docker) |
|
||||||
[Docker registry](https://index.docker.io/u/phusion/baseimage/) |
|
[Docker registry](https://index.docker.io/u/phusion/baseimage/) |
|
||||||
[Discussion forum](https://groups.google.com/d/forum/passenger-docker) |
|
[论坛](https://groups.google.com/d/forum/passenger-docker) |
|
||||||
[Twitter](https://twitter.com/phusion_nl) |
|
[Twitter](https://twitter.com/phusion_nl) |
|
||||||
[Blog](http://blog.phusion.nl/)
|
[Blog](http://blog.phusion.nl/)
|
||||||
|
|
||||||
**Table of contents**
|
|
||||||
**目录**
|
**目录**
|
||||||
|
|
||||||
* [镜像里面包含什么?](#whats_inside)
|
* [镜像里面有什么?](#whats_inside)
|
||||||
* [概述](#whats_inside_overview)
|
* [概述](#whats_inside_overview)
|
||||||
* [等等,我认为docker在一个容器中只能允许一个进程?](#docker_single_process)
|
* [等等,我认为Docker在一个容器中只能允许运行一个进程?](#docker_single_process)
|
||||||
* [细细看看baseimage-docker](#inspecting)
|
* [Baseimage-docker更侧重于“胖容器”还是“把容器当作虚拟机”?](#fat_containers)
|
||||||
* [用baseimage-docker作为基础镜像](#using)
|
* [查看baseimage-docker](#inspecting)
|
||||||
|
* [使用baseimage-docker作为基础镜像](#using)
|
||||||
* [开始](#getting_started)
|
* [开始](#getting_started)
|
||||||
* [增加后台进行](#adding_additional_daemons)
|
* [增加额外的后台进程](#adding_additional_daemons)
|
||||||
* [在启动容器过程中允许脚本](#running_startup_scripts)
|
* [容器启动时运行脚本](#running_startup_scripts)
|
||||||
* [环境变量](#environment_variables)
|
* [环境变量](#environment_variables)
|
||||||
* [集中定义你自己的环境变量](#envvar_central_definition)
|
* [集中定义自己的环境变量](#envvar_central_definition)
|
||||||
* [保存环境变量](#envvar_dumps)
|
* [保存环境变量](#envvar_dumps)
|
||||||
* [修改环境变量](#modifying_envvars)
|
* [修改环境变量](#modifying_envvars)
|
||||||
* [安全性](#envvar_security)
|
* [安全性](#envvar_security)
|
||||||
* [解决docker没有办法修改/etc/hosts的问题](#workaroud_modifying_etc_hosts)
|
|
||||||
* [禁用ssh](#disabling_ssh)
|
|
||||||
* [容器管理](#container_administration)
|
* [容器管理](#container_administration)
|
||||||
* [在一个新容器中运行单条命令](#oneshot)
|
* [在一个新容器中运行单条命令](#oneshot)
|
||||||
* [在正在运行的的容器中运行命令](#run_inside_existing_container)
|
* [在正在运行的的容器中运行一条命令](#run_inside_existing_container)
|
||||||
* [通过nsenter登录容器](#login_nsenter)
|
* [通过`docer exec`登录容器](#login_docker_exec)
|
||||||
* [用法](#nsenter_usage)
|
* [用法](#nsenter_usage)
|
||||||
* [`docker-bash`工具](#docker_bash)
|
* [使用SSH登录容器](#login_ssh)
|
||||||
* [使用ssh登录容器](#login_ssh)
|
* [启用SSH](#enabling_ssh)
|
||||||
* [在容器中使用不安全的key](#using_the_insecure_key_for_one_container_only)
|
* [关于SSH的key](#ssh_keys)
|
||||||
* [支持长久不变的不安全的key](#enabling_the_insecure_key_permanently)
|
* [只对一个容器使用不安全key](#using_insecure_key_for_one_container_only)
|
||||||
|
* [永久开启不安全key](#enabling_the_insecure_key_permanently)
|
||||||
* [使用你自己的key](#using_your_own_key)
|
* [使用你自己的key](#using_your_own_key)
|
||||||
* [`docker-ssh`工具](#docker_ssh)
|
* [`docker-ssh`工具](#docker_ssh)
|
||||||
* [构建你自己的镜像](#building)
|
* [构建自己的镜像](#building)
|
||||||
* [总结](#conclusion)
|
* [总结](#conclusion)
|
||||||
|
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
<a name="whats_inside"></a>
|
<a name="whats_inside"></a>
|
||||||
## 镜像里面包含什么?
|
## 镜像里面有什么?
|
||||||
|
|
||||||
<a name="whats_inside_overview"></a>
|
<a name="whats_inside_overview"></a>
|
||||||
### 概述
|
### 概述
|
||||||
|
|
||||||
*想看一个完整的基础镜像?这里有一个包含Ruby,Python Node.js and Meteor的.可以看看[passenger-docker](https://github.com/phusion/passenger-docker).*
|
*想看一个里面包含Ruby,Python,Node.js以及Meteor的完整基础镜像?可以看一下[passenger-docker](https://github.com/phusion/passenger-docker)。*
|
||||||
|
|
||||||
| 模块 | 包含什么 / 备注 |
|
| 模块 | 为什么包含这些?以及备注 |
|
||||||
| ---------------- | ------------------- |
|
| ---------------- | ------------------- |
|
||||||
| Ubuntu 14.04 LTS | 基础系统. |
|
| Ubuntu 14.04 LTS | 基础系统。 |
|
||||||
| 一个**正确**的初始化进程 | 根据Unix进程模型,[初始化进程](https://en.wikipedia.org/wiki/Init) -- PID 1 -- 继承了所有[孤立的子进行],并且必须[监控他们](https://en.wikipedia.org/wiki/Wait_(system_call)).大多数Docker容器没有一个正确的初始化进程,结果是他们的容器就出现了大量的[僵尸进程](https://en.wikipedia.org/wiki/Zombie_process).<br><br>此外,`docker stop`发送终止信号给初始化进程,然后停止所有的服务进程.不幸的是,由于他们主机关闭了容器,大多初始系统没有正确运行.<br><br>Baseimage-docker包含了一个初始进程`/sbin/my_init`,来正确的执行这些任务. |
|
| 一个**正确**的初始化进程 | *主要文章:[Docker和PID 1 僵尸进程回收问题](http://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/)*<br/><br/>根据Unix进程模型,[初始化进程](https://en.wikipedia.org/wiki/Init) -- PID 1 -- 继承了所有[孤立的子进程](https://en.wikipedia.org/wiki/Orphan_process),并且必须[进行回收](https://en.wikipedia.org/wiki/Wait_(system_call))。大多数Docker容器没有一个初始化进程可以正确的完成此操作,随着时间的推移会导致他们的容器出现了大量的[僵尸进程](https://en.wikipedia.org/wiki/Zombie_process)。<br/><br/>而且,`docker stop`发送SIGTERM信号给初始化进程,照理说此信号应该可以停止所有服务。不幸的是由于它们对硬件进行了关闭操作,导致Docker内的大多数初始化系统没有正确执行。这会导致进程强行被SIGKILL信号关闭,从而丧失了一个正确取消初始化设置的机会。这会导致文件损坏。<br/><br/>Baseimage-docker配有一个名为`/sbin/my_init`的初始化进程来同时正确的完成这些任务。 |
|
||||||
| 修复了APT 与docker不兼容的问题 | See https://github.com/dotcloud/docker/issues/1024. |
|
| 修复了APT与Docker不兼容的问题 | 详情参见:https://github.com/dotcloud/docker/issues/1024 。 |
|
||||||
| 修复某些Docker bugs | [Learn more.](#workaroud_modifying_etc_hosts) |
|
| syslog-ng | 对于很多服务-包括kernel自身,都需要一个syslog后台进程,以便可以正确的将log输出到/var/log/syslog中。如果没有运行syslog后台进程,很多重要的信息就会默默的丢失了。<br/><br/>只对本地进行监听。所有syslog信息会被转发给“docker logs”。 |
|
||||||
| syslog-ng | 必须要有一个监控很多服务的系统日志进程,包括内核本身,以便可以正确的输出日志到/var/log/syslog.如果没有后台日志进程,那么很多重要的信息就会丢失了.<br><br>只监听本地服务. |
|
| logrotate | 定期转存和压缩日志。 |
|
||||||
| logrotate | logrotate 程序是一个日志文件管理工具,可以定期转存和压缩日志. |
|
| SSH服务 | 允许你很容易的登录到容器中进行[查询或管理](#login_ssh)操作。<br/><br/>_SSH**默认是禁用**的,这也是baseimage-docker为此目的提供的唯一方法。其它方法需要通过[docker exec](#login_docker_exec)。由于`docker exec`同时带来了几个需要注意的问题,SSH同时也提供了一个可替换的方法。_<br/><br/>密码和challenge-response认证方式默认是禁用的。只有key认证通过之后才能够开启。 |
|
||||||
| SSH server | 允许你可以很容易的登录到你的容器中进行[管理](#login_ssh).<br><br>_baseimage-docker提供了一个SSH的方法.还有其他方法,比如通过[nsenter](#login_nsenter).SSH提供了一个方法,因为nsenter还有很多的问题._<br><br>通过密码和challenge-response的方式,默认是禁用的.只有通过key认证的方式是允许的.<br><br>如果你想禁用SSH访问的方式,禁用也是很容易的.可以阅读下面的说明. |
|
| cron | 为了保证cron任务能够工作,必须运行cron后台进程。 |
|
||||||
| cron | 定时任务进程保证定时任务的运行. |
|
| [runit](http://smarden.org/runit/) | 替换Ubuntu的Upstart。用于服务监控和管理。比SysV init更容易使用,同时当这些服务崩溃之后,支持后台进程自动重启。比Upstart更易使用,更加的轻量级。 |
|
||||||
| [runit](http://smarden.org/runit/) | 替代Ubuntu的Upstart. 用于监控服务和管理.比SysV init更容易使用,同时支持当有服务挂掉之后,重启这些服务.比Upstart更易使用,也更加的轻量级. |
|
| `setuser` | 使用其它账户运行命令的工具。比`su`更容易使用,比使用`sudo`有那么一点优势,跟`chpst`不同,这个工具需要正确的设置`$HOME`。像`/sbin/setuser`这样。 |
|
||||||
| `setuser` |使用另一个用户运行命令的工具,比`su`更容易使用,减少使用`sudo`的安全性,不像使用`chpst`,需要正确的设置`$HOME`.`/sbin/setuser`这样使用就可以了. |
|
Baseimage-docker非常的轻量级:仅仅占用6MB内存。
|
||||||
Baseimage-docker is very lightweight: it only consumes 6 MB of memory.
|
|
||||||
Baseimage-docker是非常轻量级的:仅仅小号6MB内存.
|
|
||||||
|
|
||||||
<a name="docker_single_process"></a>
|
<a name="docker_single_process"></a>
|
||||||
### 等等,我认为Docker在一个容器中就运行一个进程吗?
|
### 等等,我认为Docker在一个容器中就运行一个进程吗?
|
||||||
@ -441,7 +438,7 @@ Baseimage-docker提供了一个灵活的方式运行只要一闪而过的命令,
|
|||||||
* 缺点
|
* 缺点
|
||||||
* 需要设置ssh key.然而,baseimage-docker会提供一中办法,会让key的生成会很容器.阅读更多信息.
|
* 需要设置ssh key.然而,baseimage-docker会提供一中办法,会让key的生成会很容器.阅读更多信息.
|
||||||
|
|
||||||
第一件事情,就是你需要确定你在容器中已经安装设置了ssh key. 默认,没有任何安装key的,所有你无法登录.为了方便的原因,我们提供了一个[已经生成的key](https://github.com/phusion/baseimage-docker/blob/master/image/insecure_key) [(PuTTY format)](https://github.com/phusion/baseimage-docker/blob/master/image/insecure_key.ppk),为了让你使用方便.然后,请注意这个key仅仅是为方便.他没有任何安全行,因为它的key是在网络上提供的.**在生产环境,你必须使用你自己的key.**
|
第一件事情,就是你需要确定你在容器中已经安装设置了ssh key. 默认,没有任何安装key的,所有你无法登录.为了方便的原因,我们提供了一个[已经生成的key](https://github.com/phusion/baseimage-docker/blob/master/image/services/sshd/keys/insecure_key) [(PuTTY format)](https://github.com/phusion/baseimage-docker/blob/master/image/services/sshd/keys/insecure_key.ppk),为了让你使用方便.然后,请注意这个key仅仅是为方便.他没有任何安全行,因为它的key是在网络上提供的.**在生产环境,你必须使用你自己的key.**
|
||||||
|
|
||||||
|
|
||||||
<a name="using_the_insecure_key_for_one_container_only"></a>
|
<a name="using_the_insecure_key_for_one_container_only"></a>
|
||||||
@ -464,7 +461,7 @@ Baseimage-docker提供了一个灵活的方式运行只要一闪而过的命令,
|
|||||||
现在你有得了IP地址,你就看通过SSH来登录容器,或者在容器中执行命令了:
|
现在你有得了IP地址,你就看通过SSH来登录容器,或者在容器中执行命令了:
|
||||||
|
|
||||||
# 下载key
|
# 下载key
|
||||||
curl -o insecure_key -fSL https://github.com/phusion/baseimage-docker/raw/master/image/insecure_key
|
curl -o insecure_key -fSL https://github.com/phusion/baseimage-docker/raw/master/image/services/sshd/keys/insecure_key
|
||||||
chmod 600 insecure_key
|
chmod 600 insecure_key
|
||||||
|
|
||||||
# 登录容器
|
# 登录容器
|
||||||
|
|||||||
567
README_zh_tw.md
Normal file
567
README_zh_tw.md
Normal file
@ -0,0 +1,567 @@
|
|||||||
|
<a name="a-minimal-ubuntu-base-image-modified-for-docker-friendliness"></a>
|
||||||
|
# Docker友好的,最小的Ubuntu基礎鏡像
|
||||||
|
|
||||||
|
Baseimage-docker是一個特殊的[Docker](http://www.docker.io)鏡像,在Docker容器內做了配置,並且可以正確使用。它確實是一個Ubuntu系統, 除此之外進行了如下修訂:
|
||||||
|
|
||||||
|
* 爲更加友好的支持Docker,做了修訂。
|
||||||
|
* 在Docker環境下,作爲管理工具特別有用。
|
||||||
|
* 在[不違反Docker哲學](#docker_single_process)的前提下,能夠很容易的運行多行程的機制。
|
||||||
|
|
||||||
|
可以把它作爲自己的基礎Docker鏡像。
|
||||||
|
|
||||||
|
Baseimage-docker項目可以直接從Docker的[registry](https://index.docker.io/u/phusion/baseimage/)獲取!
|
||||||
|
|
||||||
|
<a name="what-are-the-problems-with-the-stock-ubuntu-base-image"></a>
|
||||||
|
### 原生的Ubuntu基礎鏡像有什麼問題呢?
|
||||||
|
|
||||||
|
原生Ubuntu不是爲了在Docker內運行而設計的。它的初始化系統Upstart,假定運行的環境要麼是真實的硬體,要麼是虛擬的硬體,而不是在Docker容器內。但是在一個Docker的容器內,並不需要一個完整的系統,你需要的只是一個很小的系統。但是如果你不是非常熟悉Unix的系統模型,想要在Docker容器內裁減出最小的系統,會碰到很多難以正確解決的陌生的技術坑。這些坑會引起很多莫名其妙的問題。
|
||||||
|
|
||||||
|
Baseimage-docker讓這一切完美。在"內容"部分描述了所有這些修改。
|
||||||
|
|
||||||
|
<a name="why-use-baseimage-docker"></a>
|
||||||
|
### 爲什麼使用baseimage-docker?
|
||||||
|
|
||||||
|
你自己可以從Dockerfile配置一個原生`ubuntu`鏡像,爲什麼還要多此一舉的使用baseimage-docker呢?
|
||||||
|
|
||||||
|
* 配置一個Docker友好的基礎系統並不是一個簡單的任務。如前所述,過程中會碰到很多坑。當你搞定這些坑之後,只不過是又重新發明了一個baseimage-docker而已。使用baseimage-docker可以免去你這方面需要做的努力。
|
||||||
|
* 減少需要正確編寫Dockerfile文件的時間。你不用再擔心基礎系統,可以專注於你自己的技術棧和你的項目。
|
||||||
|
* 減少需要運行`docker build`的時間,讓你更快的迭代Dockerfile。
|
||||||
|
* 減少了重新部署的時的下載時間。Docker只需要在第一次部署的時候下載一次基礎鏡像。在隨後的部署中,只需要改變你下載之後對基礎鏡像進行修改的部分。
|
||||||
|
|
||||||
|
-----------------------------------------
|
||||||
|
|
||||||
|
**相關資源**
|
||||||
|
|
||||||
|
[網站](http://phusion.github.io/baseimage-docker/) |
|
||||||
|
[Github](https://github.com/phusion/baseimage-docker) |
|
||||||
|
[Docker registry](https://index.docker.io/u/phusion/baseimage/) |
|
||||||
|
[論壇](https://groups.google.com/d/forum/passenger-docker) |
|
||||||
|
[Twitter](https://twitter.com/phusion_nl) |
|
||||||
|
[Blog](http://blog.phusion.nl/)
|
||||||
|
|
||||||
|
**目錄**
|
||||||
|
|
||||||
|
* [鏡像裏面有什麼?](#whats_inside)
|
||||||
|
* [概述](#whats_inside_overview)
|
||||||
|
* [等等,我認爲Docker在一個容器中只能允許運行一個行程?](#docker_single_process)
|
||||||
|
* [Baseimage-docker更側重於“胖容器”還是“把容器當作虛擬機”?](#fat_containers)
|
||||||
|
* [查看baseimage-docker](#inspecting)
|
||||||
|
* [使用baseimage-docker作爲基礎鏡像](#using)
|
||||||
|
* [開始](#getting_started)
|
||||||
|
* [增加額外的後臺行程](#adding_additional_daemons)
|
||||||
|
* [容器啓動時運行腳本](#running_startup_scripts)
|
||||||
|
* [環境變數](#environment_variables)
|
||||||
|
* [集中定義自己的環境變數](#envvar_central_definition)
|
||||||
|
* [保存環境變數](#envvar_dumps)
|
||||||
|
* [修改環境變數](#modifying_envvars)
|
||||||
|
* [安全性](#envvar_security)
|
||||||
|
* [容器管理](#container_administration)
|
||||||
|
* [在一個新容器中運行單條命令](#oneshot)
|
||||||
|
* [在正在運行的的容器中運行一條命令](#run_inside_existing_container)
|
||||||
|
* [通過`docer exec`登錄容器](#login_docker_exec)
|
||||||
|
* [用法](#nsenter_usage)
|
||||||
|
* [使用SSH登錄容器](#login_ssh)
|
||||||
|
* [啓用SSH](#enabling_ssh)
|
||||||
|
* [關於SSH的key](#ssh_keys)
|
||||||
|
* [只對一個容器使用不安全key](#using_insecure_key_for_one_container_only)
|
||||||
|
* [永久開啓不安全key](#enabling_the_insecure_key_permanently)
|
||||||
|
* [使用你自己的key](#using_your_own_key)
|
||||||
|
* [`docker-ssh`工具](#docker_ssh)
|
||||||
|
* [構建自己的鏡像](#building)
|
||||||
|
* [總結](#conclusion)
|
||||||
|
|
||||||
|
-----------------------------------------
|
||||||
|
|
||||||
|
<a name="whats_inside"></a>
|
||||||
|
## 鏡像裏面有什麼?
|
||||||
|
|
||||||
|
<a name="whats_inside_overview"></a>
|
||||||
|
### 概述
|
||||||
|
|
||||||
|
*想看一個裏面包含Ruby,Python,Node.js以及Meteor的完整基礎鏡像?可以看一下[passenger-docker](https://github.com/phusion/passenger-docker)。*
|
||||||
|
|
||||||
|
| 模塊 | 爲什麼包含這些?以及備註 |
|
||||||
|
| ---------------- | ------------------- |
|
||||||
|
| Ubuntu 14.04 LTS | 基礎系統。 |
|
||||||
|
| 一個**正確**的初始化行程 | *主要文章:[Docker和PID 1 殭屍行程回收問題](http://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/)*<br/><br/>根據Unix行程模型,[初始化行程](https://en.wikipedia.org/wiki/Init) -- PID 1 -- 繼承了所有[孤立的子行程](https://en.wikipedia.org/wiki/Orphan_process),並且必須[進行回收](https://en.wikipedia.org/wiki/Wait_(system_call))。大多數Docker容器沒有一個初始化行程可以正確的完成此操作,隨着時間的推移會導致他們的容器出現了大量的[殭屍行程](https://en.wikipedia.org/wiki/Zombie_process)。<br/><br/>而且,`docker stop`發送SIGTERM信號給初始化行程,照理說此信號應該可以停止所有服務。不幸的是由於它們對硬體進行了關閉操作,導致Docker內的大多數初始化系統沒有正確執行。這會導致行程強行被SIGKILL信號關閉,從而喪失了一個正確取消初始化設置的機會。這會導致文件損壞。<br/><br/>Baseimage-docker配有一個名爲`/sbin/my_init`的初始化行程來同時正確的完成這些任務。 |
|
||||||
|
| 修復了APT與Docker不兼容的問題 | 詳情參見:https://github.com/dotcloud/docker/issues/1024 。 |
|
||||||
|
| syslog-ng | 對於很多服務-包括kernel自身,都需要一個syslog後臺行程,以便可以正確的將log輸出到/var/log/syslog中。如果沒有運行syslog後臺行程,很多重要的信息就會默默的丟失了。<br/><br/>只對本地進行監聽。所有syslog信息會被轉發給“docker logs”。 |
|
||||||
|
| logrotate | 定期轉存和壓縮日誌。 |
|
||||||
|
| SSH服務 | 允許你很容易的登錄到容器中進行[查詢或管理](#login_ssh)操作。<br/><br/>_SSH**默認是禁用**的,這也是baseimage-docker爲此目的提供的唯一方法。其它方法需要通過[docker exec](#login_docker_exec)。由於`docker exec`同時帶來了幾個需要注意的問題,SSH同時也提供了一個可替換的方法。_<br/><br/>密碼和challenge-response認證方式默認是禁用的。只有key認證通過之後才能夠開啓。 |
|
||||||
|
| cron | 爲了保證cron任務能夠工作,必須運行cron後臺行程。 |
|
||||||
|
| [runit](http://smarden.org/runit/) | 替換Ubuntu的Upstart。用於服務監控和管理。比SysV init更容易使用,同時當這些服務崩潰之後,支持後臺行程自動重啓。比Upstart更易使用,更加的輕量級。 |
|
||||||
|
| `setuser` | 使用其它賬戶運行命令的工具。比`su`更容易使用,比使用`sudo`有那麼一點優勢,跟`chpst`不同,這個工具需要正確的設置`$HOME`。像`/sbin/setuser`這樣。 |
|
||||||
|
Baseimage-docker非常的輕量級:僅僅佔用6MB內存。
|
||||||
|
|
||||||
|
<a name="docker_single_process"></a>
|
||||||
|
### 等等,我認爲Docker在一個容器中就運行一個行程嗎?
|
||||||
|
絕對不是這樣的. 在一個docker容器中,運行多個行程也是很好的. 事實上,沒有什麼技術原因限制你只運行一個行程,運行很多的行程,只會把容器中系統的基本功能搞的更亂,比如syslog.
|
||||||
|
|
||||||
|
Baseimage-docker *鼓勵* 通過runit來運行多行程.
|
||||||
|
|
||||||
|
<a name="inspecting"></a>
|
||||||
|
## 檢測一下baseimage-docker
|
||||||
|
|
||||||
|
要檢測鏡像,執行下面的命令:
|
||||||
|
|
||||||
|
docker run --rm -t -i phusion/baseimage:<VERSION> /sbin/my_init -- bash -l
|
||||||
|
|
||||||
|
`<VERSION>` 是[baseimage-docker的版本號](https://github.com/phusion/baseimage-docker/blob/master/Changelog.md).
|
||||||
|
|
||||||
|
你不用手動去下載任何文件.上面的命令會自動從docker倉庫下載baseimage-docker鏡像.
|
||||||
|
|
||||||
|
<a name="using"></a>
|
||||||
|
## 使用baseimage-docker作爲基礎鏡像
|
||||||
|
|
||||||
|
<a name="getting_started"></a>
|
||||||
|
### 入門指南
|
||||||
|
|
||||||
|
The image is called `phusion/baseimage`, and is available on the Docker registry.
|
||||||
|
鏡像名字叫`phusion/baseimage`,在Docker倉庫上也是可用的.
|
||||||
|
|
||||||
|
下面的這個是一個Dockerfile的模板.
|
||||||
|
|
||||||
|
# 使用phusion/baseimage作爲基礎鏡像,去構建你自己的鏡像,需要下載一個明確的版本,千萬不要使用`latest`.
|
||||||
|
# 查看https://github.com/phusion/baseimage-docker/blob/master/Changelog.md,可用看到版本的列表.
|
||||||
|
FROM phusion/baseimage:<VERSION>
|
||||||
|
|
||||||
|
# 設置正確的環境變數.
|
||||||
|
ENV HOME /root
|
||||||
|
|
||||||
|
# 生成SSH keys,baseimage-docker不包含任何的key,所以需要你自己生成.你也可以註釋掉這句命令,系統在啓動過程中,會生成一個.
|
||||||
|
RUN /etc/my_init.d/00_regen_ssh_host_keys.sh
|
||||||
|
|
||||||
|
# 初始化baseimage-docker系統
|
||||||
|
CMD ["/sbin/my_init"]
|
||||||
|
|
||||||
|
# 這裏可以放置你自己需要構建的命令
|
||||||
|
|
||||||
|
# 當完成後,清除APT.
|
||||||
|
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
|
||||||
|
<a name="adding_additional_daemons"></a>
|
||||||
|
### 增加後臺行程
|
||||||
|
|
||||||
|
你可以通過runit工具向你的鏡像中添加後臺行程(例如:你自己的某些應用).你需要編寫一個運行你需要的後臺行程的腳步就可以了,runit工具會保證它的正常運行,如果行程死掉,runit也會重啓它的.
|
||||||
|
|
||||||
|
腳本的名稱必須是`run`,必須是可以運行的,它需要放到`/etc/service/<NAME>`.
|
||||||
|
|
||||||
|
這裏有一個例子,向你展示如果運行memcached服務的.
|
||||||
|
|
||||||
|
### memcached.sh(確定文件的權限是chmod +x):
|
||||||
|
#!/bin/sh
|
||||||
|
# `/sbin/setuser memcache` 指定一個`memcache`用戶來運行命令.如果你忽略了這部分,就會使用root用戶執行.
|
||||||
|
exec /sbin/setuser memcache /usr/bin/memcached >>/var/log/memcached.log 2>&1
|
||||||
|
|
||||||
|
### 在Dockerfile中:
|
||||||
|
RUN mkdir /etc/service/memcached
|
||||||
|
ADD memcached.sh /etc/service/memcached/run
|
||||||
|
|
||||||
|
注意腳本必須運行在後臺的,**不能讓他們行程進行daemonize/fork**.通常,後臺行程會提供一個標誌位或者配置文件.
|
||||||
|
|
||||||
|
<a name="running_startup_scripts"></a>
|
||||||
|
### 在容器啓動的時候,運行腳本.
|
||||||
|
|
||||||
|
baseimage-docker的初始化腳本 `/sbin/my_init`,在啓動的時候行程運行,按照下面的順序:
|
||||||
|
|
||||||
|
* 如果`/etc/my_init.d`存在,則按照字母順序執行腳本.
|
||||||
|
* 如果`/etc/rc.local`存在,則執行裏面的腳本.
|
||||||
|
|
||||||
|
所有的腳本都是正確退出的,例如:退出的code是0.如果有任何腳本以非0的code退出,啓動就會失敗.
|
||||||
|
|
||||||
|
下面的例子向你展示了怎麼添加一個啓動腳本.這個腳本很簡單的記錄的一個系統啓動時間,將啓動時間記錄到/tmp/boottime.txt.
|
||||||
|
|
||||||
|
### 在 logtime.sh (文件權限chmod +x):
|
||||||
|
#!/bin/sh
|
||||||
|
date > /tmp/boottime.txt
|
||||||
|
|
||||||
|
### 在 Dockerfile中:
|
||||||
|
RUN mkdir -p /etc/my_init.d
|
||||||
|
ADD logtime.sh /etc/my_init.d/logtime.sh
|
||||||
|
|
||||||
|
|
||||||
|
<a name="environment_variables"></a>
|
||||||
|
### 環境變數
|
||||||
|
|
||||||
|
如果你使用`/sbin/my_init`作爲主容器命令,那麼通過`docker run --env`或者在Dockerfile文件中設置的`ENV`環境變數,都會被`my_init`讀取.
|
||||||
|
|
||||||
|
* 在Unix系統中,環境變數都會被子行程給繼承.這就意味着,子行程不可能修改環境變數或者修改其他行程的環境變數.
|
||||||
|
* 由於上面提到的一點,這裏沒有一個可以爲所有應用和服務集中定義環境的地方.Debian提供了一個`/etc/environment` 文件,解決一些問題.
|
||||||
|
* 某些服務更改環境變數是爲了給子行程使用.Nginx有這樣的一個例子:它移除了所有的環境變數,除非你通過`env`進行了配置,明確了某些是保留的.如果你部署了任何應用在Nginx鏡像(例如:使用[passenger-docker](https://github.com/phusion/passenger-docker)鏡像或者使用Phusion Passenger作爲你的鏡像.),那麼你通過Docker,你不會看到任何環境變數.
|
||||||
|
|
||||||
|
|
||||||
|
`my_init`提供了一個辦法來解決這些問題.
|
||||||
|
|
||||||
|
<a name="envvar_central_definition"></a>
|
||||||
|
#### 集中定義你的環境變數
|
||||||
|
|
||||||
|
在啓動的時候,在執行[startup scripts](#running_startup_scripts),`my_init`會從`/etc/container_environment`導入環境變數.這個文件夾下面,包含的文件,文件被命名爲環境變數的名字.文件內容就是環境變數的值.這個文件夾是因此是一個集中定義你的環境變數的好地方,它會繼承到所有啓動項目和Runit管理的服務中.
|
||||||
|
|
||||||
|
給個例子,在你的dockerfile如何定義一個環境變數:
|
||||||
|
|
||||||
|
RUN echo Apachai Hopachai > /etc/container_environment/MY_NAME
|
||||||
|
|
||||||
|
你可以按照下面這樣驗證:
|
||||||
|
|
||||||
|
$ docker run -t -i <YOUR_NAME_IMAGE> /sbin/my_init -- bash -l
|
||||||
|
...
|
||||||
|
*** Running bash -l...
|
||||||
|
# echo $MY_NAME
|
||||||
|
Apachai Hopachai
|
||||||
|
|
||||||
|
**換行處理**
|
||||||
|
|
||||||
|
如果你觀察仔細一點,你會注意到'echo'命令,實際上在它是在新行打印出來的.爲什麼$MY_NAME沒有包含在一行呢? 因爲`my_init`在尾部有個換行字符.如果你打算讓你的值包含一個新行,你需要增*另外*一個新字符,像這樣:
|
||||||
|
|
||||||
|
RUN echo -e "Apachai Hopachai\n" > /etc/container_environment/MY_NAME
|
||||||
|
|
||||||
|
<a name="envvar_dumps"></a>
|
||||||
|
#### 環境變數存儲
|
||||||
|
|
||||||
|
上面提到集中定義環境變數,它不會從子服務行程改變父服務行程或者重置環境變數.而且,`my_init`也會很容易的讓你查詢到原始的環境變數是什麼.
|
||||||
|
|
||||||
|
在啓動的時候,`/etc/container_environment`, `my_init`中的變數會存儲起來,並且導入到環境變數中,例如一下的格式:
|
||||||
|
|
||||||
|
* `/etc/container_environment`
|
||||||
|
* `/etc/container_environment.sh`- 一個bash存儲的環境變數格式.你可以從這個命令中得到base格式的文件.
|
||||||
|
* `/etc/container_environment.json` - 一個json格式存儲的環境變數格式.
|
||||||
|
|
||||||
|
多種格式可以讓你不管採用什麼語言/apps都可以很容易使用環境變數.
|
||||||
|
|
||||||
|
這裏有個例子,展示怎麼使用:
|
||||||
|
|
||||||
|
$ docker run -t -i \
|
||||||
|
--env FOO=bar --env HELLO='my beautiful world' \
|
||||||
|
phusion/baseimage:<VERSION> /sbin/my_init -- \
|
||||||
|
bash -l
|
||||||
|
...
|
||||||
|
*** Running bash -l...
|
||||||
|
# ls /etc/container_environment
|
||||||
|
FOO HELLO HOME HOSTNAME PATH TERM container
|
||||||
|
# cat /etc/container_environment/HELLO; echo
|
||||||
|
my beautiful world
|
||||||
|
# cat /etc/container_environment.json; echo
|
||||||
|
{"TERM": "xterm", "container": "lxc", "HOSTNAME": "f45449f06950", "HOME": "/root", "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "FOO": "bar", "HELLO": "my beautiful world"}
|
||||||
|
# source /etc/container_environment.sh
|
||||||
|
# echo $HELLO
|
||||||
|
my beautiful world
|
||||||
|
|
||||||
|
<a name="modifying_envvars"></a>
|
||||||
|
#### 修改環境變數
|
||||||
|
|
||||||
|
通過修改`/etc/container_environment`這個文件,很有可能修改了`my_init`中的環境變數.之後,每次`my_init`啓動[啓動腳本](#running_startup_scripts),就會重置掉我們自己`/etc/container_environment`中的環境變數,也就會導致`container_environment.sh`和`container_environment.json`重新存儲.
|
||||||
|
|
||||||
|
但是記住這些:
|
||||||
|
|
||||||
|
* 修改`container_environment.sh` 和 `container_environment.json`是沒有效果的.
|
||||||
|
* Runit 的服務是不能像這樣修改環境變數的.`my_init`運行的時候,只對`/etc/container_environment`中的修改是生效的.
|
||||||
|
|
||||||
|
<a name="envvar_security"></a>
|
||||||
|
#### 安全
|
||||||
|
|
||||||
|
因爲環境變數可能包含敏感信息, `/etc/container_environment`和它的bash文件和JSON文件,默認都是root,都是可以被`docker_env`羣組可以訪問的(所以任何用戶只要添加到羣組中,都可以自動的獲取這些信息).
|
||||||
|
|
||||||
|
如果你確定你的環境變數中沒有什麼敏感信息,那麼你可以放鬆管理權限,將文件夾和文件分配下面的權限:
|
||||||
|
|
||||||
|
RUN chmod 755 /etc/container_environment
|
||||||
|
RUN chmod 644 /etc/container_environment.sh /etc/container_environment.json
|
||||||
|
|
||||||
|
<a name="workaroud_modifying_etc_hosts"></a>
|
||||||
|
### 解決Docker沒有辦法解決的/etc/hosts的問題
|
||||||
|
|
||||||
|
當前是沒有辦法在docker容器中修改`/etc/hosts`,這個是因爲[Docker bug 2267](https://github.com/dotcloud/docker/issues/2267).Baseimage-docker包含了解決這個問題的辦法,你必須明白是怎麼修改的.
|
||||||
|
|
||||||
|
修改的辦法包含在系統庫中的` libnss_files.so.2`文件,這個文件使用`/etc/workaround-docker-2267/hosts`來代替系統使用`/etc/hosts`.如果需要修改`/etc/hosts`,你只要修改`/etc/workaround-docker-2267/hosts`就可以了.
|
||||||
|
|
||||||
|
增加這個修改到你的Dockerfile.下面的命令修改了文件`libnss_files.so.2`.
|
||||||
|
|
||||||
|
RUN /usr/bin/workaround-docker-2267
|
||||||
|
|
||||||
|
(其實你不用在Dockerfile文件中運行這個命令,你可以在容器中運行一個shell就可以了.)
|
||||||
|
|
||||||
|
驗證一下它是否生效了,[在你的容器中打開一個shell](#inspecting),修改`/etc/workaround-docker-2267/hosts`,檢查一下是否生效了:
|
||||||
|
|
||||||
|
bash# echo 127.0.0.1 my-test-domain.com >> /etc/workaround-docker-2267/hosts
|
||||||
|
bash# ping my-test-domain.com
|
||||||
|
...should ping 127.0.0.1...
|
||||||
|
|
||||||
|
**注意apt-get升級:** 如果Ubuntu升級,就有可能將`libnss_files.so.2`覆蓋掉,那麼修改就會失效.你必須重新運行`/usr/bin/workaround-docker-2267`.爲了安全一點,你應該在運行`apt-get upgrade`之後,運行一下這個命令.
|
||||||
|
|
||||||
|
<a name="disabling_ssh"></a>
|
||||||
|
### 禁用SSH
|
||||||
|
Baseimage-docker默認是支持SSH的,所以可以[使用SSH](#login_ssh)來[管理你的容器](#container_administration).萬一你不想支持SSH,你可以只要禁用它:
|
||||||
|
|
||||||
|
RUN rm -rf /etc/service/sshd /etc/my_init.d/00_regen_ssh_host_keys.sh
|
||||||
|
|
||||||
|
<a name="container_administration"></a>
|
||||||
|
## 容器管理
|
||||||
|
|
||||||
|
一個優秀的docker想法,就是docker是一個無狀態的,容易啓動的容器,就想一個黑盒子.然而,你可能遇到某種情況,需要登錄到容器,或者運行命令在容器中.或者爲了開發,需要查看或者debug的目的.這章就給你講解怎麼管理容器.
|
||||||
|
|
||||||
|
|
||||||
|
<a name="oneshot"></a>
|
||||||
|
### 在一個新容器中運行一個一閃而過的命令
|
||||||
|
|
||||||
|
_**備註:** 這章講解怎麼在一個-新-容器中運行命令.要在一個存在的容器中運行命令,請查看[在一個存在的容器中,運行一個命令](#run_inside_existing_container)._
|
||||||
|
|
||||||
|
正常情況下,當你創建了一個新容器,爲了在容器中運行一個單獨的命令,而且在運行之後會立即退出的,你會這樣調用docker命令:
|
||||||
|
|
||||||
|
docker run YOUR_IMAGE COMMAND ARGUMENTS...
|
||||||
|
|
||||||
|
然而下面的方法初始化系統的進行是不會啓動.它是這樣的,當調用`COMMAND`的時候,重要的後臺行程,例如定時任務和系統日誌都是不運行的.同樣,子行程也是不會出現的,因爲`COMMAND`的pid是1.
|
||||||
|
|
||||||
|
Baseimage-docker提供了一個靈活的方式運行只要一閃而過的命令,同時也解決了上述所說的問題.以一下的方式運行一條命令:
|
||||||
|
|
||||||
|
docker run YOUR_IMAGE /sbin/my_init -- COMMAND ARGUMENTS ...
|
||||||
|
|
||||||
|
他們會按照下面的流程執行:
|
||||||
|
|
||||||
|
* 運行所有的啓動文件,例如 /etc/my_init.d/* and /etc/rc.local.
|
||||||
|
* 運行所有的runit服務
|
||||||
|
* 運行指定的命令
|
||||||
|
* 運行指定的命令結束之後,結束所有runit服務.
|
||||||
|
|
||||||
|
例如:
|
||||||
|
|
||||||
|
$ docker run phusion/baseimage:<VERSION> /sbin/my_init -- ls
|
||||||
|
*** Running /etc/my_init.d/00_regen_ssh_host_keys.sh...
|
||||||
|
No SSH host key available. Generating one...
|
||||||
|
Creating SSH2 RSA key; this may take some time ...
|
||||||
|
Creating SSH2 DSA key; this may take some time ...
|
||||||
|
Creating SSH2 ECDSA key; this may take some time ...
|
||||||
|
*** Running /etc/rc.local...
|
||||||
|
*** Booting runit daemon...
|
||||||
|
*** Runit started as PID 80
|
||||||
|
*** Running ls...
|
||||||
|
bin boot dev etc home image lib lib64 media mnt opt proc root run sbin selinux srv sys tmp usr var
|
||||||
|
*** ls exited with exit code 0.
|
||||||
|
*** Shutting down runit daemon (PID 80)...
|
||||||
|
*** Killing all processes...
|
||||||
|
|
||||||
|
你會發現默認的啓動的流程太負責.或者你不希望執行啓動文件.你可以自定義所有通過給`my_init`增加參數.調用`docker run YOUR_IMAGE /sbin/my_init --help`可以看到幫助信息.
|
||||||
|
|
||||||
|
例如上面運行`ls`命令,同時要求不運行啓動腳本,減少信息打印,運行runit所有命令.
|
||||||
|
|
||||||
|
$ docker run phusion/baseimage:<VERSION> /sbin/my_init --skip-startup-files --quiet -- ls
|
||||||
|
bin boot dev etc home image lib lib64 media mnt opt proc root run sbin selinux srv sys tmp usr var
|
||||||
|
|
||||||
|
<a name="run_inside_existing_container"></a>
|
||||||
|
### 在一個已經運行的容器中,運行一條命令
|
||||||
|
|
||||||
|
這裏有兩種辦法去在一個已經運行的容器中運行命令.
|
||||||
|
|
||||||
|
* 通過`nseneter`工具.這個工具用於Linux內核調用在內嵌容器中運行命令.可以查看[通過`nsenter`,登錄容器或者在容器內執行命令](#login_nsenter).
|
||||||
|
* 通過SSH.這種辦法需要在容器中運行ssh服務,而且需要你創建自己的sshkey.可以查看[通過`ssh`,登錄容器或者在容器內執行命令](#login_ssh).
|
||||||
|
|
||||||
|
兩種方法都是他們各自的優點和確定,你可以學習他們各自的章節來了他們.
|
||||||
|
|
||||||
|
<a name="login_nsenter"></a>
|
||||||
|
### 通過`nsenter`,登錄容器或者在容器內執行命令
|
||||||
|
|
||||||
|
你可以使用在docker主機上面的`nsenter`工具,來登錄任何基於baseimage-docker的docker容器.你可以使用它在你的容器中運行命令.
|
||||||
|
|
||||||
|
這裏有個和[通過`ssh`,登錄容器或者在容器內執行命令](#login_ssh)的優缺點的比較:
|
||||||
|
|
||||||
|
* 優點
|
||||||
|
* 不需要在容器中運行ssh服務.
|
||||||
|
* 不需要ssh key.
|
||||||
|
* 運行在任何容器上,甚至不是基於baseimage-docker的容器.
|
||||||
|
* 缺點
|
||||||
|
* 通過`nsenter`運行的行程會和正常運行稍微有不同.例如,他們不同結束掉在容器中正常運行的行程.這適用於所有的子行程.
|
||||||
|
* 如果`nsenter`行程被其他命令(如`kill`命令)給終止,然後由nsenter所執行的命令,是*不會*被結束的.你將不得不手動清理.(備註:終端控制命令像Ctrl-C *會* 清理所有的子行程,因爲終端信號被髮送到所有流程的終端會話)
|
||||||
|
* 需要學習新工具.
|
||||||
|
* 需要在docker主機上面提供root權限.
|
||||||
|
* 需要在docker主機上面是可用的.在寫這篇文字的時候(2014年7月),大多數linux發行版沒有加載它.然而,baseimage-docker提供了預編譯的二進制文件,允許你通過[docker-bash](#docker_bash)工具,來很容易的使用它.
|
||||||
|
* 不可能沒有登錄到docker主機,就登錄到docker容器中.(也就是說,你必須登錄到docker主機,通過docker主機登錄到容器.)
|
||||||
|
|
||||||
|
<a name="nsenter_usage"></a>
|
||||||
|
#### 用例
|
||||||
|
|
||||||
|
第一,確定`nsenter`已經安裝了.在寫這篇文字的時候(2014年7月),大多數linux發行版沒有加載它.然而,baseimage-docker提供了預編譯的二進制文件,允許你通過[docker-bash](#docker_bash)工具,讓任何人都可以使用.
|
||||||
|
|
||||||
|
接着,啓動一個容器.
|
||||||
|
|
||||||
|
docker run YOUR_IMAGE
|
||||||
|
|
||||||
|
找出你剛纔運行容器的`ID`.
|
||||||
|
|
||||||
|
docker ps
|
||||||
|
|
||||||
|
一旦擁有容器的id,找到運行容器的主要行程額`PID`.
|
||||||
|
|
||||||
|
docker inspect -f "{{ .State.Pid }}" <ID>
|
||||||
|
|
||||||
|
現在你有的容器的主行程的PID,就可以使用`nsenter`來登錄容器,或者在容器裏面執行命令:
|
||||||
|
|
||||||
|
# 登錄容器
|
||||||
|
nsenter --target <MAIN PROCESS PID> --mount --uts --ipc --net --pid bash -l
|
||||||
|
|
||||||
|
# 在容器中執行命令
|
||||||
|
nsenter --target <MAIN PROCESS PID> --mount --uts --ipc --net --pid -- echo hello world
|
||||||
|
|
||||||
|
<a name="docker_bash"></a>
|
||||||
|
#### `docker-bash`工具
|
||||||
|
|
||||||
|
查找一個容器的主要行程的PID和輸入這麼長的nsenter命令很快會變得乏味無論.幸運的是,我們提供了一個`docker-bash` 工具,它可以自動完成只要的工具.這個工具是運行在*docker主機*上面,不是在docker容器中.
|
||||||
|
|
||||||
|
該工具還附帶了一個預編譯的二進制`nsenter`,這樣你不需要自己安裝`nsenter`了.`docker-bash`是很簡單的使用的.
|
||||||
|
|
||||||
|
首先,在docker主機上安裝這個工具:
|
||||||
|
|
||||||
|
curl --fail -L -O https://github.com/phusion/baseimage-docker/archive/master.tar.gz && \
|
||||||
|
tar xzf master.tar.gz && \
|
||||||
|
sudo ./baseimage-docker-master/install-tools.sh
|
||||||
|
|
||||||
|
運行這個工具登錄到容器中:
|
||||||
|
|
||||||
|
docker-bash YOUR-CONTAINER-ID
|
||||||
|
|
||||||
|
你可以通過`docker ps`來查找你的容器ID.
|
||||||
|
|
||||||
|
默認,`docker-bash`會打開一個bash 回話.你可以告訴運行什麼命令,之後就會自動退出:
|
||||||
|
|
||||||
|
docker-bash YOUR-CONTAINER-ID echo hello world
|
||||||
|
|
||||||
|
<a name="login_ssh"></a>
|
||||||
|
### 通過`ssh`,登錄容器或者在容器內執行命令
|
||||||
|
|
||||||
|
你可以使用ssh來登錄任何基於baseimage-docker的容器.你可以使用它在容器中執行命令.
|
||||||
|
|
||||||
|
這裏有個和[通過`nsenter`,登錄容器或者在容器內執行命令](#login_nsenter)的優缺點的比較:
|
||||||
|
|
||||||
|
* 優點
|
||||||
|
* 不像`nsenter`一樣,運行在docker主機上面.幾乎每個人都會安裝一個ssh客戶端.
|
||||||
|
* 不想使用`nsenter`,運行的行程和正在的行程會不一樣.
|
||||||
|
* 不需要docker主機提供root權限.
|
||||||
|
* 運行你讓用戶登錄到容器,而不需要登錄到docker主機.然而,默認這是不啓用的,因爲baseimage-docker默認不是開放ssh服務的.
|
||||||
|
* 缺點
|
||||||
|
* 需要設置ssh key.然而,baseimage-docker會提供一中辦法,會讓key的生成會很容器.閱讀更多信息.
|
||||||
|
|
||||||
|
第一件事情,就是你需要確定你在容器中已經安裝設置了ssh key. 默認,沒有任何安裝key的,所有你無法登錄.爲了方便的原因,我們提供了一個[已經生成的key](https://github.com/phusion/baseimage-docker/blob/master/image/services/sshd/keys/insecure_key) [(PuTTY format)](https://github.com/phusion/baseimage-docker/blob/master/image/services/sshd/keys/insecure_key.ppk),爲了讓你使用方便.然後,請注意這個key僅僅是爲方便.他沒有任何安全行,因爲它的key是在網絡上提供的.**在生產環境,你必須使用你自己的key.**
|
||||||
|
|
||||||
|
|
||||||
|
<a name="using_the_insecure_key_for_one_container_only"></a>
|
||||||
|
#### 在容器中使用key
|
||||||
|
|
||||||
|
你可以臨時的使用key僅僅作爲容器使用.這就以爲這key是安裝在容器上的.如果你使用`docker stop`和`docker start`控制容器,那麼key是在容器中,但是如果你使用`docker run`開啓一個新容器,那麼這個容器是不包含key的.
|
||||||
|
|
||||||
|
啓動新容器包含key`--enable-insecure-key`:
|
||||||
|
|
||||||
|
docker run YOUR_IMAGE /sbin/my_init --enable-insecure-key
|
||||||
|
|
||||||
|
找出你的剛纔運行的容器的ID:
|
||||||
|
|
||||||
|
docker ps
|
||||||
|
|
||||||
|
一旦你擁有容器的ID,就能找到容器使用的IP地址:
|
||||||
|
|
||||||
|
docker inspect -f "{{ .NetworkSettings.IPAddress }}" <ID>
|
||||||
|
|
||||||
|
現在你有得了IP地址,你就看通過SSH來登錄容器,或者在容器中執行命令了:
|
||||||
|
|
||||||
|
# 下載key
|
||||||
|
curl -o insecure_key -fSL https://github.com/phusion/baseimage-docker/raw/master/image/services/sshd/keys/insecure_key
|
||||||
|
chmod 600 insecure_key
|
||||||
|
|
||||||
|
# 登錄容器
|
||||||
|
ssh -i insecure_key root@<IP address>
|
||||||
|
|
||||||
|
# 在容器中執行命令
|
||||||
|
ssh -i insecure_key root@<IP address> echo hello world
|
||||||
|
|
||||||
|
<a name="enabling_the_insecure_key_permanently"></a>
|
||||||
|
#### 支持一個長久的key
|
||||||
|
|
||||||
|
在一個長久存在的鏡像中支持一個key是很可能的.一般是不推薦這麼做,但是對於臨時開始或者做demo演示,對安全要求不高,還是很合適的.
|
||||||
|
|
||||||
|
編輯你的dockerfile,來安裝永久的key:
|
||||||
|
|
||||||
|
RUN /usr/sbin/enable_insecure_key
|
||||||
|
|
||||||
|
在容器中怎麼使用,同[在容器中使用key](#using_the_insecure_key_for_one_container_only)的章節說的一樣.
|
||||||
|
|
||||||
|
<a name="using_your_own_key"></a>
|
||||||
|
#### 使用你自己的key
|
||||||
|
|
||||||
|
編輯你的dockerfile,來安裝ssh public key:
|
||||||
|
|
||||||
|
## 安裝你自己的public key.
|
||||||
|
ADD your_key.pub /tmp/your_key.pub
|
||||||
|
RUN cat /tmp/your_key.pub >> /root/.ssh/authorized_keys && rm -f /tmp/your_key.pub
|
||||||
|
|
||||||
|
重新創建你的鏡像.一旦你創建成功,啓動基於這個鏡像的容器.
|
||||||
|
|
||||||
|
docker run your-image-name
|
||||||
|
|
||||||
|
找出你的剛纔運行的容器的ID:
|
||||||
|
|
||||||
|
docker ps
|
||||||
|
|
||||||
|
一旦你擁有容器的ID,就能找到容器使用的IP地址:
|
||||||
|
|
||||||
|
docker inspect -f "{{ .NetworkSettings.IPAddress }}" <ID>
|
||||||
|
|
||||||
|
現在你有得了IP地址,你就看通過SSH來登錄容器,或者在容器中執行命令了:
|
||||||
|
|
||||||
|
# 登錄容器
|
||||||
|
ssh -i /path-to/your_key root@<IP address>
|
||||||
|
|
||||||
|
# 在容器中執行命令
|
||||||
|
ssh -i /path-to/your_key root@<IP address> echo hello world
|
||||||
|
|
||||||
|
<a name="docker_ssh"></a>
|
||||||
|
#### `docker-ssh`工具
|
||||||
|
|
||||||
|
找到容器的IP,運行ssh命令,很快會變得乏味無聊.幸運的是,我們提供了一個`docker-ssh`,可以自動完成這些事情.這個工具是運行在*Docker 主機*上的,不是安裝在docker容器中的.
|
||||||
|
|
||||||
|
首先,在docker主機上面安裝這個工具.
|
||||||
|
|
||||||
|
curl --fail -L -O https://github.com/phusion/baseimage-docker/archive/master.tar.gz && \
|
||||||
|
tar xzf master.tar.gz && \
|
||||||
|
sudo ./baseimage-docker-master/install-tools.sh
|
||||||
|
|
||||||
|
使用這個工具通過ssh登錄容器:
|
||||||
|
|
||||||
|
docker-ssh YOUR-CONTAINER-ID
|
||||||
|
|
||||||
|
你可以使用`docker ps`找到`YOUR-CONTAINER-ID`.
|
||||||
|
|
||||||
|
默認,`docker-bash`會打開一個bash 回話.你可以告訴運行什麼命令,之後就會自動退出:
|
||||||
|
|
||||||
|
docker-ssh YOUR-CONTAINER-ID echo hello world
|
||||||
|
|
||||||
|
<a name="building"></a>
|
||||||
|
## 創建你自己的鏡像
|
||||||
|
|
||||||
|
如果某些原因,你需要創建你自己的鏡像,來替代從docker倉庫下載鏡像,可以按照的說明.
|
||||||
|
|
||||||
|
克隆倉庫:
|
||||||
|
|
||||||
|
git clone https://github.com/phusion/baseimage-docker.git
|
||||||
|
cd baseimage-docker
|
||||||
|
|
||||||
|
創建一個包含docker在的虛擬機.你可以使用我們提供的Vagrantfile.
|
||||||
|
|
||||||
|
vagrant up
|
||||||
|
vagrant ssh
|
||||||
|
cd /vagrant
|
||||||
|
|
||||||
|
編譯鏡像:
|
||||||
|
|
||||||
|
make build
|
||||||
|
|
||||||
|
如果你想把創建的鏡像名字,叫其他名字,通過`NAME`變數可以設置:
|
||||||
|
|
||||||
|
make build NAME=joe/baseimage
|
||||||
|
|
||||||
|
<a name="conclusion"></a>
|
||||||
|
## 總結
|
||||||
|
|
||||||
|
* Using baseimage-docker? [Tweet about us](https://twitter.com/share) or [follow us on Twitter](https://twitter.com/phusion_nl).
|
||||||
|
* Having problems? Want to participate in development? Please post a message at [the discussion forum](https://groups.google.com/d/forum/passenger-docker).
|
||||||
|
* Looking for a more complete base image, one that is ideal for Ruby, Python, Node.js and Meteor web apps? Take a look at [passenger-docker](https://github.com/phusion/passenger-docker).
|
||||||
|
|
||||||
|
[<img src="http://www.phusion.nl/assets/logo.png">](http://www.phusion.nl/)
|
||||||
|
|
||||||
|
Please enjoy baseimage-docker, a product by [Phusion](http://www.phusion.nl/). :-)
|
||||||
@ -2,12 +2,11 @@
|
|||||||
FROM resin/rpi-raspbian:wheezy
|
FROM resin/rpi-raspbian:wheezy
|
||||||
MAINTAINER Phusion <info@phusion.nl>
|
MAINTAINER Phusion <info@phusion.nl>
|
||||||
|
|
||||||
ENV HOME /root
|
ADD . /bd_build
|
||||||
ADD . /build
|
|
||||||
|
|
||||||
RUN /build/prepare.sh && \
|
RUN /bd_build/prepare.sh && \
|
||||||
/build/system_services.sh && \
|
/bd_build/system_services.sh && \
|
||||||
/build/utilities.sh && \
|
/bd_build/utilities.sh && \
|
||||||
/build/cleanup.sh
|
/bd_build/cleanup.sh
|
||||||
|
|
||||||
CMD ["/sbin/my_init"]
|
CMD ["/sbin/my_init"]
|
||||||
|
|||||||
@ -9,6 +9,8 @@ LOG_LEVEL_WARN = 1
|
|||||||
LOG_LEVEL_INFO = 2
|
LOG_LEVEL_INFO = 2
|
||||||
LOG_LEVEL_DEBUG = 3
|
LOG_LEVEL_DEBUG = 3
|
||||||
|
|
||||||
|
SHENV_NAME_WHITELIST_REGEX = re.compile('[^\w\-_\.]')
|
||||||
|
|
||||||
log_level = None
|
log_level = None
|
||||||
|
|
||||||
terminated_child_processes = {}
|
terminated_child_processes = {}
|
||||||
@ -57,6 +59,8 @@ def is_exe(path):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def import_envvars(clear_existing_environment = True, override_existing_environment = True):
|
def import_envvars(clear_existing_environment = True, override_existing_environment = True):
|
||||||
|
if not os.path.exists("/etc/container_environment"):
|
||||||
|
return
|
||||||
new_env = {}
|
new_env = {}
|
||||||
for envfile in listdir("/etc/container_environment"):
|
for envfile in listdir("/etc/container_environment"):
|
||||||
name = os.path.basename(envfile)
|
name = os.path.basename(envfile)
|
||||||
@ -73,6 +77,8 @@ def import_envvars(clear_existing_environment = True, override_existing_environm
|
|||||||
os.environ[name] = value
|
os.environ[name] = value
|
||||||
|
|
||||||
def export_envvars(to_dir = True):
|
def export_envvars(to_dir = True):
|
||||||
|
if not os.path.exists("/etc/container_environment"):
|
||||||
|
return
|
||||||
shell_dump = ""
|
shell_dump = ""
|
||||||
for name, value in os.environ.items():
|
for name, value in os.environ.items():
|
||||||
if name in ['HOME', 'USER', 'GROUP', 'UID', 'GID', 'SHELL']:
|
if name in ['HOME', 'USER', 'GROUP', 'UID', 'GID', 'SHELL']:
|
||||||
@ -80,7 +86,7 @@ def export_envvars(to_dir = True):
|
|||||||
if to_dir:
|
if to_dir:
|
||||||
with open("/etc/container_environment/" + name, "w") as f:
|
with open("/etc/container_environment/" + name, "w") as f:
|
||||||
f.write(value)
|
f.write(value)
|
||||||
shell_dump += "export " + shquote(name) + "=" + shquote(value) + "\n"
|
shell_dump += "export " + sanitize_shenvname(name) + "=" + shquote(value) + "\n"
|
||||||
with open("/etc/container_environment.sh", "w") as f:
|
with open("/etc/container_environment.sh", "w") as f:
|
||||||
f.write(shell_dump)
|
f.write(shell_dump)
|
||||||
with open("/etc/container_environment.json", "w") as f:
|
with open("/etc/container_environment.json", "w") as f:
|
||||||
@ -99,6 +105,9 @@ def shquote(s):
|
|||||||
# the string $'b is then quoted as '$'"'"'b'
|
# the string $'b is then quoted as '$'"'"'b'
|
||||||
return "'" + s.replace("'", "'\"'\"'") + "'"
|
return "'" + s.replace("'", "'\"'\"'") + "'"
|
||||||
|
|
||||||
|
def sanitize_shenvname(s):
|
||||||
|
return re.sub(SHENV_NAME_WHITELIST_REGEX, "_", s)
|
||||||
|
|
||||||
# Waits for the child process with the given PID, while at the same time
|
# Waits for the child process with the given PID, while at the same time
|
||||||
# reaping any other child processes that have exited (e.g. adopted child
|
# reaping any other child processes that have exited (e.g. adopted child
|
||||||
# processes that have terminated).
|
# processes that have terminated).
|
||||||
@ -118,7 +127,10 @@ def waitpid_reap_other_children(pid):
|
|||||||
status = None
|
status = None
|
||||||
while not done:
|
while not done:
|
||||||
try:
|
try:
|
||||||
this_pid, status = os.waitpid(-1, 0)
|
# https://github.com/phusion/baseimage-docker/issues/151#issuecomment-92660569
|
||||||
|
this_pid, status = os.waitpid(pid, os.WNOHANG)
|
||||||
|
if this_pid == 0:
|
||||||
|
this_pid, status = os.waitpid(-1, 0)
|
||||||
if this_pid == pid:
|
if this_pid == pid:
|
||||||
done = True
|
done = True
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -1,3 +1,9 @@
|
|||||||
export LC_ALL=C
|
export LC_ALL=C
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
minimal_apt_get_install='apt-get install -y --no-install-recommends'
|
minimal_apt_get_install='apt-get install -y --no-install-recommends'
|
||||||
|
|
||||||
|
# Default services
|
||||||
|
# Set 1 to the service you want to disable
|
||||||
|
export DISABLE_SYSLOG=${DISABLE_SYSLOG:-0}
|
||||||
|
export DISABLE_SSH=${DISABLE_SSH:-0}
|
||||||
|
export DISABLE_CRON=${DISABLE_CRON:-0}
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
source /build/buildconfig
|
source /bd_build/buildconfig
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
apt-get clean
|
apt-get clean
|
||||||
rm -rf /build
|
rm -rf /bd_build
|
||||||
rm -rf /tmp/* /var/tmp/*
|
rm -rf /tmp/* /var/tmp/*
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
rm -f /etc/dpkg/dpkg.cfg.d/02apt-speedup
|
rm -f /etc/dpkg/dpkg.cfg.d/02apt-speedup
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
source /build/buildconfig
|
source /bd_build/buildconfig
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
## Temporarily disable dpkg fsync to make building faster.
|
## Temporarily disable dpkg fsync to make building faster.
|
||||||
|
|||||||
17
image/services/cron/cron.sh
Executable file
17
image/services/cron/cron.sh
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
source /bd_build/buildconfig
|
||||||
|
set -x
|
||||||
|
|
||||||
|
$minimal_apt_get_install cron
|
||||||
|
mkdir /etc/service/cron
|
||||||
|
chmod 600 /etc/crontab
|
||||||
|
cp /bd_build/services/cron/cron.runit /etc/service/cron/run
|
||||||
|
|
||||||
|
## Remove useless cron entries.
|
||||||
|
# Checks for lost+found and scans for mtab.
|
||||||
|
rm -f /etc/cron.daily/standard
|
||||||
|
rm -f /etc/cron.daily/upstart
|
||||||
|
rm -f /etc/cron.daily/dpkg
|
||||||
|
rm -f /etc/cron.daily/password
|
||||||
|
rm -f /etc/cron.weekly/fstrim
|
||||||
25
image/services/sshd/sshd.sh
Executable file
25
image/services/sshd/sshd.sh
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
source /bd_build/buildconfig
|
||||||
|
set -x
|
||||||
|
|
||||||
|
SSHD_BUILD_PATH=/bd_build/services/sshd
|
||||||
|
|
||||||
|
## Install the SSH server.
|
||||||
|
$minimal_apt_get_install openssh-server
|
||||||
|
mkdir /var/run/sshd
|
||||||
|
mkdir /etc/service/sshd
|
||||||
|
touch /etc/service/sshd/down
|
||||||
|
cp $SSHD_BUILD_PATH/sshd.runit /etc/service/sshd/run
|
||||||
|
cp $SSHD_BUILD_PATH/sshd_config /etc/ssh/sshd_config
|
||||||
|
cp $SSHD_BUILD_PATH/00_regen_ssh_host_keys.sh /etc/my_init.d/
|
||||||
|
|
||||||
|
## Install default SSH key for root and app.
|
||||||
|
mkdir -p /root/.ssh
|
||||||
|
chmod 700 /root/.ssh
|
||||||
|
chown root:root /root/.ssh
|
||||||
|
cp $SSHD_BUILD_PATH/keys/insecure_key.pub /etc/insecure_key.pub
|
||||||
|
cp $SSHD_BUILD_PATH/keys/insecure_key /etc/insecure_key
|
||||||
|
chmod 644 /etc/insecure_key*
|
||||||
|
chown root:root /etc/insecure_key*
|
||||||
|
cp $SSHD_BUILD_PATH/enable_insecure_key /usr/sbin/
|
||||||
148
image/services/syslog-ng/syslog-ng.conf
Normal file
148
image/services/syslog-ng/syslog-ng.conf
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
@version: 3.5
|
||||||
|
@include "scl.conf"
|
||||||
|
@include "`scl-root`/system/tty10.conf"
|
||||||
|
|
||||||
|
# Syslog-ng configuration file, compatible with default Debian syslogd
|
||||||
|
# installation.
|
||||||
|
|
||||||
|
# First, set some global options.
|
||||||
|
options { chain_hostnames(off); flush_lines(0); use_dns(no); use_fqdn(no);
|
||||||
|
owner("root"); group("adm"); perm(0640); stats_freq(0);
|
||||||
|
bad_hostname("^gconfd$");
|
||||||
|
};
|
||||||
|
|
||||||
|
########################
|
||||||
|
# Sources
|
||||||
|
########################
|
||||||
|
# This is the default behavior of sysklogd package
|
||||||
|
# Logs may come from unix stream, but not from another machine.
|
||||||
|
#
|
||||||
|
source s_src {
|
||||||
|
unix-stream("/dev/log");
|
||||||
|
internal();
|
||||||
|
};
|
||||||
|
|
||||||
|
# If you wish to get logs from remote machine you should uncomment
|
||||||
|
# this and comment the above source line.
|
||||||
|
#
|
||||||
|
#source s_net { tcp(ip(127.0.0.1) port(1000)); };
|
||||||
|
|
||||||
|
########################
|
||||||
|
# Destinations
|
||||||
|
########################
|
||||||
|
# First some standard logfile
|
||||||
|
#
|
||||||
|
destination d_auth { file("/var/log/auth.log"); };
|
||||||
|
destination d_cron { file("/var/log/cron.log"); };
|
||||||
|
destination d_daemon { file("/var/log/daemon.log"); };
|
||||||
|
destination d_kern { file("/var/log/kern.log"); };
|
||||||
|
destination d_lpr { file("/var/log/lpr.log"); };
|
||||||
|
destination d_mail { file("/var/log/mail.log"); };
|
||||||
|
destination d_syslog { file("/var/log/syslog"); };
|
||||||
|
destination d_user { file("/var/log/user.log"); };
|
||||||
|
destination d_uucp { file("/var/log/uucp.log"); };
|
||||||
|
|
||||||
|
# This files are the log come from the mail subsystem.
|
||||||
|
#
|
||||||
|
destination d_mailinfo { file("/var/log/mail.info"); };
|
||||||
|
destination d_mailwarn { file("/var/log/mail.warn"); };
|
||||||
|
destination d_mailerr { file("/var/log/mail.err"); };
|
||||||
|
|
||||||
|
# Logging for INN news system
|
||||||
|
#
|
||||||
|
destination d_newscrit { file("/var/log/news/news.crit"); };
|
||||||
|
destination d_newserr { file("/var/log/news/news.err"); };
|
||||||
|
destination d_newsnotice { file("/var/log/news/news.notice"); };
|
||||||
|
|
||||||
|
# Some `catch-all' logfiles.
|
||||||
|
#
|
||||||
|
destination d_debug { file("/var/log/debug"); };
|
||||||
|
destination d_error { file("/var/log/error"); };
|
||||||
|
destination d_messages { file("/var/log/messages"); };
|
||||||
|
|
||||||
|
# The named pipe /dev/xconsole is for the nsole' utility. To use it,
|
||||||
|
# you must invoke nsole' with the -file' option:
|
||||||
|
#
|
||||||
|
# $ xconsole -file /dev/xconsole [...]
|
||||||
|
#
|
||||||
|
destination d_xconsole { pipe("/dev/xconsole"); };
|
||||||
|
|
||||||
|
# Send the messages to an other host
|
||||||
|
#
|
||||||
|
#destination d_net { tcp("127.0.0.1" port(1000) log_fifo_size(1000)); };
|
||||||
|
|
||||||
|
# Debian only
|
||||||
|
destination d_ppp { file("/var/log/ppp.log"); };
|
||||||
|
|
||||||
|
########################
|
||||||
|
# Filters
|
||||||
|
########################
|
||||||
|
# Here's come the filter options. With this rules, we can set which
|
||||||
|
# message go where.
|
||||||
|
|
||||||
|
filter f_dbg { level(debug); };
|
||||||
|
filter f_info { level(info); };
|
||||||
|
filter f_notice { level(notice); };
|
||||||
|
filter f_warn { level(warn); };
|
||||||
|
filter f_err { level(err); };
|
||||||
|
filter f_crit { level(crit .. emerg); };
|
||||||
|
|
||||||
|
filter f_debug { level(debug) and not facility(auth, authpriv, news, mail); };
|
||||||
|
filter f_error { level(err .. emerg) ; };
|
||||||
|
filter f_messages { level(info,notice,warn) and
|
||||||
|
not facility(auth,authpriv,cron,daemon,mail,news); };
|
||||||
|
|
||||||
|
filter f_auth { facility(auth, authpriv) and not filter(f_debug); };
|
||||||
|
filter f_cron { facility(cron) and not filter(f_debug); };
|
||||||
|
filter f_daemon { facility(daemon) and not filter(f_debug); };
|
||||||
|
filter f_kern { facility(kern) and not filter(f_debug); };
|
||||||
|
filter f_lpr { facility(lpr) and not filter(f_debug); };
|
||||||
|
filter f_local { facility(local0, local1, local3, local4, local5,
|
||||||
|
local6, local7) and not filter(f_debug); };
|
||||||
|
filter f_mail { facility(mail) and not filter(f_debug); };
|
||||||
|
filter f_news { facility(news) and not filter(f_debug); };
|
||||||
|
filter f_syslog3 { not facility(auth, authpriv, mail) and not filter(f_debug); };
|
||||||
|
filter f_user { facility(user) and not filter(f_debug); };
|
||||||
|
filter f_uucp { facility(uucp) and not filter(f_debug); };
|
||||||
|
|
||||||
|
filter f_cnews { level(notice, err, crit) and facility(news); };
|
||||||
|
filter f_cother { level(debug, info, notice, warn) or facility(daemon, mail); };
|
||||||
|
|
||||||
|
filter f_ppp { facility(local2) and not filter(f_debug); };
|
||||||
|
filter f_console { level(warn .. emerg); };
|
||||||
|
|
||||||
|
########################
|
||||||
|
# Log paths
|
||||||
|
########################
|
||||||
|
log { source(s_src); filter(f_auth); destination(d_auth); };
|
||||||
|
log { source(s_src); filter(f_cron); destination(d_cron); };
|
||||||
|
log { source(s_src); filter(f_daemon); destination(d_daemon); };
|
||||||
|
log { source(s_src); filter(f_kern); destination(d_kern); };
|
||||||
|
log { source(s_src); filter(f_lpr); destination(d_lpr); };
|
||||||
|
log { source(s_src); filter(f_syslog3); destination(d_syslog); };
|
||||||
|
log { source(s_src); filter(f_user); destination(d_user); };
|
||||||
|
log { source(s_src); filter(f_uucp); destination(d_uucp); };
|
||||||
|
|
||||||
|
log { source(s_src); filter(f_mail); destination(d_mail); };
|
||||||
|
#log { source(s_src); filter(f_mail); filter(f_info); destination(d_mailinfo); };
|
||||||
|
#log { source(s_src); filter(f_mail); filter(f_warn); destination(d_mailwarn); };
|
||||||
|
#log { source(s_src); filter(f_mail); filter(f_err); destination(d_mailerr); };
|
||||||
|
|
||||||
|
log { source(s_src); filter(f_news); filter(f_crit); destination(d_newscrit); };
|
||||||
|
log { source(s_src); filter(f_news); filter(f_err); destination(d_newserr); };
|
||||||
|
log { source(s_src); filter(f_news); filter(f_notice); destination(d_newsnotice); };
|
||||||
|
|
||||||
|
#log { source(s_src); filter(f_ppp); destination(d_ppp); };
|
||||||
|
|
||||||
|
log { source(s_src); filter(f_debug); destination(d_debug); };
|
||||||
|
log { source(s_src); filter(f_error); destination(d_error); };
|
||||||
|
log { source(s_src); filter(f_messages); destination(d_messages); };
|
||||||
|
|
||||||
|
# All messages send to a remote site
|
||||||
|
#
|
||||||
|
#log { source(s_src); destination(d_net); };
|
||||||
|
|
||||||
|
###
|
||||||
|
# Include all config files in /etc/syslog-ng/conf.d/
|
||||||
|
###
|
||||||
|
@include "/etc/syslog-ng/conf.d/*.conf"
|
||||||
24
image/services/syslog-ng/syslog-ng.sh
Executable file
24
image/services/syslog-ng/syslog-ng.sh
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
source /bd_build/buildconfig
|
||||||
|
set -x
|
||||||
|
|
||||||
|
SYSLOG_NG_BUILD_PATH=/bd_build/services/syslog-ng
|
||||||
|
|
||||||
|
## Install a syslog daemon.
|
||||||
|
$minimal_apt_get_install syslog-ng-core
|
||||||
|
mkdir /etc/service/syslog-ng
|
||||||
|
cp $SYSLOG_NG_BUILD_PATH/syslog-ng.runit /etc/service/syslog-ng/run
|
||||||
|
mkdir -p /var/lib/syslog-ng
|
||||||
|
cp $SYSLOG_NG_BUILD_PATH/syslog_ng_default /etc/default/syslog-ng
|
||||||
|
touch /var/log/syslog
|
||||||
|
chmod u=rw,g=r,o= /var/log/syslog
|
||||||
|
cp $SYSLOG_NG_BUILD_PATH/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf
|
||||||
|
|
||||||
|
## Install syslog to "docker logs" forwarder.
|
||||||
|
mkdir /etc/service/syslog-forwarder
|
||||||
|
cp $SYSLOG_NG_BUILD_PATH/syslog-forwarder.runit /etc/service/syslog-forwarder/run
|
||||||
|
|
||||||
|
## Install logrotate.
|
||||||
|
$minimal_apt_get_install logrotate
|
||||||
|
cp $SYSLOG_NG_BUILD_PATH/logrotate_syslogng /etc/logrotate.d/syslog-ng
|
||||||
@ -1,10 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
source /build/buildconfig
|
source /bd_build/buildconfig
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
## Install init process.
|
## Install init process.
|
||||||
cp /build/bin/my_init /sbin/
|
cp /bd_build/bin/my_init /sbin/
|
||||||
mkdir -p /etc/my_init.d
|
mkdir -p /etc/my_init.d
|
||||||
mkdir -p /etc/container_environment
|
mkdir -p /etc/container_environment
|
||||||
touch /etc/container_environment.sh
|
touch /etc/container_environment.sh
|
||||||
@ -19,51 +19,11 @@ ln -s /etc/container_environment.sh /etc/profile.d/
|
|||||||
## Install runit.
|
## Install runit.
|
||||||
$minimal_apt_get_install runit
|
$minimal_apt_get_install runit
|
||||||
|
|
||||||
## Install a syslog daemon.
|
## Install a syslog daemon and logrotate.
|
||||||
$minimal_apt_get_install syslog-ng-core
|
[ "$DISABLE_SYSLOG" -eq 0 ] && /bd_build/services/syslog-ng/syslog-ng.sh || true
|
||||||
mkdir /etc/service/syslog-ng
|
|
||||||
cp /build/runit/syslog-ng /etc/service/syslog-ng/run
|
|
||||||
mkdir -p /var/lib/syslog-ng
|
|
||||||
cp /build/config/syslog_ng_default /etc/default/syslog-ng
|
|
||||||
touch /var/log/syslog
|
|
||||||
chmod u=rw,g=r,o= /var/log/syslog
|
|
||||||
# Replace the system() source because inside Docker we
|
|
||||||
# can't access /proc/kmsg.
|
|
||||||
sed -i -E 's/^(\s*)system\(\);/\1unix-stream("\/dev\/log");/' /etc/syslog-ng/syslog-ng.conf
|
|
||||||
|
|
||||||
## Install syslog to "docker logs" forwarder.
|
|
||||||
mkdir /etc/service/syslog-forwarder
|
|
||||||
cp /build/runit/syslog-forwarder /etc/service/syslog-forwarder/run
|
|
||||||
|
|
||||||
## Install logrotate.
|
|
||||||
$minimal_apt_get_install logrotate
|
|
||||||
cp /build/config/logrotate_syslogng /etc/logrotate.d/syslog-ng
|
|
||||||
|
|
||||||
## Install the SSH server.
|
## Install the SSH server.
|
||||||
$minimal_apt_get_install openssh-server
|
[ "$DISABLE_SSH" -eq 0 ] && /bd_build/services/sshd/sshd.sh || true
|
||||||
mkdir /var/run/sshd
|
|
||||||
mkdir /etc/service/sshd
|
|
||||||
touch /etc/service/sshd/down
|
|
||||||
cp /build/runit/sshd /etc/service/sshd/run
|
|
||||||
cp /build/config/sshd_config /etc/ssh/sshd_config
|
|
||||||
cp /build/00_regen_ssh_host_keys.sh /etc/my_init.d/
|
|
||||||
|
|
||||||
## Install default SSH key for root and app.
|
|
||||||
mkdir -p /root/.ssh
|
|
||||||
chmod 700 /root/.ssh
|
|
||||||
chown root:root /root/.ssh
|
|
||||||
cp /build/insecure_key.pub /etc/insecure_key.pub
|
|
||||||
cp /build/insecure_key /etc/insecure_key
|
|
||||||
chmod 644 /etc/insecure_key*
|
|
||||||
chown root:root /etc/insecure_key*
|
|
||||||
cp /build/bin/enable_insecure_key /usr/sbin/
|
|
||||||
|
|
||||||
## Install cron daemon.
|
## Install cron daemon.
|
||||||
$minimal_apt_get_install cron
|
[ "$DISABLE_CRON" -eq 0 ] && /bd_build/services/cron/cron.sh || true
|
||||||
mkdir /etc/service/cron
|
|
||||||
chmod 600 /etc/crontab
|
|
||||||
cp /build/runit/cron /etc/service/cron/run
|
|
||||||
|
|
||||||
## Remove useless cron entries.
|
|
||||||
# Checks for lost+found and scans for mtab.
|
|
||||||
rm -f /etc/cron.daily/standard
|
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
source /build/buildconfig
|
source /bd_build/buildconfig
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
## Often used tools.
|
## Often used tools.
|
||||||
$minimal_apt_get_install curl less nano vim psmisc
|
$minimal_apt_get_install curl less vim-tiny psmisc
|
||||||
|
ln -s /usr/bin/vim.tiny /usr/bin/vim
|
||||||
|
|
||||||
## This tool runs a command as another user and sets $HOME.
|
## This tool runs a command as another user and sets $HOME.
|
||||||
cp /build/bin/setuser /sbin/setuser
|
cp /bd_build/bin/setuser /sbin/setuser
|
||||||
|
|||||||
@ -8,5 +8,5 @@ cp tools/docker-bash /usr/local/bin/
|
|||||||
cp tools/docker-ssh /usr/local/bin/
|
cp tools/docker-ssh /usr/local/bin/
|
||||||
cp tools/baseimage-docker-nsenter /usr/local/bin/
|
cp tools/baseimage-docker-nsenter /usr/local/bin/
|
||||||
mkdir -p /usr/local/share/baseimage-docker
|
mkdir -p /usr/local/share/baseimage-docker
|
||||||
cp image/insecure_key /usr/local/share/baseimage-docker/
|
cp image/services/sshd/keys/insecure_key /usr/local/share/baseimage-docker/
|
||||||
chmod 644 /usr/local/share/baseimage-docker/insecure_key
|
chmod 644 /usr/local/share/baseimage-docker/insecure_key
|
||||||
|
|||||||
@ -21,7 +21,7 @@ ID=`docker run -d -v $PWD/test:/test $NAME:$VERSION /sbin/my_init --enable-insec
|
|||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
echo " --> Obtaining IP"
|
echo " --> Obtaining IP"
|
||||||
IP=`docker inspect $ID | grep IPAddress | sed -e 's/.*: "//; s/".*//'`
|
IP=`docker inspect -f "{{ .NetworkSettings.IPAddress }}" "$ID"`
|
||||||
if [[ "$IP" = "" ]]; then
|
if [[ "$IP" = "" ]]; then
|
||||||
abort "Unable to obtain container IP"
|
abort "Unable to obtain container IP"
|
||||||
fi
|
fi
|
||||||
@ -35,7 +35,7 @@ docker exec -t -i $ID sv start /etc/service/sshd
|
|||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
echo " --> Logging into container and running tests"
|
echo " --> Logging into container and running tests"
|
||||||
cp image/insecure_key /tmp/insecure_key
|
cp image/services/sshd/keys/insecure_key /tmp/insecure_key
|
||||||
chmod 600 /tmp/insecure_key
|
chmod 600 /tmp/insecure_key
|
||||||
sleep 1 # Give container some more time to start up.
|
sleep 1 # Give container some more time to start up.
|
||||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /tmp/insecure_key root@$IP \
|
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /tmp/insecure_key root@$IP \
|
||||||
|
|||||||
@ -40,8 +40,8 @@ if ! test -e ~/.baseimage_docker_insecure_key; then
|
|||||||
else
|
else
|
||||||
dir=`dirname "$0"`
|
dir=`dirname "$0"`
|
||||||
dir=`cd "$dir/.." && pwd`
|
dir=`cd "$dir/.." && pwd`
|
||||||
if test -e "$dir/image/insecure_key"; then
|
if test -e "$dir/image/services/sshd/keys/insecure_key"; then
|
||||||
cp "$dir/image/insecure_key" ~/.baseimage_docker_insecure_key
|
cp "$dir/image/services/sshd/keys/insecure_key" ~/.baseimage_docker_insecure_key
|
||||||
else
|
else
|
||||||
echo "*** ERROR ***: Baseimage-docker insecure key not found." >&2
|
echo "*** ERROR ***: Baseimage-docker insecure key not found." >&2
|
||||||
echo "You probably didn't install docker-ssh properly. Please reinstall it:" >&2
|
echo "You probably didn't install docker-ssh properly. Please reinstall it:" >&2
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user