Docker Hub地址:https://hub.docker.com
Docker Hub 存放着 Docker 及其组件的所有资源。Docker Hub 可以帮助你与同事之间协作,并获得功能完整的 Docker。为此,它提供的服务有:
- Docker 镜像主机
- 用户认证
- 自动镜像构建和工作流程工具,如构建触发器和 web hooks
- 整合了 GitHub 和 BitBucket
常用的命令和功能记录:
1.docker search http //查询镜像 ,http为镜像名称2.docker pull http //下载镜像3.docker images ls //查看本地所有存在的镜像4.docker ps -a //查看本地 开启或未开启的镜像5.docker run http //启动一个镜像6.docker run -t -i http /bin/bash //交互式启动镜像 -t代表伪终端 -i代表标准输入 exit;可以推出容器,默认退出后容器关闭7.docker start http //启动此镜像 stop为停止8.docker run -d http //指定镜像后台运行9. docker exec -t -i http bash //进入容器10.docker export fe523b5ce4e8 >ubuntu.tar //导出容器到本地11.cat ubuntu.tar |ocker import - test/ubuntu:v1.0 //导入容器快照
实例操作:
1.根据镜像创建一个容器
[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhopeful_austin latest b373750484ee About an hour ago 133.3 MBdocker.io/ubuntu 12.04 5b117edd0b76 9 months ago 103.6 MB[root@localhost ~]# docker run -t -i docker.io/ubuntu:12.04root@8b0042551f59:/# ifconfigbash: ifconfig: command not found
2.安装一些命令,然后保存我更新后的镜像,并根据保存的新镜像进入查看是否存在我安装的命令
root@8b0042551f59:/# apt-get updateroot@8b0042551f59:/# apt-get install net-toolsroot@8b0042551f59:/# ifconfigeth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:03 inet addr:172.17.0.3 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::42:acff:fe11:3/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5311 errors:0 dropped:0 overruns:0 frame:0 TX packets:3419 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:29054244 (29.0 MB) TX bytes:241320 (241.3 KB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)root@8b0042551f59:/# exitexit[root@localhost ~]# docker commit -m="install ifconfig" -a="quanl" 8b0042551f59 quanl/unbuntu:v9sha256:15590c143fcc9d5c7d5692fdb9df2e4ff134cd124b78cbad348ac53027382f2c[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEquanl/unbuntu v9 15590c143fcc 38 seconds ago 133.1 MBhopeful_austin latest b373750484ee About an hour ago 133.3 MBdocker.io/ubuntu 12.04 5b117edd0b76 9 months ago 103.6 MB[root@localhost ~]#[root@localhost ~]# docker run -t -i quanl/unbuntu:v9 bashroot@9a51a8960a80:/#root@9a51a8960a80:/#root@9a51a8960a80:/# ifconfigeth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:03 inet addr:172.17.0.3 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::42:acff:fe11:3/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:6 errors:0 dropped:0 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:508 (508.0 B) TX bytes:508 (508.0 B)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
3.将保存后的镜像传到docker hub上备份
[root@localhost ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9a51a8960a80 quanl/unbuntu:v9 "bash" 4 minutes ago Exited (127) 8 seconds ago cranky_wright8b0042551f59 docker.io/ubuntu:12.04 "/bin/bash" 11 minutes ago Exited (0) 8 minutes ago awesome_golick117094955ea2 ubuntu:12.04 "/bin/bash" About an hour ago Up 14 minutes hopeful_austin[root@localhost ~]# docker push quanl/unbuntu:v9The push refers to a repository [docker.io/quanl/unbuntu]eac11db21faf: Pushed3efd1f7c01f6: Mounted from quanl/ubuntu73b4683e66e8: Mounted from quanl/ubuntuee60293db08f: Mounted from quanl/ubuntu9dc188d975fd: Mounted from quanl/ubuntu58bcc73dcf40: Mounted from quanl/ubuntuv9: digest: sha256:a5a64a1eb2a5f14841c09f2ee51405905c4051fe7f34363558a6765ac8c48ac7 size: 1571[root@localhost ~]#
4.删除本地镜像,查找我docker hub上的的镜像并下载
[root@localhost ~]# docker rmi quanl/unbuntu:v9Error response from daemon: conflict: unable to remove repository reference "quanl/unbuntu:v9" (must force) - container 9a51a8960a80 is using its referenced image 15590c143fcc[root@localhost ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9a51a8960a80 quanl/unbuntu:v9 "bash" 9 minutes ago Exited (127) 5 minutes ago cranky_wright8b0042551f59 docker.io/ubuntu:12.04 "/bin/bash" 16 minutes ago Exited (0) 12 minutes ago awesome_golick117094955ea2 ubuntu:12.04 "/bin/bash" About an hour ago Up 18 minutes hopeful_austin[root@localhost ~]# docker rm 9a51a8960a809a51a8960a80[root@localhost ~]# docker rmi quanl/unbuntu:v9Untagged: quanl/unbuntu:v9Untagged: quanl/unbuntu@sha256:a5a64a1eb2a5f14841c09f2ee51405905c4051fe7f34363558a6765ac8c48ac7Deleted: sha256:15590c143fcc9d5c7d5692fdb9df2e4ff134cd124b78cbad348ac53027382f2cDeleted: sha256:576eb2435ca331eb55e1fe63df789d38be6c058184e0bc249cf20a14d5235ca5[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhopeful_austin latest b373750484ee About an hour ago 133.3 MBdocker.io/ubuntu 12.04 5b117edd0b76 9 months ago 103.6 MB[root@localhost ~]# docker search quanl/unbuntu:v9INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATEDdocker.io docker.io/quanlong/ck-vpn IKEv2 VPN Server for iOS/OSX with zero config 4 [OK]docker.io docker.io/quanlong/coreos-pxe-installer Bootstrap CoreOS cluster via PXE in seconds 1 [OK]docker.io docker.io/quanlong/gitlab-runner gitlab-ci-multi-runner with automated regi... 1docker.io docker.io/ntworld/quanly-node-base Base image for nodes in QuanLy project 0 [OK]docker.io docker.io/quanl/test pull rom docker images 0docker.io docker.io/quanlin/docker-whale 0docker.io docker.io/quanlin/node-web-app 0docker.io docker.io/quanlong/ckdots Manage dotfiles across all your devices, e... 0 [OK]docker.io docker.io/quanlong/worktile-events-to-slack 0 [OK][root@localhost ~]# docker pull quanl/unbuntu:v9Trying to pull repository docker.io/quanl/unbuntu ...v9: Pulling from docker.io/quanl/unbuntu396e9d6ee8c9: Already exists403b0fc2e6f1: Already exists7124ef1a91d2: Already existsf47441d15565: Already exists588e8920e707: Already existsedadee58a8ba: Downloading [===========================> ] 15.62 MB/28.71 MB
挂载数据目录:
[root@localhost ~]# docker run --name=liuquan --privileged=true -it -v /letv:/letv docker.io/quanl/unbuntu:v9 /bin/bashroot@9c3348840322:/# df -hFilesystem Size Used Avail Use% Mounted onrootfs 10G 161M 9.9G 2% //dev/mapper/docker-253:0-244534-c98505094cc27e988de9eeba4644966f8986a88e95039f47f71640e71c5092bf 10G 161M 9.9G 2% /tmpfs 12G 0 12G 0% /devtmpfs 12G 0 12G 0% /sys/fs/cgroup/dev/sdb 8.1T 4.1T 4.1T 51% /letv/dev/mapper/cl-root 50G 1.5G 49G 3% /etc/resolv.conf/dev/mapper/cl-root 50G 1.5G 49G 3% /etc/hostname/dev/mapper/cl-root 50G 1.5G 49G 3% /etc/hostsshm 64M 0 64M 0% /dev/shm/dev/mapper/cl-root 50G 1.5G 49G 3% /run/secretsroot@9c3348840322:/#root@9c3348840322:/#root@9c3348840322:/#root@9c3348840322:/# exitexit[root@localhost ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9c3348840322 docker.io/quanl/unbuntu:v9 "/bin/bash" 17 seconds ago Exited (0) 4 seconds ago liuquan286a6354107b docker.io/quanl/unbuntu:v9 "/bin/bash" 45 seconds ago Exited (0) 27 seconds ago desperate_shirleycf9e2a661fa6 docker.io/quanl/unbuntu:v9 "--privileged=ture /b" 4 minutes ago Created sad_bardeen48993aefdbcb docker.io/quanl/unbuntu:v9 "/bin/bash --privileg" 4 minutes ago Exited (2) 4 minutes ago admiring_shockley5795128d9e04 docker.io/quanl/unbuntu:v9 "/bin/bash --privileg" 5 minutes ago Exited (2) 5 minutes ago rom1231e3bf90ce70e docker.io/quanl/unbuntu:v9 "/bin/bash" 6 minutes ago Exited (0) 6 minutes ago rom9a129171fa6e docker.io/quanl/unbuntu:v9 "/bin/bash" 7 minutes ago Exited (1) 6 minutes ago boring_fermat0abcc43d34c9 docker.io/quanl/unbuntu:v9 "/bin/bash" 8 minutes ago Exited (1) 7 minutes ago sharp_shannon8b0042551f59 docker.io/ubuntu:12.04 "/bin/bash" 46 minutes ago Exited (0) 42 minutes ago awesome_golick117094955ea2 ubuntu:12.04 "/bin/bash" 2 hours ago Up 48 minutes hopeful_austin[root@localhost ~]# docker start liuquanliuquan[root@localhost ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9c3348840322 docker.io/quanl/unbuntu:v9 "/bin/bash" 32 seconds ago Up 5 seconds liuquan286a6354107b docker.io/quanl/unbuntu:v9 "/bin/bash" About a minute ago Exited (0) 42 seconds ago desperate_shirleycf9e2a661fa6 docker.io/quanl/unbuntu:v9 "--privileged=ture /b" 4 minutes ago Created sad_bardeen48993aefdbcb docker.io/quanl/unbuntu:v9 "/bin/bash --privileg" 5 minutes ago Exited (2) 5 minutes ago admiring_shockley5795128d9e04 docker.io/quanl/unbuntu:v9 "/bin/bash --privileg" 5 minutes ago Exited (2) 5 minutes ago rom1231e3bf90ce70e docker.io/quanl/unbuntu:v9 "/bin/bash" 6 minutes ago Exited (0) 6 minutes ago rom9a129171fa6e docker.io/quanl/unbuntu:v9 "/bin/bash" 7 minutes ago Exited (1) 6 minutes ago boring_fermat0abcc43d34c9 docker.io/quanl/unbuntu:v9 "/bin/bash" 9 minutes ago Exited (1) 7 minutes ago sharp_shannon8b0042551f59 docker.io/ubuntu:12.04 "/bin/bash" 46 minutes ago Exited (0) 43 minutes ago awesome_golick117094955ea2 ubuntu:12.04 "/bin/bash" 2 hours ago Up 49 minutes hopeful_austin[root@localhost ~]# docker exec -ti 9c3348840322 bash
设置ssh登录docker
[root@localhost ~]# docker run -ti -p2022:22 --name="ubuntu_rom" --privileged=true -v /letv/Android/:/letv/Android/ yeming_rom /bin/bash关闭宿主机的selinux 和 iptables 即可登录到docker系统内
ubuntu系统安装后没有ifconfig和ping命令解决:
apt-get install net-toolsapt-get install iputils-ping