Docker
docker是什么?
docker最初是dotCloud公司创始人Solomom Hykes在法国期间发起的一个公司内部项目,它是基于dotCloud公司多年云服务技术的一次革新,并在2013年3月以Apache2.0授权协议开源,主要项目代码在GitHub上进行维护...
docker是linux容器的一种封装,提供简单易用的容器使用接口,它是最流行的linux容器解决方案.docker的接口非常简单,用户可以方便的创建和销毁容器,docker将应用程序的依赖,打包在一个文件里面,运行这个文件就会生成虚拟容器,程序运行在虚拟容器里,如同真实物理机上运行一样,反正就是有了docker,就不用担心讨厌的环境配置问题了!
为什么要用docker?
它作为一种新兴的虚拟化方式,Docker跟传统的虚拟化方式相比具有众多的优势.
docker容器的优势
- 更高效的利用系统资源
- 更快速的启动时间
- 一直的运行环境
- 持续交付和部署
- 更轻松的迁移
- 更轻松的维护和扩展
docker的生命周期
镜像 (images)
Docker镜像就是一个只读的模板,镜像可以用来创建容器.docker提供了一个很简单的机制来创建镜像或更新现有镜像,用户甚至可以从其他人那里下载已经做好的镜像直接使用
容器 (container)
镜像(image)和容器(container)的关系,就像面向对象中类和实例的关系一样,镜像是静态定义的class ;容器是镜像运行时的实体object
#容器随时都可以被创建,暂停,销毁,停止,每个容器都是相互隔离的,保证安全的平台,docker利用容器运行应用.
#我们也可以把容器看作简易的linux环境.
仓库 (repository)
仓库是存放镜像文件的场所,分为公开仓库(public)和私有仓库(Private)
#最大的公开仓库就是Docker Hub,存放了数量庞大的镜像供用户下载.
#用户创建自己镜像之后就可以使用push命令将它上传到公开或私有库,这样另外一台机器使用的时候,只需要从仓库上pull下来即可
#Docker仓库和Git的概念类似,仓库注册服务器和GitHub这样的代码托管服务类似.
部署docker

