docker:安裝centos7映象(六)

lcjasas發表於2020-10-28

拉取映象

[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

相關文章