拉取镜像
[root@localhost local]# docker pull centos:7
7: Pulling from library/centos
75f829a71a1c: Pull complete
Digest: sha256:19a79828ca2e505eaee0ff38c2f3fd9901f4826737295157cc5212b7a372cd2b
Status: Downloaded newer image for centos:7
docker.io/library/centos:7
查看
[root@localhost local]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 7e6257c9f8d8 2 months ago 203MB
hello-world latest bf756fb1ae65 9 months ago 13.3kB
启动镜像
启动镜像centos7,如果不指定 /bin/bash,容器运行后会自动停止
[root@localhost ~]# docker run -d -i -t <IMAGE ID> /bin/bash
进入容器
[root@localhost ~]# docker exec -it <CONTAINER ID> bash
进入后发现没有ifconfig,直接yum安装
[root@22a91333c6ad /]# yum install -y net-tools
如果无法ping外网,重建docker0网络
[root@localhost ~]# pkill docker
[root@localhost ~]# iptables -t nat -F
[root@localhost ~]# ifconfig docker0 down
[root@localhost ~]# brctl delbr docker0
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker start