使用docker安装centos7并挂载主机目录

1. docker拉取官方centos镜像

docker pull centos:centos7

2. 等待下载完成后,我们就可以在本地镜像列表里查到

mac@MacdeMacBook-Pro ~ % docker images                                       
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       centos7   8652b9f0cb4c   9 months ago   204MB

3.运行容器(直接挂载主机的/Users/mac/bingo/test_dir目录到容器的/root/test_dir目录)

docker run --privileged --name=centos7_01 -itd -v /Users/mac/bingo/test_dir:/root/test_dir centos:centos7

命令解释:

--privileged   #超级权限
--name     #指定容器名称

4.进入容器

docker exec -it centos7_01 /bin/bash

5.退出容器

exit

 

 

附=>常用命令:

查看已经安装的镜像:
docker images

查看正在运行的容器:
docker ps

查看所有容器:
docker ps -a

停止运行容器:
docker stop 容器名称/ID

启动容器:
docker start 容器名称/ID

删除容器(非镜像):
docker rm 容器名称/ID

 

posted @ 2021-09-06 18:33  007少侠  阅读(800)  评论(0编辑  收藏  举报
友情链接:便宜vps(CN2GIA线路)
站长统计: