标签:ges tps 临时 lxc linux容器 auto service fas continue
更快的交付和部署
使用docker开发人员可以使用镜像来快速构建一套标准的开发环境
开发完之后,测试和运维人员可以直接使用完全相同的环境来部署代码
只要是开发测试过的代码就可以确保在生产环境无缝运行
docker可以快速创建和删除容器,实现快速迭代,节约开发、测试及部署时间
更高的利用资源
运行docker不需要额外的虚拟化管理程序的支持
docker是内核级的虚拟化,可以实现更高的性能,同时对资源的额外需求低
与传统虚拟机方式相比,docker性能要提高1~2个数量级
更轻松地迁移和扩展
docker容器几乎可以在任意的平台运行,包括物理机、虚拟机、公有云、私有云、PC等
支持主流的操作系统发行版本
高兼容性可以让用户在不同的平台之间轻松的迁移应用
更轻松的管理和更新
使用dockerfile只需小的配置修改就可以替代大量的更新工作
所有的修改都以增量的方式被发布和更新,从而实现自动化且高效的容器管理
特性 | 容器 | 虚拟机 |
---|---|---|
启动速度 | 秒级 | 分钟级 |
性能 | 接近原生 | 较好 |
内存 | MB级 | GB级 |
硬盘适应 | MB级 | GB级 |
运行密度 | 单台主机支持上千个 | 单台主机支持几个 |
隔离性 | 安全隔离 | 完全隔离 |
迁移 | 优秀 | 一般 |
# 查看操作系统内核版本
[root@ccc ~]# uname -a
Linux ccc 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
# 备份原来的yum源
[root@ccc ~]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
# 刷新yum源缓存
[root@ccc ~]# yum makecache
# 安装必要的一些系统工具
[root@ccc ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 下载新的CentOS-Base.repo 到 /etc/yum.repos.d/
[root@ccc ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 安装yum源
[root@ccc ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@ccc ~]# yum makecache fast
[root@ccc ~]# yum -y install docker-ce
[root@ccc ~]# systemctl enable --now docker
[root@ccc ~]# docker info
[root@ccc ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2020-11-30 21:57:57 CST; 1min 1s ago
# 第一种方式
root@alvin-test-os:~# uname -a
# 第二种方式
root@alvin-test-os:~# cat /proc/version
root@alvin-test-os:~# apt-get update
root@alvin-test-os:~# apt-get -y install apt-transport-https ca-certificates curl software-properties-common
root@alvin-test-os:~# curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - OK
root@alvin-test-os:~# sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
root@alvin-test-os:~# sudo apt-get -y update
root@alvin-test-os:~# docker version
[root@ccc ~]# docker run -d --rm --name nginx -p 80:80 nginx
Unable to find image ‘nginx:latest‘ locally
latest: Pulling from library/nginx
bb79b6b2107f: Pull complete
5a9f1c0027a7: Downloading [==============> ] 7.457MB/26.49MB
5a9f1c0027a7: Downloading [======================> ] 12.17MB/26.49MB
166a2418f7e8: Download complete
1966ea362d23: Download complete
[root@ccc ~]# docker pull busybox:latest
或
[root@ccc ~]# docker pull docker.io/library/busybox:latest
[root@ccc ~]# docker pull nginx:1.17
1.17: Pulling from library/nginx
afb6ec6fdc1c: Pull complete
b90c53a0b692: Pull complete
11fa52a0fdc0: Pull complete
Digest: sha256:6fff55753e3b34e36e24e37039ee9eae1fe38a6420d8ae16ef37c92d1eb26699
Status: Downloaded newer image for nginx:1.17
docker.io/library/nginx:1.17
[root@ccc ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest bc9a0695f571 5 days ago 133MB
busybox latest dc3bacd8b5ea 6 days ago 1.23MB
[root@ccc ~]# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest bc9a0695f571 5 days ago 133MB
busybox latest dc3bacd8b5ea 6 days ago 1.23MB
nginx 1.17 9beeba249f3e 6 months ago 127MB
[root@ccc ~]# docker images --digests
REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE
nginx latest sha256:6b1daa9462046581ac15be20277a7c75476283f969cb3a61c8725ec38d3b01c3 bc9a0695f571 5 days ago 133MB
busybox latest sha256:9f1c79411e054199210b4d489ae600a061595967adb643cd923f8515ad8123d2 dc3bacd8b5ea 6 days ago 1.23MB
nginx 1.17 sha256:6fff55753e3b34e36e24e37039ee9eae1fe38a6420d8ae16ef37c92d1eb26699 9beeba249f3e 6 months ago 127MB
[root@ccc ~]# docker images -q
bc9a0695f571
dc3bacd8b5ea
9beeba249f3e
[root@Centos7 docker]# docker push registry.cn-hangzhou.aliyuncs.com/alvinos/py15-nginx:1.19.2
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/alvinos/py15-nginx]
908cf8238301: Pushed
eabfa4cd2d12: Pushed
60c688e8765e: Pushed
f431d0917d41: Pushed
07cab4339852: Pushed
1.19.2: digest: sha256:794275d96b4ab96eeb954728a7bf11156570e8372ecd5ed0cbc7280313a27d19 size: 1362
[root@ccc ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest bc9a0695f571 5 days ago 133MB
busybox latest dc3bacd8b5ea 6 days ago 1.23MB
nginx 1.17 9beeba249f3e 6 months ago 127MB
[root@ccc ~]# docker tag busybox:latest mybusybox:latest
[root@ccc ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest bc9a0695f571 5 days ago 133MB
mybusybox latest dc3bacd8b5ea 6 days ago 1.23MB
busybox latest dc3bacd8b5ea 6 days ago 1.23MB
nginx 1.17 9beeba249f3e 6 months ago 127MB
[root@ccc ~]# docker inspect busybox
[
{
"Id": "sha256:dc3bacd8b5ea796cea5d6070c8f145df9076f26a6bc1c8981fd5b176d37de843",
"RepoTags": [
"busybox:latest",
"mybusybox:latest"
],
...
"Metadata": {
"LastTagTime": "2020-11-30T22:39:16.14474717+08:00"
}
}
]
[root@ccc ~]# docker history busybox
IMAGE CREATED CREATED BY SIZE COMMENT
dc3bacd8b5ea 6 days ago /bin/sh -c #(nop) CMD ["sh"] 0B
<missing> 6 days ago /bin/sh -c #(nop) ADD file:7f51bbea8802a227e… 1.23MB
[root@ccc ~]# docker search python
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
python Python is an interpreted, interactive, objec… 5661 [OK]
django Django is a free web application framework, … 1021 [OK]
...
[root@ccc ~]# docker search python -f stars=300
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
python Python is an interpreted, interactive, objec… 5661 [OK]
django Django is a free web application framework, … 1021 [OK]
[root@ccc ~]# docker search python --limit 3
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
python Python is an interpreted, interactive, objec… 5661 [OK]
nikolaik/python-nodejs Python with Node.js 55 [OK]
circleci/python Python is an interpreted, interactive, objec… 41
[root@ccc ~]# docker search python --limit 3 --no-trunc
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
python Python is an interpreted, interactive, object-oriented, open-source programming language. 5661 [OK]
nikolaik/python-nodejs Python with Node.js 55 [OK]
circleci/python Python is an interpreted, interactive, object-oriented, open-source programming language. 41
[root@ccc ~]# docker rmi redis
Untagged: redis:latest
Untagged:
redis@sha256:5b98e32b58cdbf9f6b6f77072c4915d5ebec43912114031f37fa5fa25b032489
# -f 强制删除镜像
[root@ccc ~]# docker rmi -f redis
Untagged: redis:latest
Untagged:
redis@sha256:5b98e32b58cdbf9f6b6f77072c4915d5ebec43912114031f37fa5fa25b032489
# 查看原来的镜像
[root@ccc ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest bc9a0695f571 5 days ago 133MB
busybox latest dc3bacd8b5ea 6 days ago 1.23MB
mybusybox latest dc3bacd8b5ea 6 days ago 1.23MB
nginx 1.17 9beeba249f3e 6 months ago 127MB
# -a 删除所有的未被使用的镜像
[root@ccc ~]# docker image prune -a
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
Deleted Images:
untagged: nginx:1.17
...
# -f 强制删除镜像而不进行提示
alvin@AlvindeMacBook-Pro: docker image prune -a -f
Deleted Images:
untagged: registry.cn-hangzhou.aliyuncs.com/alvinos/swoole:latest
...
参数:
-a : 维护者
-m : 简介
-p : 保存镜像时,镜像暂停运行
-d : 以守护进程的方式运行
-p : 指定端口映射(格式:宿主主机端口:容器向外暴露的端口)
docker run -d -p 8899:80 nginx:1.19.2
-P : 随机端口映射
docker run -d -P nginx:1.19.2
--name: 指定容器的名称(同一台宿主主机上的docker名称不能重复)
docker run -d --name nginx_name -P nginx:1.19.2
--rm:当一个容器结束了它的生命周期,就立即删除
docker run -d --rm --name nginx_rm nginx:1.19.2
-v: 映射存储卷(可以映射文件及文件夹)
docker run -d -v /root/test:/usr/share/nginx/html -P nginx:1.19.2
-i : 打开标准输出
-t : 创建一个伪准端
-e : 在容器内设置一个环境变量
docker run -d -e NGINX_NAME=nginx nginx:1.19.2
[root@alvin-test-os ~]# docker run -d --name nginx -p 80:80 nginx
Unable to find image ‘nginx:latest‘ locally
latest: Pulling from library/nginx
852e50cd189d: Pull complete
a29b129f4109: Pull complete
b3ddf1fa5595: Pull complete
c5df295936d3: Pull complete
232bf38931fc: Pull complete
Digest: sha256:c3a1592d2b6d275bef4087573355827b200b00ffc2d9849890a4f3aa2128c4ae
Status: Downloaded newer image for nginx:latest
6381d29d6e0ec3f6b01cf1aabb58b799ee88acf1a722e251807c9cb44e73a3e0
标签:ges tps 临时 lxc linux容器 auto service fas continue
原文地址:https://www.cnblogs.com/caojiaxin/p/14065610.html