MacOS?Docker?安裝的實(shí)現(xiàn)步驟
本文講述主要是基于Mac電腦安裝教程,使用的是homebrew安裝,未安裝homebrew的請(qǐng)先自行安裝下
一、使用 Homebrew 安裝
macOS 我們可以使用 Homebrew 來安裝 Docker。Homebrew 的 Cask 已經(jīng)支持 Docker for Mac,因此可以很方便的使用 Homebrew Cask 來進(jìn)行安裝。
1. 輸入安裝命令如下:
brew install --cask --appdir=/Applications docker # 1.輸入安裝命令 ==> Creating Caskroom at /usr/local/Caskroom ==> We'll set permissions properly so we won't need sudo in the future Password: # 2.輸入你的macOS 密碼 ==> Satisfying dependencies ==> Downloading https://download.docker.com/mac/stable/21090/Docker.dmg #################################################################### 100.0% ==> Verifying checksum for Cask docker ==> Installing Cask docker ==> Moving App 'Docker.app' to '/Applications/Docker.app'. 🍺 docker was successfully installed!
最后如果提示了successfully installed! 字樣就表示安裝成功了

2. 安裝完畢后,從應(yīng)用中找到Docker 圖標(biāo)點(diǎn)擊運(yùn)行??赡軙?huì)詢問 macOS 登陸密碼,輸入即可

3. 打開終端,輸入命令顯示docker的版本信息
wpf@B-L0Q0JHD2-2029 ~ % docker --version # 1.該命令僅顯示安裝版本 Docker version 20.10.22, build 3a2c30b wpf@B-L0Q0JHD2-2029 ~ % docker version # 2.該命令顯示docker具體版本信息 Client: # 客戶端信息 Cloud integration: v1.0.29 Version: 20.10.22 API version: 1.41 Go version: go1.18.9 Git commit: 3a2c30b Built: Thu Dec 15 22:28:41 2022 OS/Arch: darwin/amd64 Context: default Experimental: true Server: Docker Desktop 4.16.1 (95567) # 服務(wù)器信息 Engine: Version: 20.10.22 API version: 1.41 (minimum version 1.12) Go version: go1.18.9 Git commit: 42c8b31 Built: Thu Dec 15 22:26:14 2022 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.14 GitCommit: 9ba4b250366a5ddde94bb7c9d1def331423aa323 runc: Version: 1.1.4 GitCommit: v1.1.4-0-g5fd4c4d docker-init: Version: 0.19.0 GitCommit: de40ad0 wpf@B-L0Q0JHD2-2029 ~ %

4. 試運(yùn)行docker,使用docker run 運(yùn)行 hello-world鏡像
- doker 拉取hello-world鏡像:docker pull hello-world
- 運(yùn)行拉取hello-world鏡像:docker run hello-world
譯:當(dāng)運(yùn)行容器時(shí),使用的鏡像如果在本地中不存在,docker 就會(huì)自動(dòng)從 docker 鏡像倉(cāng)庫(kù)中下載,默認(rèn)是從 Docker Hub 公共鏡像源下載。
wpf@B-L0Q0JHD2-2029 ~ % docker run hello-world # 運(yùn)行hello-world
Unable to find image 'hello-world:latest' locally # 提示未找到hello-world鏡像
latest: Pulling from library/hello-world # 嘗試?yán)∵h(yuǎn)程官方library下的h-w鏡像
2db29710123e: Pull complete # 拉取完畢了,后面是簽名信息
Digest: sha256:aa0cc8055b82dc2509bed2e19b275c8f463506616377219d9642221ab53cf9fe
Status: Downloaded newer image for hello-world:latest
Hello from Docker! # 顯示這句話說明docker安裝成功了
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
wpf@B-L0Q0JHD2-2029 ~ % 
5. 我們可以使用 docker images 命令來列出本地主機(jī)上的鏡像。

或者直接打開Docker Desktop應(yīng)用

二、Docker底層運(yùn)行原理
docker 是一個(gè)c/s結(jié)構(gòu)的系統(tǒng)(client客戶端/server服務(wù)端)。
Docker的守護(hù)進(jìn)程運(yùn)行在宿主主機(jī)上,通過socket從客戶端訪問。DockerServer 接收到 Docker-Client的指令,就會(huì)執(zhí)行這個(gè)指令。
Docker會(huì)以root權(quán)限運(yùn)行它的守護(hù)進(jìn)程,來處理普通Linux用戶無(wú)法完成的操作(如掛載文件系統(tǒng)等操作)

? 說明:8080和3306兩個(gè)容器外部是訪問不到的,是屬于容器內(nèi)的,容器就好比一個(gè)小的虛擬機(jī),容器之間互相隔離;容器與外部大的Linux服務(wù)器也是互相隔離的,一個(gè)容器占用的進(jìn)程資源是非常小的
? Docker執(zhí)行run命令的流程如下:
- Dockers引擎會(huì)在本地查找鏡像
- 本地找到鏡像 然后啟動(dòng)鏡像
- 本地未找到鏡像,然后根據(jù)Docker引擎配置的倉(cāng)庫(kù)地址,遠(yuǎn)程去查找鏡像。
- 遠(yuǎn)程查詢到鏡像,把鏡像下載到本地,然后啟動(dòng)鏡像
- 遠(yuǎn)程查詢到鏡像,Docker返回錯(cuò)誤,提示鏡像遠(yuǎn)程未找到。
- 運(yùn)行中的鏡像支持:停止、啟動(dòng)、重啟、刪除(先停止才可以刪除)操作。

到此這篇關(guān)于MacOS Docker 安裝的實(shí)現(xiàn)步驟的文章就介紹到這了,更多相關(guān)MacOS Docker 安裝內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Docker啟動(dòng)容器后自動(dòng)關(guān)閉問題解決
在使用Docker創(chuàng)建并啟動(dòng)mysql容器時(shí),發(fā)現(xiàn)mysql容器并沒有啟動(dòng)而是自動(dòng)關(guān)閉了,本文主要介紹了Docker啟動(dòng)容器后自動(dòng)關(guān)閉問題解決,具有一定的參考價(jià)值,感興趣的可以了解一下2024-07-07
docker自定義網(wǎng)絡(luò)從入門到實(shí)踐
Docker 網(wǎng)絡(luò)模式?jīng)Q定了容器之間、容器與宿主機(jī)之間的通信方式,掌握網(wǎng)絡(luò)機(jī)制是理解容器互聯(lián)互通的關(guān)鍵,本文給大家介紹docker自定義網(wǎng)絡(luò)從入門到實(shí)踐,感興趣的朋友跟隨小編一起看看吧2025-10-10
Docker部署nnunetv2的實(shí)現(xiàn)步驟
本文主要介紹了Docker部署nnunetv2的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-04-04
win10中docker部署和運(yùn)行countly-server的流程
這篇文章主要記錄一下windows10中使用docker容器安裝和部署countly-server的整個(gè)流程,本文給大家講解的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2019-11-11

