source: mundodocker
前情提要
Docker 從 17.05 版本以後就有這個貼心的設計, multi-stage build(多階段建構),這對於長期因為 build docker image 太大而困擾的我們真的是很方便,所以現在 multi-stage build 幾乎已經成為 build docker image 標準配備。
在不支持多階段建構的年代,通常會有兩種作法:
LXC (LinuX Containers) provide an isolated operating system environment with its own file system, network, process and block I/O space. A favorite way to describe containers is that they are like “chroot on steroids”, since they provide the file system isolation that chroot jails provide but they go beyond that by also providing an IP address, a separate process domain, user ids and dedicated access to the host’s physical resources (i.e. memory, CPU) which chroot jails do not provide
| Virtualization (i.e. kvm, xen) | LXC Containers | |
| Footprint | Requires a hypervisor and a full operating system image. | Does not require a hypervisor or a separate operating system image. |
| OS supported | Any OS supported by the hypervisor | Most Linux distros, uses same kernel as host |
| Typical server deployment | 10 – 100 VMs | 100 - 1000 containers |
| Boot time | Less than a minute | Seconds |
| Physical resources use (i.e. memory, CPU) | Each VM has resource reserved for its own use | Shared by all containers |
Docker images are essentially a collection of files which include everything needed to run that process. This is everything from the OS packages and up.
A docker image has a default process it runs when it is instantiated. This could be bash, to drop you into the terminal, or a web server so you can access it from the browser.
CoreOS (alpha) core@core-01 ~ $ docker run centos:centos6 yum update Loaded plugins: fastestmirror Setting up Update Process Resolving Dependencies --> Running transaction check ---> Package ca-certificates.noarch 0:2013.1.95-65.1.el6_5 will be updated ---> Package ca-certificates.noarch 0:2014.1.98-65.0.el6_5 will be an update --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Updating: ca-certificates noarch 2014.1.98-65.0.el6_5 updates 1.1 M Transaction Summary ================================================================================ Upgrade 1 Package(s) Total download size: 1.1 M
docker run -i -t centos:centos6 /bin/bash bash-4.1#
Please remember that at this time, we don't claim Docker out-of-the-box is suitable for containing untrusted programs with root privileges. So if you're thinking "pfew, good thing we upgraded to 1.0 or we were toast", you need to change your underlying configuration now. Add apparmor or selinux containment, map trust groups to separate machines, or ideally don't grant root access to the application.最後Xen Community 也有幾個建議:
Docker will soon support user namespaces, which is a great additional security layer but also not a silver bullet!
When we feel comfortable saying that Docker out-of-the-box can safely contain untrusted uid0 programs, we will say so clearly.
However, using containers for security isolation is not a good idea. In a blog last August, one of Docker’s engineers expressed optimism that containers would eventually catch up to virtual machines from a security standpoint. But in a presentation given in January, the same engineer said that the only way to have real isolation with Docker was to either run one Docker per host, or one Docker per VM. (Or, as Solomon Hykes says here, to use Dockers that trust each other in the same host or the same VM.)結論: