更快的交付和部署html
使用docker開發人員可使用鏡像來快速構建一套標準的開發環境node
開發完以後,測試和運維人員能夠直接使用徹底相同的環境來部署代碼python
只要是開發測試過的代碼就能夠確保在生產環境無縫運行linux
docker能夠快速建立和刪除容器,實現快速迭代,節約開發、測試及部署時間nginx
更高的利用資源git
運行docker不須要額外的虛擬化管理程序的支持web
docker是內核級的虛擬化,能夠實現更高的性能,同時對資源的額外需求低redis
與傳統虛擬機方式相比,docker性能要提升1~2個數量級docker
更輕鬆地遷移和擴展django
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