Mac下通过docker使用CentOS

参见https://www.cnblogs.com/v5captain/p/12591275.html

1.安装docker

手工下载安装(https://www.docker.com/products/docker-desktop
或者
brew cask install docker

2.安装centos

  搜索想要的镜像

sixu@bogon ~ % docker search centos

NAME                                    DESCRIPTION                                                  STARS               OFFICIAL         AUTOMATED

centos                                    The official build of CentOS.                                 6140                [OK]                

ansible/centos7-ansible            Ansible on Centos7                                               132                                     [OK]

consol/centos-xfce-vnc           Centos container with "headless" VNC session…       119                                     [OK]

……

下载镜像

sixu@bogon ~ % docker pull centos

Using default tag: latest

latest: Pulling from library/centos

3c72a8ed6814: Pull complete 

Digest: sha256:76d24f3ba3317fa945743bb3746fbaf3a0b752f10b10376960de01da70685fbd

Status: Downloaded newer image for centos:latest

docker.io/library/centos:latest

查看本地镜像:

sixu@bogon ~ % docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

centos              latest              0d120b6ccaa8        9 days ago          215MB

hello-world         latest              fce289e99eb9        19 months ago       1.84kB

启动镜像,把mac本地用户zhang影射到容器里:

sixu@bogon ~ % docker run -t -i --privileged=true -v /Users/sixu:/home/sixu centos

[root@4d3e87e79af0 /]# pwd

/

[root@4d3e87e79af0 /]# ls

bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

[root@4d3e87e79af0 /]# ls /home

sixu

[root@4d3e87e79af0 /]# 

3.其他:

  sudo docker ps -a //显示本地已创建的容器

  sudo docker rm 1d994860ab3b  //删除容器

  sudo docker restart 072583834fa5 //重启容器

  sudo docker attach 072583834fa5  //进入容器

原文地址:https://www.cnblogs.com/newalan/p/13538542.html