使用Docker创建CentOS容器

拉取CentOS镜像
[root@localhost ~]# docker pull centos:centos7
centos7: Pulling from library/centos
2d473b07cdd5: Pull complete 
Digest: sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4
Status: Downloaded newer image for centos:centos7
docker.io/library/centos:centos7
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
centos       centos7   eeb6ee3f44bd   17 months ago   204MB
[root@localhost ~]#
 
 
 
创建CentOS容器并运行
[root@localhost ~]# docker run -itd --name docker-centos7 centos:centos7
541820ede8e15053e7c77dac36fcb5f8eb23764455b714033664610f51d51a79
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE            COMMAND       CREATED          STATUS          PORTS     NAMES
541820ede8e1   centos:centos7   "/bin/bash"   17 seconds ago   Up 17 seconds             docker-centos7
[root@localhost ~]#
 
 
 
进入CentOS容器
[root@localhost ~]# docker exec -it docker-centos7 env LANG=C.UTF-8 /bin/bash
[root@541820ede8e1 /]# exit # 退出CentOS容器
exit
[root@localhost ~]#
备注:进入CentOS容器后就可以和使用虚拟机CentOS一样操作了。

Copyright © 2024 码农人生. All Rights Reserved