###注意: 若之前装过docker,可用以下命令移除docker
# yum remove docker
###步骤
1. 安装必要的系统工具
# yum install -y yum-utils device-mapper-persistent-data lvm2
2. 添加软件源信息
# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3. 更新 yum 缓存
# yum makecache fast
4. 安装docker-ce
# yum -y install docker-ce
5. 启动docker
# systemctl start docker
6. 测试运行 hello-world
# docker run hello-world
## 如果测试失败,首先测试如下:
# #docker version | docker info #两个命令都没问题的话再进行分析问题.
7.安装docker之后,测试hello-world镜像,终端卡在Unable to find image 'hello-world:latest' locally位置 ?
#分析 : docker在本地没有找到hello-world镜像,也没有从docker仓库中拉取镜像,出项这个问题的原因:是应为docker服务器再国外,我们在国内无法正常拉取镜像,所以就需要我们为docker设置国内阿里云的镜像加速器;
#解决
1.修改配置文件 /etc/docker/daemon.json 如下:
{"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]}
2. sudo systemctl restart docker #重启docker即可!
安装docker
docker常用命令
增
docker pull hello-world #下载docker镜像,产生容器示例
docker run ubuntu #运行docker镜像,ubuntu系统
docker run -it ubuntu /bin/bush #交互式运行ubuntu容器,进入容器空间内 参数解释 -i 交互式的命令操作,-t开启一个终端提供访问, /bin/bush 指定shell解释器
打包构建一个携带vim的contos镜像文件
1.docker run -it centos /bin/bush #先运行一个centos的基础镜像文件
2.yum install vim -y #安装vim
3.exit #退出容器
4.docker commit -m "description info" -a "author" 1d5698b91178 (当前镜像id) centos-vim #提交这个容器,生成新的镜像
导出/导入镜像文件
#方式1 (无法修改镜像名称)
docker save 94e814e2efa8 > /opt/ubuntu.tar.gz #导出依据镜像ID
docker load 94e814e2efa8 < /opt/ubuntu.tar.gz #导入镜像,自动解压缩
#方式2
docker export a0a83edd02d0 >docker-test.tar #导出依据容器ID
docker import - new-docker-test < docker-test.tar #导入镜像
查
#---注意运行过docker镜像后,会产生容器记录;docker容器必须有后台程序在运行,否则容器就退出---
docker image ls /docker images #两者都是查看镜像
docker container ls /docker ps #两者都是查看正在运行的容器进程
docker ps -a 查看所有的容器记录
docker search centos #查询docker镜像记录
删 (深思而行)
docker rm 容器id # 删除容器记录
docker rm `docker ps -aq` # 批量删除容器记录,不推荐操作此命令
docker rm -f `docker ps -aq` #强制删除所有容器记录,包括正在运行的容器,慎用!!!
docker rmi 镜像id #删除镜像记录
docker rmi `docker images -aq` #批量删除镜像文件
改
docker tag 镜像id 新的镜像名 #修改docker镜像名,tag标记名
docker镜像常用命令
docker images #查看所有本级镜像
docker pull redis # 获取新的redis镜像
docker search nginx #搜索nginx 的镜像
容器相关
docker start/stop 容器id #启/停docker容器
docker run -it --rm 94e /bin/bash # --rm运行容器,退出后,删除容器记录
docker run --name mynginx 881 /bin/bash #运行容器后给其命名
docker run -d centos /bin/sh -c "while true;do echo hello centos; sleep 1;done" #后台不断运行一个shell语句 -d后台运行, -C指定一个shell语句
docker logs 容器id #查看容器空间内的日志 !!!
docker logs -f 容器id #不间断打印容器内日志信息
docker exec -it 容器id /bin/bash # 进入正在运行的容器空间
启动容器的方式
启动容器的方式有两种:
#1.基于镜像新建一个容器并启动,也就是新建一个容器 docker run nginx
#2.在处于(stopped)停止状态下的容器重新启动,利用原来启动过的容器id启动. docker start as5
#因为Docker的容器太过于轻量级,大部分用户都是随时删除,随时创建.
外部访问容器
在容器中可以运行网络应用,但是要让外部也可以访问这些应用,可以通过-P 和-p参数进行端口映射!!!
docker的端口映射
-P #大写P参数会随机映射端口到容器开放的网络端口
docker run -d -P training/webapp python app.py
检查映射的端口
docker ps -l #0.0.0.0:32771->5000/tcp
其中32771是宿主机ip的端口,5000是容器端口
最好通过-p参数指定映射端口,因为-P参数随机映射端口,给访问带来极大不便
docker run -d -p 9999:5000 training/webapp python app.py
52ceb29239466617e2ebff333fbb9e59514910d1309961c6a94a191fbf68a646
查看指定容器的端口映射
#[root@localhost opt]# docker port 52c
5000/tcp -> 0.0.0.0:32771
然后通过宿主机ip:9999访问服务器
dockerfile
...研究待续
CrazyShenldon
posted @
2019-03-13 22:13
FindSoul
阅读(
170)
评论()
收藏
举报
var RENDERER = {
POINT_INTERVAL : 5,
FISH_COUNT : 3,
MAX_INTERVAL_COUNT : 50,
INIT_HEIGHT_RATE : 0.5,
THRESHOLD : 50,
init : function(){
this.setParameters();
this.reconstructMethods();
this.setup();
this.bindEvent();
this.render();
},
setParameters : function(){
this.$window = $(window);
this.$container = $('#jsi-flying-fish-container');
this.$canvas = $('');
this.context = this.$canvas.appendTo(this.$container).get(0).getContext('2d');
this.points = [];
this.fishes = [];
this.watchIds = [];
},
createSurfacePoints : function(){
var count = Math.round(this.width / this.POINT_INTERVAL);
this.pointInterval = this.width / (count - 1);
this.points.push(new SURFACE_POINT(this, 0));
for(var i = 1; i < count; i++){
var point = new SURFACE_POINT(this, i * this.pointInterval),
previous = this.points[i - 1];
point.setPreviousPoint(previous);
previous.setNextPoint(point);
this.points.push(point);
}
},
reconstructMethods : function(){
this.watchWindowSize = this.watchWindowSize.bind(this);
this.jdugeToStopResize = this.jdugeToStopResize.bind(this);
this.startEpicenter = this.startEpicenter.bind(this);
this.moveEpicenter = this.moveEpicenter.bind(this);
this.reverseVertical = this.reverseVertical.bind(this);
this.render = this.render.bind(this);
},
setup : function(){
this.points.length = 0;
this.fishes.length = 0;
this.watchIds.length = 0;
this.intervalCount = this.MAX_INTERVAL_COUNT;
this.width = this.$container.width();
this.height = this.$container.height();
this.fishCount = this.FISH_COUNT * this.width / 500 * this.height / 500;
this.$canvas.attr({width : this.width, height : this.height});
this.reverse = false;
this.fishes.push(new FISH(this));
this.createSurfacePoints();
},
watchWindowSize : function(){
this.clearTimer();
this.tmpWidth = this.$window.width();
this.tmpHeight = this.$window.height();
this.watchIds.push(setTimeout(this.jdugeToStopResize, this.WATCH_INTERVAL));
},
clearTimer : function(){
while(this.watchIds.length > 0){
clearTimeout(this.watchIds.pop());
}
},
jdugeToStopResize : function(){
var width = this.$window.width(),
height = this.$window.height(),
stopped = (width == this.tmpWidth && height == this.tmpHeight);
this.tmpWidth = width;
this.tmpHeight = height;
if(stopped){
this.setup();
}
},
bindEvent : function(){
this.$window.on('resize', this.watchWindowSize);
this.$container.on('mouseenter', this.startEpicenter);
this.$container.on('mousemove', this.moveEpicenter);
this.$container.on('click', this.reverseVertical);
},
getAxis : function(event){
var offset = this.$container.offset();
return {
x : event.clientX - offset.left + this.$window.scrollLeft(),
y : event.clientY - offset.top + this.$window.scrollTop()
};
},
startEpicenter : function(event){
this.axis = this.getAxis(event);
},
moveEpicenter : function(event){
var axis = this.getAxis(event);
if(!this.axis){
this.axis = axis;
}
this.generateEpicenter(axis.x, axis.y, axis.y - this.axis.y);
this.axis = axis;
},
generateEpicenter : function(x, y, velocity){
if(y < this.height / 2 - this.THRESHOLD || y > this.height / 2 + this.THRESHOLD){
return;
}
var index = Math.round(x / this.pointInterval);
if(index < 0 || index >= this.points.length){
return;
}
this.points[index].interfere(y, velocity);
},
reverseVertical : function(){
this.reverse = !this.reverse;
for(var i = 0, count = this.fishes.length; i < count; i++){
this.fishes[i].reverseVertical();
}
},
controlStatus : function(){
for(var i = 0, count = this.points.length; i < count; i++){
this.points[i].updateSelf();
}
for(var i = 0, count = this.points.length; i < count; i++){
this.points[i].updateNeighbors();
}
if(this.fishes.length < this.fishCount){
if(--this.intervalCount == 0){
this.intervalCount = this.MAX_INTERVAL_COUNT;
this.fishes.push(new FISH(this));
}
}
},
render : function(){
requestAnimationFrame(this.render);
this.controlStatus();
this.context.clearRect(0, 0, this.width, this.height);
this.context.fillStyle = 'hsl(0, 0%, 95%)';
for(var i = 0, count = this.fishes.length; i < count; i++){
this.fishes[i].render(this.context);
}
this.context.save();
this.context.globalCompositeOperation = 'xor';
this.context.beginPath();
this.context.moveTo(0, this.reverse ? 0 : this.height);
for(var i = 0, count = this.points.length; i < count; i++){
this.points[i].render(this.context);
}
this.context.lineTo(this.width, this.reverse ? 0 : this.height);
this.context.closePath();
this.context.fill();
this.context.restore();
}
};
var SURFACE_POINT = function(renderer, x){
this.renderer = renderer;
this.x = x;
this.init();
};
SURFACE_POINT.prototype = {
SPRING_CONSTANT : 0.03,
SPRING_FRICTION : 0.9,
WAVE_SPREAD : 0.3,
ACCELARATION_RATE : 0.01,
init : function(){
this.initHeight = this.renderer.height * this.renderer.INIT_HEIGHT_RATE;
this.height = this.initHeight;
this.fy = 0;
this.force = {previous : 0, next : 0};
},
setPreviousPoint : function(previous){
this.previous = previous;
},
setNextPoint : function(next){
this.next = next;
},
interfere : function(y, velocity){
this.fy = this.renderer.height * this.ACCELARATION_RATE * ((this.renderer.height - this.height - y) >= 0 ? -1 : 1) * Math.abs(velocity);
},
updateSelf : function(){
this.fy += this.SPRING_CONSTANT * (this.initHeight - this.height);
this.fy *= this.SPRING_FRICTION;
this.height += this.fy;
},
updateNeighbors : function(){
if(this.previous){
this.force.previous = this.WAVE_SPREAD * (this.height - this.previous.height);
}
if(this.next){
this.force.next = this.WAVE_SPREAD * (this.height - this.next.height);
}
},
render : function(context){
if(this.previous){
this.previous.height += this.force.previous;
this.previous.fy += this.force.previous;
}
if(this.next){
this.next.height += this.force.next;
this.next.fy += this.force.next;
}
context.lineTo(this.x, this.renderer.height - this.height);
}
};
var FISH = function(renderer){
this.renderer = renderer;
this.init();
};
FISH.prototype = {
GRAVITY : 0.4,
init : function(){
this.direction = Math.random() < 0.5;
this.x = this.direction ? (this.renderer.width + this.renderer.THRESHOLD) : -this.renderer.THRESHOLD;
this.previousY = this.y;
this.vx = this.getRandomValue(4, 10) * (this.direction ? -1 : 1);
if(this.renderer.reverse){
this.y = this.getRandomValue(this.renderer.height * 1 / 10, this.renderer.height * 4 / 10);
this.vy = this.getRandomValue(2, 5);
this.ay = this.getRandomValue(0.05, 0.2);
}else{
this.y = this.getRandomValue(this.renderer.height * 6 / 10, this.renderer.height * 9 / 10);
this.vy = this.getRandomValue(-5, -2);
this.ay = this.getRandomValue(-0.2, -0.05);
}
this.isOut = false;
this.theta = 0;
this.phi = 0;
},
getRandomValue : function(min, max){
return min + (max - min) * Math.random();
},
reverseVertical : function(){
this.isOut = !this.isOut;
this.ay *= -1;
},
controlStatus : function(context){
this.previousY = this.y;
this.x += this.vx;
this.y += this.vy;
this.vy += this.ay;
if(this.renderer.reverse){
if(this.y > this.renderer.height * this.renderer.INIT_HEIGHT_RATE){
this.vy -= this.GRAVITY;
this.isOut = true;
}else{
if(this.isOut){
this.ay = this.getRandomValue(0.05, 0.2);
}
this.isOut = false;
}
}else{
if(this.y < this.renderer.height * this.renderer.INIT_HEIGHT_RATE){
this.vy += this.GRAVITY;
this.isOut = true;
}else{
if(this.isOut){
this.ay = this.getRandomValue(-0.2, -0.05);
}
this.isOut = false;
}
}
if(!this.isOut){
this.theta += Math.PI / 20;
this.theta %= Math.PI * 2;
this.phi += Math.PI / 30;
this.phi %= Math.PI * 2;
}
this.renderer.generateEpicenter(this.x + (this.direction ? -1 : 1) * this.renderer.THRESHOLD, this.y, this.y - this.previousY);
if(this.vx > 0 && this.x > this.renderer.width + this.renderer.THRESHOLD || this.vx < 0 && this.x < -this.renderer.THRESHOLD){
this.init();
}
},
render : function(context){
context.save();
context.translate(this.x, this.y);
context.rotate(Math.PI + Math.atan2(this.vy, this.vx));
context.scale(1, this.direction ? 1 : -1);
context.beginPath();
context.moveTo(-30, 0);
context.bezierCurveTo(-20, 15, 15, 10, 40, 0);
context.bezierCurveTo(15, -10, -20, -15, -30, 0);
context.fill();
context.save();
context.translate(40, 0);
context.scale(0.9 + 0.2 * Math.sin(this.theta), 1);
context.beginPath();
context.moveTo(0, 0);
context.quadraticCurveTo(5, 10, 20, 8);
context.quadraticCurveTo(12, 5, 10, 0);
context.quadraticCurveTo(12, -5, 20, -8);
context.quadraticCurveTo(5, -10, 0, 0);
context.fill();
context.restore();
context.save();
context.translate(-3, 0);
context.rotate((Math.PI / 3 + Math.PI / 10 * Math.sin(this.phi)) * (this.renderer.reverse ? -1 : 1));
context.beginPath();
if(this.renderer.reverse){
context.moveTo(5, 0);
context.bezierCurveTo(10, 10, 10, 30, 0, 40);
context.bezierCurveTo(-12, 25, -8, 10, 0, 0);
}else{
context.moveTo(-5, 0);
context.bezierCurveTo(-10, -10, -10, -30, 0, -40);
context.bezierCurveTo(12, -25, 8, -10, 0, 0);
}
context.closePath();
context.fill();
context.restore();
context.restore();
this.controlStatus(context);
}
};
$(function(){
RENDERER.init();
});