docker安裝
windows安裝在另一篇隨筆
centos安裝
# 更改centos7默認的yum源,使用清華鏡像
cd /etc/yum.repos.d wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
#
yum -y install vim vim docker-ce.repo :%s@https://download.docker.com/@https://mirrors.tuna.tsinghua.edu.cn/docker-ce/@ yum repolist yum -y install docker-ce
當我們安裝好docker后,默認主配置文件沒有生成 # /etc/docker/daemon.json mkdir /etc/docker vim /etc/docker/daemon.json
{ "registry-mirrors": ["https://registry.docker-cn.com","https://duado9su.mirror.aliyuncs.com"] }
# 鏡像服務器 $ docker run -d -p 5000:5000 \ -e STANDALONE=false \ -e MIRROR_SOURCE=https://registry-1.docker.io \ -e MIRROR_SOURCE_INDEX=https://index.docker.io \ registry # 國內 docker --registry-mirror=http://服務端ip地址:5000 -d
systemctl start docker.service
[root@localhost vagrant]# docker Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: builder Manage builds config Manage Docker configs container Manage containers engine Manage the docker engine image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumes Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information
[root@localhost vagrant]# docker info Containers: 4 Running: 0 Paused: 0 Stopped: 4 Images: 5 Server Version: 18.09.0 Storage Driver: devicemapper # 分層構建,聯合掛載,必須建立在特殊的文件系統 Pool Name: docker-253:0-33789307-pool Pool Blocksize: 65.54kB Base Device Size: 10.74GB Backing Filesystem: xfs Udev Sync Supported: true Data file: /dev/loop0 Metadata file: /dev/loop1 Data loop file: /var/lib/docker/devicemapper/devicemapper/data Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata Data Space Used: 246.8MB Data Space Total: 107.4GB Data Space Available: 6.727GB Metadata Space Used: 995.3kB Metadata Space Total: 2.147GB Metadata Space Available: 2.146GB Thin Pool Minimum Free Space: 10.74GB Deferred Removal Enabled: true Deferred Deletion Enabled: true Deferred Deleted Device Count: 0 Library Version: 1.02.107-RHEL7 (2015-10-14) Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: c4446665cb9c30056f4998ed953e6d4ff22c7c39 runc version: 4fc53a81fb7c994640722ac585fa9ca548971871 init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 3.10.0-327.4.5.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 615.2MiB Name: localhost.localdomain ID: B2VY:FO47:USXN:LXSE:V6YP:WW44:366C:7LE7:CC7V:HVFC:T3OL:WG6J Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Username: aceq2018 Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://duado9su.mirror.aliyuncs.com/ Live Restore Enabled: false Product License: Community Engine WARNING: bridge-nf-call-iptables is disabled WARNING: bridge-nf-call-ip6tables is disabled WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device. [root@localhost vagrant]#
inspect Return low-level information on Docker objects # 查看某個容器的詳細信息 kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers # 刪除容器 rmi Remove one or more images # 刪除鏡像 run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information
Client: Version: 18.09.0 API version: 1.39 Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:48:22 2018 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.0 API version: 1.39 (minimum version 1.12) Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:19:08 2018 OS/Arch: linux/amd64 Experimental: false
wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command.
docker run -it -i 交互式界面 -t 開啟一個終端
-d 后台
-c 指定shell語法
docker run -d centos /bin/sh -c 'while true;do echo hello;sleep 1 ;done'
依附容器 docker attach
構建容器 docker build
提交容器 docker commit
復制文件至宿主機 docker cp
創建容器 docker create
查看容器變化 docker diff
查看事件 docker events
進入容器 docker exec
導出鏡像 docker export
查看鏡像歷史 docker history
查看本地鏡像 docker images
導入容器 docker import
查看docker信息 docker info
查看詳細信息 docker inspect
殺死容器 docker kill
導入鏡像 docker load
登陸倉庫 docker login
登出倉庫 docker logout
查看容器日志 docker logs
管理網絡 docker network
管理節點 docker node
暫停容器 docker pause
查看容器端口 docker port
查看本地容器 docker ps
拉取鏡像 docker pull
推送鏡像 docker push
容器重命名 docker rename
重啟容器 docker restart
刪除容器 docker rm
刪除鏡像 docker rmi
運行容器 docker run
導出鏡像 docker save
搜索鏡像 docker search
管理服務 docker service
啟動容器 docker start
查看容器狀態 docker status
停止容器 docker stop
管理集群 docker swarm
設置標簽 docker tag
查看容器進程 docker top
恢復暫停容器 docker unpause
更新容器 docker update
查看版本 docker version
管理數據卷 docker volume
設置等待 docker wait


docker鏡像
apline是一個用來構建非常小的鏡像文件的微型發型版,提供基礎運行環境,但缺少調試工具
將來的鏡像可能不會來自docker hub,其中的鏡像可能不會滿足我們的需求,---->自己編織--->私有registry
# docker pull <registry>[:<port>]/[<namespace>/]<name>:<tag> # docker pull quay.io/coreos/flannel:v0.010.0-amd64

docker image pull nginx:1.14-apline # 來下版本為1.14-apline 的 nginx
docker run --name b1 -it busybox docker run --name redis1 -d redis 本地沒有鏡像也不要緊,只要能搜到, docker中運行的程序一定不能運行在后台
啟動容器時,docker damon會試圖從本地獲取相關的鏡像;本地沒有將從registry中下載該鏡像並保存到本地

docker的registry
Repository 由某特定的docker鏡像的所有迭代版本組成的鏡像倉庫 一個registry中可以存在多個repository Repository 可分為頂層倉庫和用戶倉庫 用戶倉庫名稱格式為 用戶名/倉庫名 每個倉庫可以包含多個Tag,每個標簽對應一個鏡像 Index 維護用戶賬戶、鏡像的校驗以及公共命名空間的信息 相當於為registry提供了一個完成用戶認證等功能的檢索接口
Registry用於保存docker鏡像,包括鏡像的層次結構和元數據
用戶可自建registry,也可以使用官方的docker hub
分類
Sponsor registry 第三方的registry ,供客戶和docker社區使用
Mirror Registry 第三方的registry,只讓客戶使用
Vendor registry 由發布Docker鏡像的供應商提供的registry
Private registry 通過設有防火牆和額外的安全層的私有實體提供的registry

docker 的Hub

docker鏡像的制作

Dockerfile 專門制作鏡像的
基於容器制作 commit 會把容器的可寫層單獨創建一個鏡像
Docker Hub automated builds 內部還是調用的dockerfile
基於容器制作



給鏡像添加標簽

刪除標簽 docker image rm aceq2018/bbox:v0.0.1
當我創建完鏡像后,發現默認命令還是基礎鏡像的命令


我們只需要在創建鏡像的時候指定-c參數就可以修改了

推鏡像到docker hub


推到阿里雲,阿里雲控制台有教程,

密碼是單獨設置的

打包保存鏡像


只要拷貝到了那台機器有docker就可以運行
加載鏡像文件

缺陷:run的時候如果沒有鏡像還是到registry拉鏡像,因此必須本地需要提前准備好
