docker安装、镜像管理、创建镜像、导入导出镜像
2020-03-13 07:41
676 查看
文章目录
Centos7安装docker
下载阿里云提供的docker yum源:
[root@linux01 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装docker社区版(免费版):
[root@linux01 ~]# yum -y install docker-ce
启动docker服务:
[root@linux01 ~]# systemctl start docker
查看docker版本信息:
docker version
配置docker加速器
配置加速器可以提升获取Docker官方镜像的速度,创建配置文件:
[root@linux01 ~]# vi /etc/docker/daemon.json
配置文件内容:
{ "registry-mirrors": ["https://jmnbijcd.mirror.aliyuncs.com"] }
#该url为加速器地址,需要自行到阿里云—>容器镜像服务—>加速器获取
重启docker服务:
[root@linux01 ~]# systemctl restart docker
镜像管理
下载docker官方仓库的centos镜像:
[root@linux01 ~]# docker pull centos
查看本地的镜像:
[root@linux01 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 0f3e07c0138f 3 months ago 220MB
#从左到右分别为镜像名、标签、镜像id、创建时间、大小
根据镜像名称搜索镜像:
[root@linux01 ~]# docker search ubuntu
更改镜像名:
[root@linux01 ~]# docker tag centos test [root@linux01 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 0f3e07c0138f 3 months ago 220MBtest latest 0f3e07c0138f 3 months ago 220MB
#更改镜像名centos为test,会产生一个id相同但镜像名不相同的镜像
更改镜像名并更改标签:
[root@linux01 ~]# docker tag test abc:abc [root@linux01 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE test latest 0f3e07c0138f 3 months ago 220MB abc abc 0f3e07c0138f 3 months ago 220MB centos latest 0f3e07c0138f 3 months ago 220MB
启动镜像:
[root@linux01 ~]# docker run -itd centos af57114ec8a10c96b6301de65fb6d6e30a61fee19ef48676a15d736e83628264
#镜像启动后就变成了容器,-i表示让容器的标准输入打开,-t表示分配一个伪终端,-d表示后台启动,要把-i -t -d 放到镜像名字前面
查看正在运行的容器:
[root@linux01 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES af57114ec8a1 centos "/bin/bash" 4 minutes ago Up 4 minutes charming_mclaren
#docker ps -a可以查看所有容器(包括未运行的)
删除指定镜像:
[root@linux01 ~]# docker rmi test
当镜像标签不是latest时,需要指定镜像名以及标签才可删除:
[root@linux01 ~]# docker rmi abc:abc
#如果指定的是镜像id而非镜像名时,所有该id的镜像都会被删除
通过容器创建镜像
使用docker run启动镜像后,即可指定容器id进入容器:
[root@linux01 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES af57114ec8a1 centos "/bin/bash" 12 minutes ago Up 12 minutes charming_mclaren [root@linux01 ~]# docker exec -it af57114ec8a1 bash [root@af57114ec8a1 /]#
在容器中安装任意服务后退出:
[root@af57114ec8a1 /]# yum -y install net-tools [root@af57114ec8a1 /]# exit [root@linux01 ~]#
将变更后的容器创建镜像:
[root@linux01 ~]# docker commit -m "add net-tools" -a "root" af57114ec8a1 centos_net sha256:f9dba795f88479c70133e18145ad5337c3199fe633523009a2bb84febf58d695 [root@linux01 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos_net latest f9dba795f884 8 seconds ago 261MB centos latest 0f3e07c0138f 3 months ago 220MB
#新的镜像创建成功,这个命令类似git、svn的提交,-m参数添加描述,-a参数指定操作者或是作者 af57114ec8a1这一串为容器id(通过docker ps获取),再后面为新镜像的名字
导入导出镜像
导出镜像:
[root@linux01 ~]# docker save -o centos_net.tar centos_net
#将centos_net镜像导出为.tar文件
删除centos_net镜像:
[root@linux01 ~]# docker rmi centos_net [root@linux01 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 0f3e07c0138f 3 months ago 220MB
导入镜像:
[root@linux01 ~]# docker load < centos_net.tar 45a8968b6423: Loading layer [==================================================>] 41.4MB/41.4MB Loaded image: centos_net:latest
#导入镜像的第二种方式:
docker load --input centos_net.tar
查看镜像是否导入成功:
[root@linux01 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos_net latest f9dba795f884 31 minutes ago 261MB centos latest 0f3e07c0138f 3 months ago 220MB
- 点赞 2
- 收藏
- 分享
- 文章举报
相关文章推荐
- (1)docker安装、镜像管理-导入导出
- docker导入导出已经安装好javaWeb镜像
- docker离线安装及镜像导入导出
- 运维之我的docker-镜像的管理和导入导出
- docker实战1 (docker-toolbox的安装,docker基础命令详解[运行,容器导入/导出,镜像导入/导出,数据卷,网络],构建100个docker实例的测试环境)
- Docker系列(二)镜像下载、操作容器、镜像导入导出等操作
- Docker镜像导出与导入与拷贝实例分析
- Docker的安装和镜像管理并利用Docker容器实现nginx的负载均衡、动静分离
- docker 私有镜像管理工具harbor 安装
- 有关oracle遇到日期显示问题,导入导出,安装,卸载,修改listener配置文件,创建用户和表空间等的部分问题.
- Docker的安装和镜像创建
- Docker微服务-镜像构建交付和使用Rancher进行容器创建管理
- docker(四):Mac docker 把war包导入tomcat创建新的镜像
- docker镜像文件导入与导出
- 在节点之间导出和导入 DOCKER 镜像
- 【系列3】使用Dockerfile创建yum安装nginx服务的Centos Docker镜像
- docker镜像文件导入与导出,支持批量
- Docker镜像导入导出
- Windows10下的docker安装与入门 (三) 创建自己的docker镜像并且在容器中运行它
- Docker之提交容器为镜像(导出镜像和导入镜像)和端口映射