本教程屬于初學(xué)者教程道偷,大神請(qǐng)自動(dòng)略過玖雁。
Docker 是一個(gè)開源程序更扁,它可以將應(yīng)用及其完整的依賴包捆綁到一起,并打包為容器赫冬。在云大行其道的今天浓镜,虛擬化發(fā)揮了其無限潛能。未來會(huì)有更多的服務(wù)部署在云端劲厌。在實(shí)際開發(fā)的過程中膛薛,常常會(huì)因?yàn)楝F(xiàn)網(wǎng)環(huán)境和開發(fā)環(huán)境不一致導(dǎo)致各種各樣的問題出現(xiàn),但是如果我們利用docker則會(huì)完全規(guī)避這個(gè)問題补鼻。docker的好處這里就不一一列舉了哄啄,接下來雅任,讓我們從0開始,創(chuàng)建一個(gè)dock的http應(yīng)用吧咨跌。無論之后要開發(fā)多么復(fù)雜的應(yīng)用沪么,這個(gè)教程都會(huì)使你收益匪淺。
知識(shí)點(diǎn)&目錄
1锌半、在windows上安裝docker
2禽车、wsl下安裝docker,配置daemon
3刊殉、編寫一個(gè)Hello Container的基于http web的應(yīng)用
4殉摔、dockerfile初探
5、構(gòu)建/運(yùn)行容器
正文
一冗澈、在windows安裝docker應(yīng)用
如果你是在玩docker toolbx你可以參考這篇文章钦勘。
http://www.reibang.com/p/aa41f5b77aea
下面我們來看下怎么玩docker for windows:
1、在docker官網(wǎng)下載docker for windows,為什么說坑爹的亚亲,現(xiàn)在的docker竟然要求先注冊(cè)才能下載。
點(diǎn)擊安裝:一直next腐缤,此處省略10個(gè)字
安裝完成后在桌面會(huì)出現(xiàn)一個(gè)docker的圖標(biāo)捌归,雙擊即可運(yùn)行。
狀態(tài)欄右下角出現(xiàn)圖標(biāo):
即表示docker服務(wù)已經(jīng)成功拉起岭粤。
如果你想在wsl編譯運(yùn)行容器惜索,則需要右擊圖標(biāo)->settings,有以下界面剃浇,選擇Expose daemon on tcp://localhost:2375 without TLS巾兆,至于為什么,稍后就會(huì)揭曉虎囚。
角塑。
以上windows端的docker安裝就完成了,是不是太easy了!
二淘讥、wsl端的docker安裝
這里所述的wsl均是基于ubuntu的圃伶,其他系統(tǒng)換湯不換藥。
更新源:apt-get update
安裝docker: apt-get install docker
讀條完畢蒲列,至此wsl的docker也安裝完成了窒朋。是不是更簡單。
**三蝗岖、測試docker是否安裝成功
鍵入:docker version
Client:
Version: 18.09.7
API version: 1.39
Go version: go1.10.1
Git commit: 2d0083d
Built: Wed Jul 3 12:13:59 2019
OS/Arch: linux/amd64
Experimental: false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
出現(xiàn)以上界面侥猩,就說明docker已經(jīng)安裝成功了。
但是下面顯示
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
是因?yàn)閣sl目前不支持docker daemon抵赢,需要使用Docker CLI連接到windows通過Docker for Windows或您創(chuàng)建的遠(yuǎn)程Docker守護(hù)進(jìn)程欺劳。之前已經(jīng)在windows端開啟docker服務(wù)的時(shí)候已經(jīng)在setting中開啟了Expose daemon on tcp://localhost:2375 without TLS這個(gè)選項(xiàng).
設(shè)置一下環(huán)境變量:export DOCKER_HOST=tcp://127.0.0.1:2375
Client:
Version: 18.09.7
API version: 1.39
Go version: go1.10.1
Git commit: 2d0083d
Built: Wed Jul 3 12:13:59 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:13:06 2019
OS/Arch: linux/amd64
Experimental: false
可以看到Client 和 Server都起來了唧取。
四、來玩?zhèn)€hello world吧杰标。
輸入:docker pull hello-world
來拉取一個(gè)hello world的image
查看image: docker image ls
看到hello-world的image已經(jīng)存在:
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest fce289e99eb9 6 months ago 1.84kB
運(yùn)行image container:
輸入:docker run hello-world
顯示如下:
Hello from 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/
至此WSL下的docker環(huán)境就已經(jīng)安裝完成兵怯,下一篇教程我們來自己編寫一個(gè)hello docker的web應(yīng)用∏患粒可以在瀏覽器顯示的那種媒区。
快速跳轉(zhuǎn)。
http://www.reibang.com/p/ac1a1b4c087d