- 启动docker
systemctl start docker
systemctl enable docker 开机自启动
- 查看版本
[root@localhost ~]# docker -v
Docker version 19.03.13, build 4484c46d9d
3.查看服务状态
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2020-11-06 23:13:49 PST; 10s ago
Docs: https://docs.docker.com
Main PID: 1639 (dockerd)
Tasks: 13
Memory: 144.1M
CGroup: /system.slice/docker.service
└─1639 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/cont...
Nov 06 23:13:48 localhost.localdomain dockerd[1639]: time="2020-11-06T23:13:4...
Nov 06 23:13:48 localhost.localdomain dockerd[1639]: time="2020-11-06T23:13:4...
Nov 06 23:13:48 localhost.localdomain dockerd[1639]: time="2020-11-06T23:13:4...
Nov 06 23:13:48 localhost.localdomain dockerd[1639]: time="2020-11-06T23:13:4...
Nov 06 23:13:49 localhost.localdomain dockerd[1639]: time="2020-11-06T23:13:4...
Nov 06 23:13:49 localhost.localdomain dockerd[1639]: time="2020-11-06T23:13:4...
Nov 06 23:13:49 localhost.localdomain dockerd[1639]: time="2020-11-06T23:13:4...
Nov 06 23:13:49 localhost.localdomain dockerd[1639]: time="2020-11-06T23:13:4...
Nov 06 23:13:49 localhost.localdomain dockerd[1639]: time="2020-11-06T23:13:4...
Nov 06 23:13:49 localhost.localdomain systemd[1]: Started Docker Application ...
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#
4.查找镜像
[root@localhost yum.repos.d]# docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 6268 [OK]
ansible/centos7-ansible Ansible on Centos7 132 [OK]
consol/centos-xfce-vnc Centos container with "headless" VNC session… 123 [OK]
jdeathe/centos-ssh OpenSSH / Supervisor / EPEL/IUS/SCL Repos - … 115 [OK]
centos/systemd systemd enabled base container. 86 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 84
imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 58 [OK]
tutum/centos Simple CentOS docker image with SSH access 46
centos/postgresql-96-centos7 PostgreSQL is an advanced Object-Relational … 45
centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or bui… 36
kinogmt/centos-ssh CentOS with SSH 29 [OK]
pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag names… 13
centos/mariadb-101-centos7 MariaDB 10.1 SQL database server 12
drecom/centos-ruby centos ruby 6 [OK]
centos/tools Docker image that has systems administration… 6 [OK]
pivotaldata/centos Base centos, freshened up a little with a Do… 5
pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated wi… 3
darksheer/centos Base Centos Image -- Updated hourly 3 [OK]
pivotaldata/centos-mingw Using the mingw toolchain to cross-compile t… 3
indigo/centos-maven Vanilla CentOS 7 with Oracle Java Developmen… 1 [OK]
blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK]
mcnaughton/centos-base centos base image 1 [OK]
pivotaldata/centos7-dev CentosOS 7 image for GPDB development 0
smartentry/centos centos with smartentry 0 [OK]
pivotaldata/centos6.8-dev CentosOS 6.8 image for GPDB development 0
5.镜像下载
[root@localhost yum.repos.d]# docker pull ansible/centos7-ansible
6.查看镜像
[root@localhost yum.repos.d]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos_installed_net-tools latest 773684bbbd7f 2 hours ago 236MB
centos latest 0d120b6ccaa8 2 months ago 215MB
fan_centos fanqc 0d120b6ccaa8 2 months ago 215MB
ansible/centos7-ansible latest 688353a31fde 3 years ago 447MB
7.更改镜像标签
[root@localhost yum.repos.d]# docker tag ansible/centos7-ansible new_centos7-ansible:new-tag
[root@localhost yum.repos.d]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos_installed_net-tools latest 773684bbbd7f 2 hours ago 236MB
centos latest 0d120b6ccaa8 2 months ago 215MB
fan_centos fanqc 0d120b6ccaa8 2 months ago 215MB
ansible/centos7-ansible latest 688353a31fde 3 years ago 447MB
new_centos7-ansible new-tag 688353a31fde 3 years ago 447MB
8.删除镜像
[root@localhost yum.repos.d]# docker rmi new_centos7-ansible:new-tag
Untagged: new_centos7-ansible:new-tag
[root@localhost yum.repos.d]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos_installed_net-tools latest 773684bbbd7f 2 hours ago 236MB
centos latest 0d120b6ccaa8 2 months ago 215MB
ansible/centos7-ansible latest 688353a31fde 3 years ago 447MB
9.部署镜像,相当于VMware的部署ova,-itd参数, i标准输入 t终端 d后台运行
[root@localhost yum.repos.d]# docker run --name ansible -itd ansible/centos7-ansible
b8c75b3d2115178de0011208924e892f4a5c8c5064917f2874ef65bb8b016cda
11.查看容器,docker ps -a 查看全部开机和未开机的
[root@localhost yum.repos.d]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8c75b3d2115 ansible/centos7-ansible "/bin/bash" About a minute ago Up 58 seconds ansible
2f9e533bfbbd centos_installed_net-tools "bash" 3 hours ago Up 3 hours new_centos
ed028cc2bae6 centos "/bin/bash" 3 hours ago Up 3 hours fan
[root@localhost yum.repos.d]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8c75b3d2115 ansible/centos7-ansible "/bin/bash" 3 minutes ago Up 3 minutes ansible
2f9e533bfbbd centos_installed_net-tools "bash" 3 hours ago Exited (0) 8 seconds ago new_centos
ed028cc2bae6 centos "/bin/bash" 3 hours ago Up 3 hours fan
[root@localhost yum.repos.d]#
12.进入容器
[root@localhost yum.repos.d]# docker exec -it new_centos bash
[root@2f9e533bfbbd /]# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.3 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet)
RX packets 8 bytes 648 (648.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
13.退出容器
[root@2f9e533bfbbd /]# exit
exit
[root@localhost yum.repos.d]#
14.关闭容器
[root@localhost yum.repos.d]# docker stop new_centos
new_centos
[root@localhost yum.repos.d]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8c75b3d2115 ansible/centos7-ansible "/bin/bash" 10 minutes ago Up 10 minutes ansible
ed028cc2bae6 centos "/bin/bash" 3 hours ago Up 3 hours fan
[root@localhost yum.repos.d]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8c75b3d2115 ansible/centos7-ansible "/bin/bash" 10 minutes ago Up 10 minutes ansible
2f9e533bfbbd centos_installed_net-tools "bash" 3 hours ago Exited (0) 12 seconds ago new_centos
ed028cc2bae6 centos "/bin/bash" 3 hours ago Up 3 hours fan
[root@localhost yum.repos.d]#
15.启动容器
[root@localhost yum.repos.d]# docker start new_centos
new_centos
[root@localhost yum.repos.d]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8c75b3d2115 ansible/centos7-ansible "/bin/bash" 13 minutes ago Up 13 minutes ansible
2f9e533bfbbd centos_installed_net-tools "bash" 3 hours ago Up 33 seconds new_centos
ed028cc2bae6 centos "/bin/bash" 3 hours ago Up 3 hours fan
[root@localhost yum.repos.d]#
16.删除容器,一般建议是先停止再删除,也可以运行中强制删除
[root@localhost yum.repos.d]# docker rm -f ansible
ansible
[root@localhost yum.repos.d]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2f9e533bfbbd centos_installed_net-tools "bash" 3 hours ago Up 2 minutes new_centos
ed028cc2bae6 centos "/bin/bash" 3 hours ago Up 3 hours fan
[root@localhost yum.repos.d]#
17.导出容器
[root@localhost yum.repos.d]# docker export -o new_centos.tar new_centos
[root@localhost yum.repos.d]# ls
CentOS-Base.repo docker.repo new_centos.tar redhat.repo rpm
[root@localhost yum.repos.d]#
18.导入容器,导入后在镜像库中查看,可以用此镜像再部署容器
[root@localhost yum.repos.d]# docker import new_centos.tar newcentos2
sha256:2e323086835787331093168f070c02d7c4f8cfc873aeba2d8518a8ea36f73652
[root@localhost yum.repos.d]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
newcentos2 latest 2e3230868357 5 seconds ago 236MB
centos_installed_net-tools latest 773684bbbd7f 3 hours ago 236MB
centos latest 0d120b6ccaa8 2 months ago 215MB
ansible/centos7-ansible latest 688353a31fde 3 years ago 447MB
[root@localhost yum.repos.d]#