docker学习(一) 使用和保存新镜像
最近工作中需要解决离线词表生产环境的一些稳定性问题,调研了一些工具后发现docker在环境迁移上非常实用,因此简单学习了一下docker的使用,在此记录一下。
阅读本文之前,请确认docker已经安装完毕,并且设置了正确的远程仓库,如果还没有完成,请先阅读 Docker安装。
1.搜索镜像
>> docker search contos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 4782 [OK]
ansible/centos7-ansible Ansible on Centos7 118 [OK]
jdeathe/centos-ssh CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x86… 99 [OK]
consol/centos-xfce-vnc Centos container with "headless" VNC session… 64 [OK]
imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 46 [OK]
- 下载镜像
>> docker pull centos
Using default tag: latest
latest: Pulling from library/centos
256b176beaff: Pull complete
Digest: sha256:6f6d986d425aeabdc3a02cb61c02abb2e78e57357e92417d6d58332856024faf
Status: Downloaded newer image for centos:latest
-
使用镜像
>> docker run centos -
查看本地镜像
>> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5182e96772bf 2 months ago 200MB
-
为新镜像创建容器
>> docker run -t -i centos /bin/bash
在这个可交互环境中创建一个/home/hello.sh
文件,用于测试。 -
保存修改后的镜像
查看运行中的容器
>> docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e400eca4994d centos "/bin/bash" 54 seconds ago Up 54 seconds vigilant_davinci
提交容器
>> docker commit e400eca4994d centos1
查看镜像
>> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos1 latest c3a2601d7725 4 seconds ago 200MB
centos latest 5182e96772bf 2 months ago 200MB
现在使用镜像centos1就是修改后的镜像了。
>>docker run -i -t centos1 /bin/bash