Docker摘要

Docker

https://www.docker.com/

消除应用的依赖矩阵。 消除硬件依赖 和 软件依赖。

  • Escape the app dependency matrix

    Eliminate the “it works on my machine” problem once and for all. Package dependencies with your apps in Docker containers for portability and predictability during development, testing, and deployment.

和任何栈工作。

在任何地方部署微服务和传统应用, 不用任何的昂贵的重写。

将应用隔离在容器中,消灭冲突和保证安全。

  • Works with any stack

    Deploy both microservices and traditional apps anywhere without costly rewrites. Isolate apps in containers to eliminate conflicts and enhance security.

更好的团队合作。

流水线式的合作关系从开发到运维, 更快地将功能和补丁部署到生产环境。

多产的开发者频繁发布release版本, 释放构建伟大软件的创造力。

  • Better team collaboration

    Streamline collaboration between developers and operators and get features and fixes into production faster. Productive developers doing frequent releases unleashes creativity to build awesome software.

http://www.docker.org.cn/book/docker/what-is-docker-16.html

Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的、可移植的、自给自足的容器。开发者在笔记本上编译测试通过的容器可以批量地在生产环境中部署,包括VMs(虚拟机)、bare metal、OpenStack 集群和其他的基础应用平台。 

Docker通常用于如下场景:

  • web应用的自动化打包和发布;
  • 自动化测试和持续集成、发布;
  • 在服务型环境中部署和调整数据库或其他的后台应用;
  • 从头编译或者扩展现有的OpenShift或Cloud Foundry平台来搭建自己的PaaS环境。

Docker入门

http://www.docker.org.cn/book/docker/docker-search-image-6.html

Docker镜像制作

commit方式

https://help.aliyun.com/document_detail/28023.html?spm=5176.doc42403.6.572.PRRKlq

1. 运行基础镜像容器

docker run -it ubuntu

然后你会发现你已经以root身份进入ubuntu

root@0bab204d8f9b:/#

你可以在这里安装你想要的软件, 比如:

apt-get install python -y
apt-get install openjdk-7-jdk
....

安装完成后, 退出

exit

2. 制作镜像

docker ps -n 1  #列出最新container

找到对应的CONTAINER ID , 如: 41570524e867

docker commit 41570524e867 myubuntu

完成后,可以使用以下命令查看是否成功。

docker images

dockerfile

本例中我们将制作一个 Ubuntu 镜像,内置python。镜像名称:myubuntu。

新建一个目录 dockerUbuntu,结构如下:

  1. dockerUbuntu
  2. |-- Dockerfile

文件 Dockerfile 的内容:

  1. FROM ubuntu:14.04
  2. # 这里要替换 your_name 为您的名字, 和your_email 为您的Email
  3. MAINTAINER your_name <your_email>
  4. # 更新源
  5. RUN apt-get update
  6. # 清除缓存
  7. RUN apt-get autoclean
  8. # 安装python
  9. RUN apt-get install -y python
  10. # 启动时运行这个命令
  11. CMD ["/bin/bash"]

运行以下命令,build镜像:

  1. cd dockerUbuntu #进入 dockerUbuntu 目录
  2. docker build -t myubuntu ./ #正式build, 命名为 myubuntu
  • 注意:docker 命令在ubuntu中默认需要加sudo才能运行,而在Mac/Windows中,需要从“Docker Quickstart Terminal”中启动的命令行工具中运行。

build 完成后, 运行以下命令查看:

  1. docker images

可以看到类似下面的结果:

制作docker镜像,除了Dockerfile这种方式外,还有更加直观的制作方式

Docker命令

https://github.com/wsargent/docker-cheat-sheet#delete-stopped-containers

Delete old containers

docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs docker rm

Delete stopped containers

docker rm -v $(docker ps -a -q -f status=exited)

Delete dangling images

docker rmi $(docker images -q -f dangling=true)

Delete all images

docker rmi $(docker images -q)

运行WINDOWS APP的镜像

可运行带图形界面的 win app。

https://hub.docker.com/r/suchja/wine/

https://github.com/suchja/wine

GUI via suchja/x11server

If you like to see the graphical output, you first need to run a container based on suchja/x11server like this:

docker run -d --name display -e VNC_PASSWORD=newPW -p 5900:5900 suchja/x11server

Now you can start the Wine container like this:

docker run --rm -it --link display:xserver --volumes-from display suchja/wine:latest /bin/bash

The --link display:xserver and --volumes-from display option is only required, if graphical output from Wine shall be shown via suchja/x11server. Otherwise these two options can be omitted. Then wine will show warning messages, because it is not able to display graphical output.

应用于持续集成

持续集成过程包括若干环境不一的过程, 例如代码下载、 自动化单元测试、自动化CRT测试、使用astyle进行代码风格检查, 使用sourcemonitor进行代码检查。

每个过程的依赖的工具和环境, 可以固化到docker镜像中, 为每个过程制作单一的镜像。

使用Jenkins pipeline, 将持续集成的过程串起来:

https://jenkins.io/doc/book/pipeline-as-code/

Pipeline as Code describes a set of features that allow Jenkins users to define pipelined job processes with code, stored and versioned in a source repository. These features allow Jenkins to discover, manage, and run jobs for multiple source repositories and branches — eliminating the need for manual job creation and management.

To use Pipeline as Code, projects must contain a file named Jenkinsfile in the repository root, which contains a "Pipeline script."

原文地址:https://www.cnblogs.com/lightsong/p/6799718.html