Docker学习笔记・04

这篇文章里面记录关于docker的一些概念。

「Image」是一个数据包,里面包含了要运行在「Container」里面的脚本以及所需要的相关的文件。「Image」不需要完整的操作系统,因为「Container」本身不是一个「Hypervisor」(比如VMWare,VirtualBox和Parallel Desktop都是完整的虚拟机,也就是Hypervisor)。

「Container」就是隔离的内核运行环境,是靠操作系统层面提供相关的功能支持起来的。每个操作系统在内核层面所使用的「Container」隔离技术不一样,下面是从书中1的摘抄:

查看本机已有的images:

$ docker images
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
docker.io/jaegertracing/all-in-one   latest              ac3c5fe795ac        2 days ago          48.13 MB
docker.io/ubuntu                     latest              00fd29ccc6f1        3 weeks ago         110.5 MB
docker.io/hello-world                latest              f2a91732366c        7 weeks ago         1.848 kB

构建这些images需要「Dockerfile」,「Dockerfile」是描述Image的文件,可以类比地理解为RPM的spec文件,当然还有些许差异。下面是一个「Dockerfile」的例子2

# Install a rethinkdb node. The node will be accessible via HTTP on port 8100. The port can be changed.

# After creating the image you can run:
#
#    docker run -i -t rethinkdb
#
# Which will run with database storage in /var/rethinkdb on the containers file system
#
# To expose a system directory on the host:
#
#    First initialize the database directory
#
#    docker run -b /local/path:/var/rethinkdb -i -t rethinkdb create -d /var/rethinkdb/db
#
#    Then you can run new containers that access that database.
#
#    docker run -b /local/path:/var/rethinkdb -i -t rethinkdb
#
#    Just don't run multiple containers using that at the same time.
#
# This image will be created to use an entrypoint. If you need to create a container 
#   with a shell you can run:
#
#    docker run -i -t -entrypoint='/bin/bash' rethinkdb -i
#
#    Just keep in mind that's giving you a shell in a new instance of the image not 
#    connecting you to an already running container.

FROM ubuntu
MAINTAINER Kimbro Staken

RUN echo "0.2" > /version

#ADD https://raw.github.com/kstaken/dockerfile-examples/master/rethinkdb-install.sh /rethinkdb-install.sh
ADD rethinkdb-install.sh /

#RUN /bin/bash /rethinkdb-install.sh

EXPOSE 8100

#ENTRYPOINT ["rethinkdb"]

#CMD ["-d", "/var/rethinkdb/db", "--bind", "all", "--http-port", "8100"] 

可以自己试着通过Dockerfile来build一个image试试看。

  1. Matthias, Karl, and Sean P. Kane. Docker: Up & Running: Shipping Reliable Containers in Production. “ O’Reilly Media, Inc.”, 2015. 

  2. https://github.com/kstaken/dockerfile-examples/blob/master/rethinkdb/Dockerfile 

My Github Page: https://github.com/liweinan

Powered by Jekyll and Theme by solid

If you have any question want to ask or find bugs regarding with my blog posts, please report it here:
https://github.com/liweinan/liweinan.github.io/issues