容器是一種基礎工具;泛指任何可用於容納其餘物品的工具,能夠部分或徹底封閉,被用於容納、存儲、運輸物品;html
人類使用容器的歷史至少有十萬年,甚至有數百萬年的歷史前端
如:瓶、罐、箱、桶、袋linux
nmpnginx
machine + swarm + composeweb
mesos + marathonredis
kubernetes à k8sdocker
清華大學鏡像網源:wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repojson
[root@C7-1 yum.repos.d]#vim docker-ce.repovim
%s@https://download.docker.com/@https://mirrors.tuna.tsinghua.edu.cn/docker-ce/@g # 下載後是docker的官方源,修改成清華大學源後端
yum install docker-ce # 安裝
docker cn
阿里雲加速器
中國科技大學
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
[root@C7-1 ~]#mkdir /etc/docker
[root@C7-1 ~]#vim /etc/docker/daemon.json
docker version
docker info
docker search:搜索
[root@C7-1 ~]#docker pull quay.io/coreos/flannel:v0.11.0-arm64
[root@C7-1 ~]#docker image pull nginx:1.14-alpine # 下載鏡像
[root@C7-1 ~]#docker image ls # 查看下載的鏡像
-t:打開tty終端
-i:交互式
--name:名字
--network:網絡
--rm :中止容器後直接刪除
-d --detach:後臺
-a --author string:做者
-c --change list:修改原有基礎鏡像的指令
-p --pause:現將容器暫停
-u,--username 用戶名 registry.cn-hangzhou.aliyuncs.com 後即可以跟服務器地址
-o:名字
[root@C7-1 ~]#docker inspect web1
[root@C7-1 ~]#docker pull busybox # 下載 [root@C7-1 ~]#docker image pull nginx:1.14-alpine [root@C7-1 ~]#docker container run --name b1 -it busybox:latest # latest是標籤 [root@C7-1 ~]#docker container run --name web1 -d nginx:1.14-alpine # 後臺運行 [root@C7-1 ~]#docker container run --name kvstor1 -d redis:4-alpine # 若是沒有則會從網絡中下載 [root@C7-1 ~]#docker container exec -it kvstor1 /bin/sh # 進入容器的終端
Aufs(advanced multi-layered unfication filesystem):高級多層統一文件系統,Aufs是以前UnionFS的從新實現,由Junjiro Okajima開發
Storage:如今Centos7使用的就只這種文件系統,overlay2須要創建在也已經用的文件系統上,因此在Cetno7中,前端使用overlay2後端使用xfs
由某特定的docker鏡像的全部迭代版本組成的鏡像倉庫
每一個倉庫明能夠包含多個tag,每一個tag對應一個鏡像,每一個鏡像能夠對應多個tag
dockerfile
基於容器製做
Docker Hub automated builds
[root@C7-1 ~]#docker run --name b1 -it busybox # 製做一個容器 / # mkdir -p /data/html # 建立目錄 / # echo "<h1>busybox httpd server.</h1>" > /data/html/index.html # 建立主頁文件 # 再開一個終端,應爲若是退出的話容器就會中止 [root@C7-1 ~]#docker commit -p b1 # -p暫停容器 [root@C7-1 ~]#docker image ls # 查看 REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 7cfd827c15d4 6 seconds ago 1.2MB [root@C7-1 ~]#docker tag 7cfd827c15d4 p-pp/busybox_httpd:v0.1-1 # 打標籤 [root@C7-1 ~]#docker image ls # 打完標籤後查看 REPOSITORY TAG IMAGE ID CREATED SIZE p-pp/busybox_httpd v0.1-1 7cfd827c15d4 2 minutes ago 1.2MB [root@C7-1 ~]#docker tag p-pp/busybox_httpd:v0.1-1 p-pp/busybox_httpd:latest # 打一個新的標籤 [root@C7-1 ~]#docker image ls # 再次查看,能夠看到兩個,Id是同樣的 REPOSITORY TAG IMAGE ID CREATED SIZE p-pp/busybox_httpd latest 7cfd827c15d4 4 minutes ago 1.2MB p-pp/busybox_httpd v0.1-1 7cfd827c15d4 4 minutes ago 1.2MB [root@C7-1 ~]#docker commit -a "Mrxuan<www.p-pp.cn>" -c 'CMD [ "/bin/httpd","-f","-h","/data/html" ]' -p b1 p-pp/busybox_httpd:v0.2-1 [root@C7-1 ~]#docker run --name p2 p-pp/busybox_httpd:v0.2-1 # 再打開一個終端,使用命令查看ip [root@C7-1 ~]#docker inspect p2 "Gateway": "172.17.0.1", "IPAddress": "172.17.0.3", [root@C7-1 ~]#curl 172.17.0.3 <h1>busybox httpd server.</h1>
將本身的docker鏡像保存至dockerhub:docker push
[root@C7-1 ~]#docker login -u dong9205 #登陸,用戶名爲dong9205 Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded # 登陸成功的提示 [root@C7-1 ~]#docker image ls # 名字要和建立的倉庫名一致 REPOSITORY TAG IMAGE ID CREATED SIZE dong9205/busybox v0.2-1 8f6be032912d 31 minutes ago 1.2MB dong9205/busybox v0.1-1 7cfd827c15d4 About an hour ago 1.2MB [root@C7-1 ~]#docker push dong9205/busybox # 像dockerhub推送
註冊阿里雲帳號,以後打開網站:https://cr.console.aliyun.com,或https://dev.aliyun.com
[root@C7-1 ~]#docker tag dong9205/busybox:v0.2-1 registry.cn-hangzhou.aliyuncs.com/dong9205/busybox:v0.2-1 #標籤更改一致 [root@C7-1 ~]#docker logout # 退出dockerhub的帳號 [root@C7-1 ~]#docker login --username=socket軒 registry.cn-hangzhou.aliyuncs.com # 登陸,密碼爲單獨設置的密碼 Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@C7-1 ~]#docker push registry.cn-hangzhou.aliyuncs.com/dong9205/busybox # 推送
[root@C7-1 ~]#docker save -o myimages.gz dong9205/busybox:v0.2-1 dong9205/busybox:v0.1-1 [root@C7-1 ~]#docker load -i myimages.gz