关于docker 基础使用记录
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 images
REPOSITORY TAG IMAGE ID CREATED SIZE
hopeful_austin latest b373750484ee About an hour ago 133.3 MB
docker.io/ubuntu 12.04 5b117edd0b76 9 months ago 103.6 MB
[root@localhost ~]# docker run -t -i docker.io/ubuntu:12.04
root@8b0042551f59:/# ifconfig
bash: ifconfig: command not found
2.安装一些命令,然后保存我更新后的镜像,并根据保存的新镜像进入查看是否存在我安装的命令
root@8b0042551f59:/# apt-get update
root@8b0042551f59:/# apt-get install net-tools
root@8b0042551f59:/# ifconfig
eth0 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:/# exit
exit
[root@localhost ~]# docker commit -m="install ifconfig" -a="quanl" 8b0042551f59 quanl/unbuntu:v9
sha256:15590c143fcc9d5c7d5692fdb9df2e4ff134cd124b78cbad348ac53027382f2c
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
quanl/unbuntu v9 15590c143fcc 38 seconds ago 133.1 MB
hopeful_austin latest b373750484ee About an hour ago 133.3 MB
docker.io/ubuntu 12.04 5b117edd0b76 9 months ago 103.6 MB
[root@localhost ~]#
[root@localhost ~]# docker run -t -i quanl/unbuntu:v9 bash
root@9a51a8960a80:/#
root@9a51a8960a80:/#
root@9a51a8960a80:/# ifconfig
eth0 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 -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a51a8960a80 quanl/unbuntu:v9 "bash" 4 minutes ago Exited (127) 8 seconds ago cranky_wright
8b0042551f59 docker.io/ubuntu:12.04 "/bin/bash" 11 minutes ago Exited (0) 8 minutes ago awesome_golick
117094955ea2 ubuntu:12.04 "/bin/bash" About an hour ago Up 14 minutes hopeful_austin
[root@localhost ~]# docker push quanl/unbuntu:v9
The push refers to a repository [docker.io/quanl/unbuntu]
eac11db21faf: Pushed
3efd1f7c01f6: Mounted from quanl/ubuntu
73b4683e66e8: Mounted from quanl/ubuntu
ee60293db08f: Mounted from quanl/ubuntu
9dc188d975fd: Mounted from quanl/ubuntu
58bcc73dcf40: Mounted from quanl/ubuntu
v9: digest: sha256:a5a64a1eb2a5f14841c09f2ee51405905c4051fe7f34363558a6765ac8c48ac7 size: 1571
[root@localhost ~]#
4.删除本地镜像,查找我docker hub上的的镜像并下载
[root@localhost ~]# docker rmi quanl/unbuntu:v9
Error 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 -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a51a8960a80 quanl/unbuntu:v9 "bash" 9 minutes ago Exited (127) 5 minutes ago cranky_wright
8b0042551f59 docker.io/ubuntu:12.04 "/bin/bash" 16 minutes ago Exited (0) 12 minutes ago awesome_golick
117094955ea2 ubuntu:12.04 "/bin/bash" About an hour ago Up 18 minutes hopeful_austin
[root@localhost ~]# docker rm 9a51a8960a80
9a51a8960a80
[root@localhost ~]# docker rmi quanl/unbuntu:v9
Untagged: quanl/unbuntu:v9
Untagged: quanl/unbuntu@sha256:a5a64a1eb2a5f14841c09f2ee51405905c4051fe7f34363558a6765ac8c48ac7
Deleted: sha256:15590c143fcc9d5c7d5692fdb9df2e4ff134cd124b78cbad348ac53027382f2c
Deleted: sha256:576eb2435ca331eb55e1fe63df789d38be6c058184e0bc249cf20a14d5235ca5
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hopeful_austin latest b373750484ee About an hour ago 133.3 MB
docker.io/ubuntu 12.04 5b117edd0b76 9 months ago 103.6 MB
[root@localhost ~]# docker search quanl/unbuntu:v9
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.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... 1
docker.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 0
docker.io docker.io/quanlin/docker-whale 0
docker.io docker.io/quanlin/node-web-app 0
docker.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:v9
Trying to pull repository docker.io/quanl/unbuntu ...
v9: Pulling from docker.io/quanl/unbuntu
396e9d6ee8c9: Already exists
403b0fc2e6f1: Already exists
7124ef1a91d2: Already exists
f47441d15565: Already exists
588e8920e707: Already exists
edadee58a8ba: 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/bash
root@9c3348840322:/# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 10G 161M 9.9G 2% /
/dev/mapper/docker-253:0-244534-c98505094cc27e988de9eeba4644966f8986a88e95039f47f71640e71c5092bf 10G 161M 9.9G 2% /
tmpfs 12G 0 12G 0% /dev
tmpfs 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/hosts
shm 64M 0 64M 0% /dev/shm
/dev/mapper/cl-root 50G 1.5G 49G 3% /run/secrets
root@9c3348840322:/#
root@9c3348840322:/#
root@9c3348840322:/#
root@9c3348840322:/# exit
exit
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9c3348840322 docker.io/quanl/unbuntu:v9 "/bin/bash" 17 seconds ago Exited (0) 4 seconds ago liuquan
286a6354107b docker.io/quanl/unbuntu:v9 "/bin/bash" 45 seconds ago Exited (0) 27 seconds ago desperate_shirley
cf9e2a661fa6 docker.io/quanl/unbuntu:v9 "--privileged=ture /b" 4 minutes ago Created sad_bardeen
48993aefdbcb docker.io/quanl/unbuntu:v9 "/bin/bash --privileg" 4 minutes ago Exited (2) 4 minutes ago admiring_shockley
5795128d9e04 docker.io/quanl/unbuntu:v9 "/bin/bash --privileg" 5 minutes ago Exited (2) 5 minutes ago rom123
1e3bf90ce70e docker.io/quanl/unbuntu:v9 "/bin/bash" 6 minutes ago Exited (0) 6 minutes ago rom
9a129171fa6e docker.io/quanl/unbuntu:v9 "/bin/bash" 7 minutes ago Exited (1) 6 minutes ago boring_fermat
0abcc43d34c9 docker.io/quanl/unbuntu:v9 "/bin/bash" 8 minutes ago Exited (1) 7 minutes ago sharp_shannon
8b0042551f59 docker.io/ubuntu:12.04 "/bin/bash" 46 minutes ago Exited (0) 42 minutes ago awesome_golick
117094955ea2 ubuntu:12.04 "/bin/bash" 2 hours ago Up 48 minutes hopeful_austin
[root@localhost ~]# docker start liuquan
liuquan
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9c3348840322 docker.io/quanl/unbuntu:v9 "/bin/bash" 32 seconds ago Up 5 seconds liuquan
286a6354107b docker.io/quanl/unbuntu:v9 "/bin/bash" About a minute ago Exited (0) 42 seconds ago desperate_shirley
cf9e2a661fa6 docker.io/quanl/unbuntu:v9 "--privileged=ture /b" 4 minutes ago Created sad_bardeen
48993aefdbcb docker.io/quanl/unbuntu:v9 "/bin/bash --privileg" 5 minutes ago Exited (2) 5 minutes ago admiring_shockley
5795128d9e04 docker.io/quanl/unbuntu:v9 "/bin/bash --privileg" 5 minutes ago Exited (2) 5 minutes ago rom123
1e3bf90ce70e docker.io/quanl/unbuntu:v9 "/bin/bash" 6 minutes ago Exited (0) 6 minutes ago rom
9a129171fa6e docker.io/quanl/unbuntu:v9 "/bin/bash" 7 minutes ago Exited (1) 6 minutes ago boring_fermat
0abcc43d34c9 docker.io/quanl/unbuntu:v9 "/bin/bash" 9 minutes ago Exited (1) 7 minutes ago sharp_shannon
8b0042551f59 docker.io/ubuntu:12.04 "/bin/bash" 46 minutes ago Exited (0) 43 minutes ago awesome_golick
117094955ea2 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-tools
apt-get install iputils-ping
关于docker 基础使用记录的更多相关文章
- Docker 基础技术之 Linux cgroups 详解
PS:欢迎大家关注我的公众号:aCloudDeveloper,专注技术分享,努力打造干货分享平台,二维码在文末可以扫,谢谢大家. 推荐大家到公众号阅读,那里阅读体验更好,也沉淀了很多篇干货. 前面两篇 ...
- 【补充】docker基础学习
docker 基础知识 之前写了一篇docker未授权访问的文章,现在来补充一下docker基础知识,以便更好的学习docker上的漏洞. docker是一款轻量级的虚拟化的产品,它属于层级化的架构. ...
- Linux - docker基础
目录 Linux - docker基础 docker的概念 docker安装流程 docker基本命令学习 docker 的 hello docker 运行一个ubuntu容器 Docker与Cent ...
- Docker基础与实战,看这一篇就够了
docker 基础 什么是Docker Docker 使用 Google 公司推出的 Go 语言 进行开发实现,基于 Linux 内核的 cgroup,namespace,以及 AUFS 类的 Uni ...
- 庐山真面目之九微服务架构 NetCore 基于 Docker 基础镜像和挂载文件部署
庐山真面目之九微服务架构 NetCore 基于 Docker 基础镜像和挂载文件部署 一.简介 我们在上一篇文章<庐山真面目之八微服务架构 NetCore 基于 Dockerfile ...
- docker基础命令,常用操作
docker基础命令 使用docker镜像 获取镜像 从docker registry获取镜像的命令是docker pull.命令格式是: docker pull [选项][docker regist ...
- C#基础知识记录一
C#基础知识记录一 static void Main(string[] args) { #region 合并运算符的使用(合并运算符??) 更多运算符请参考:https://msdn.microsof ...
- Docker - Docker基础命令及使用
Docker Docker - 官网 Docker - Hub GitHub - Docker Docker中文社区 Docker基础命令 Docker 查看帮助信息:docker --help 查看 ...
- 【云计算】Docker云平台—Docker基础
Docker云平台系列共三讲,此为第一讲:Docker基础 参考资料: Docker官方文档:https://docs.docker.com/ Docker从入门到实践:https://yeasy.g ...
随机推荐
- 学习笔记 - 中国剩余定理&扩展中国剩余定理
中国剩余定理&扩展中国剩余定理 NOIP考完回机房填坑 ◌ 中国剩余定理 处理一类相较扩展中国剩余定理更特殊的问题: 在这里要求 对于任意i,j(i≠j),gcd(mi,mj)=1 (就是互素 ...
- YouCompleteMe
需要配套的.vimrc :sw:.h与.cpp切换 Issue:YouCompleteMe unavailable no module named future cd .vim/Vundle/YouC ...
- obfuscator-llvm Xcode集成配置
一.简介 obfuscator-llvm 是一个开源的代码混淆编译器,能够使编译出来的文件添加垃圾代码和各种跳转流程,给逆向分析者增加难度. 二.编译 (1) 下载 目前最新版的是4.0的,下载地址是 ...
- HTML5中的拖拽与拖放(drag&&drop)
1.drag 当拖动某个元素时,将会依次触发下列事件: 1)dragstart:按下鼠标键并开始移动鼠标时,会触发该事件 2)drag:dragstart触发后,随即便触发drag事件,而且在元素被拖 ...
- 2.1 摄像头V4L2驱动框架分析
学习目标:学习V4L2(V4L2:vidio for linux version 2)摄像头驱动框架,分析vivi.c(虚拟视频硬件相关)驱动源码程序,总结V4L2硬件相关的驱动的步骤: 一.V4L ...
- inotify和epoll
参考EventHub.cpp 1.初始化inotify int mINotifyFd = inotify_init(); 2.将要监测的目录添加到inotify int result = inotif ...
- Hangfire初探
Hangfire 是什么? Hangfire 是一个定时任务的管理后台,它拥有定时任务功能和及其相关的管理后台界面.Hangfire 原生使用 .NET 开发的,同时支持 .NET 和 .NET Co ...
- 在CentOS7中搭建Zookeeper集群
前几天装了CentOS7.并安装了一些基本的工具,现在我手上有三台机器:分别是master,slave1,slave2. 今天我将搭建zookeeper,使用的版本是zookeeper-3.4.11. ...
- Java中的IO
引言: 对程序语言的设计者来说,创建一个好的输入/输出(I/O)系统是一项艰难的任务 < Thinking in Java > 本文的目录视图如下: Java IO概要 a ...
- vue中cssModules理解可以用于加密和避免重复使用
cssModules可以用于加密和避免重复使用,也就是说可以在当前vue文件中写的样式会生成独一无二的名字,在其他vue文件中是无法调用的, 一.可以直接配cssModules 第一步,配置vue-l ...