Using Docker [读书笔记] 1

Using Docker [读书笔记]

Containers are a lightweight and portable store for an application and its dependencies. 序的开头这么一句话, lightweight应该是较VM而言, 这里的container确实包含了你的应用及其依赖;
containerization: 集装箱化;
Containers share resources with the host OS;

Container 里面ps 看进程
psInContainer.png
Host OS 查看 docker 进程
psOutContainer.png

如果选择让container知道外部的线程, 那么container 内部其实是可以看到的
inContainerWithPidOption.png

The purpose of a VM is to fully emulate a foreign environment, whilst the purpose of a container is to make applications portable and self-contained;

Containers are an old concept. For decades, UNIX systems have had the chroot command which provides a simple form of filesystem isolation. FreeBSD has had the jail utility since 1998, which extended chroot sandboxing to processes. Solaris Zones offered a comparatively complete containerization technology around 2001, but was limited to the Solaris OS. Also in 2001, Parrallels Inc (then SWsoft) released the commercial Virtuozzo container technology for Linux, and later open sourced the core technology as OpenVZ in 2005[1]. Following on from this, Google started the development of CGroups for the Linux kernel and began moving their infrastructure to containers. The LXC project started in 2008 and brought together CGroups, kernel namespaces and chroot technology (amongst others) to provide a complete containerization solution. Finally, in 2013, Docker brought the final pieces to the containerization puzzle and the technology began to enter the mainstream.

Docker took the existing Linux container technology then wrapped it and extended it in various ways — primarily portable images and a user-friendly interface — to create a complete solution for the creation and distribution of containers. The Docker platform has two distinct components; the Docker Engine, which is responsible for creating and running containers and the Docker Hub, a cloud service for distributing containers.

The Docker Engine provides a very fast and convenient interface for running containers. Before this, running a container using a technology such as LXC required significant specialist knowledge and manual work. The Docker Hub provides an enormous number of public container images for download, allowing users to quickly get started and avoid duplicating work already done by others.

Early versions of Docker were little more than a wrapper around LXC paired with a Union Filesystem when start open-source;

Docker uses a Union File System (UFS) for containers, which allows multiple file systems to be mounted in a hierarchy and appear as a single file system. The file system from the image has been mounted as a read-only layer and any changes to the running container are made to a read-write layer mounted on top of this.

删除退出的container
$ docker rm $(docker ps -aq -f status=exited)

linux 磁盘 文件夹 大小查看

在 windows 系统上很容易查看整个磁盘的已使用大小, 也很容易看到某个文件夹下面的文件总大小.
其实在linux 系统中更容易, 一个命令行解决

查看磁盘使用情况:
df

查看某个文件夹下面的文件夹里面的大小
sudo du -sh *

制作自己的docker tomcat image

制作自己的dockfile image

新建文本文件: Dockerfile (没有后缀), 里面内容如下:

FROM tomcat:7.0
RUN rm -rf /usr/local/tomcat/webapps/ROOT
ADD http://ci.qa.tianxiaohui.com/job/bnrdash-r2-2_job_Eric/197/artifact/bnrdash/target/ROOT.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]

每一行解释:
1) 基于公共的tomcat:7.0 的image, 更多tomcat image 看这里 https://registry.hub.docker.com/_/tomcat/
2) 因为我自己的包是ROOT.war, 所以把tomcat 再带的删除, 也为了安全, 当然其它自带的最好也删除
3) 把CI做好的war 文件ccopy 进去
4) 默认启动tomcat

使用下面的命令打包(最后的点表示当前目录去找 Dockerfile):

docker build -t xiatian/tomcatBnrdash .

查看local的images, 已经包含最新的

docker images

那么就可以去run了, 下面分别开8081, 8082, 开了2个containers.

docker run -d -p 8081:8080 xiatian/tomcatBnrdash
docker run -d -p 8082:8080 xiatian/tomcatBnrdash

查看正在运行的container

docker ps

进入正在运行的container

docker exec -it  CONTAINER_ID bash


Java Collection Framework List, Set, Queue, Deque 关系图

使用 https://www.draw.io/ 在线画的, 只涉及到List, Set, Queue, Deque. 只包含util 包里面的类和接口.
接口以圆角长方形表示, 类以直角长方形表示.

在线浏览版本: https://drive.google.com/file/d/0B6ry0l2WQQIjclhSSGZyNGgxX1k/view?usp=sharing

离线下载版本, 下面 png 格式图片, 可以另存为, 放大. 也可以下载pdf 格式
pdf version: JavaCollection.pdf
JavaCollection.png

tomcat 配置在linux上, 机器重启后 自动启动

#!/bin/bash

### BEGIN INIT INFO
# Provides:        tomcat7
# Required-Start:  $network
# Required-Stop:   $network
# Default-Start:   2 3 4 5
# Default-Stop:    0 1 6
# Short-Description: Start/Stop Tomcat server
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

start() {
 sh /opt/apache-tomcat-7.0.59/bin/startup.sh
}

stop() {
 sh /opt/apache-tomcat-7.0.59/bin/shutdown.sh
}

case $1 in
  start|stop) $1;;
  restart) stop; start;;
  *) echo "Run as $0 <start|stop|restart>"; exit 1;;
esac

chmod 755 /etc/init.d/tomcat7
update-rc.d tomcat7 defaults

另外一种写法

 #!/bin/sh
 #tomcat auto-start
 case $1 in
        start)
            sh /opt/apache-tomcat-7.0.59/bin/startup.sh;;
        stop)
            sh /opt/apache-tomcat-7.0.59/bin/shutdown.sh;;
        restart)
            sh /opt/apache-tomcat-7.0.59/bin/shutdown.sh
            sh /opt/apache-tomcat-7.0.59/bin/startup.sh;;
        *)
            echo 'Usage:tomcat7 start|stop|restart';;
    esac
    exit 0

从这里抄过来的: http://askubuntu.com/questions/223944/how-to-automatically-restart-tomcat7-on-system-reboots