久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

Win10內(nèi)置Ubuntu,,完美使用Docker in Windows

 區(qū)區(qū)收藏 2020-07-26
  • Windows10 內(nèi)置了Linux系統(tǒng):WSL (Windows Subsystem for Linux, 又稱(chēng)Bash for Windows)??梢苑奖愕卦赪in10里使用Ubuntu等Linux系統(tǒng)的命令行
  • Win10可以直接安裝Docker in Windows,不需要像Win7一樣,,要配合VirtualBox,。
  • Ref: https:///blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly

關(guān)鍵字:Win10 Ubuntu18 WSL Docker “remote Docker daemon”

  • 問(wèn)題:
    • WSL如何完美配合Docker使用呢?難道一定要通過(guò)VirtualBox么,?或者一定要安裝單獨(dú)的Ubuntu系統(tǒng)么,?
    • 答案:很簡(jiǎn)單,通過(guò)remote Docker daemon連接,!
  • 優(yōu)點(diǎn):
    • Docker基本無(wú)性能損失
    • 無(wú)須另外安裝VirtualBox等虛擬機(jī)
    • 方便同時(shí)使用Win10,、Ubuntu兩個(gè)系統(tǒng)
image.png

框架

Win10 + Docker <-- 本機(jī)共享文件夾Volume --> Ubuntu命令行(in WSL)
Ubuntu --> remote Docker daemon --> Docker in Windows
Win10瀏覽器 --> Docker in Windows --> Ubuntu IP --> Ubuntu內(nèi)服務(wù)

步驟

1. 安裝Docker in Windows10

2. 在Win10 WSL里安裝Ubuntu

  • 這教程太多了,自行搜索,。大致是打開(kāi)虛擬化HyperV,,安裝Windows Feature: WSL,重啟,,微軟商店里安裝“Ubuntu18.04”


    image.png
  • 安裝完畢,,通過(guò)開(kāi)始菜單 - Ubuntu打開(kāi),,設(shè)置Linux用戶(hù)名/密碼
  • Win+R - “Bash”也能打開(kāi),注意跟上一步起始目錄的區(qū)別

3. Ubuntu18安裝Docker CE

# Allow your user to access the Docker CLI without needing root access.
sudo usermod -aG docker $USER
  • 安裝Docker Compose
# Install Python and PIP.
sudo apt-get install -y python3 python3-pip

# Install Docker Compose into your user's home directory.
pip install --user docker-compose

4. 連接Docker daemon

  • 最關(guān)鍵的一行命令,,打開(kāi)Bash:
echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc

不通過(guò)deamon連接的話,,你在Ubuntu里運(yùn)行docker,就會(huì)出現(xiàn)錯(cuò)誤:

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
  • 驗(yàn)證Docker啟動(dòng)成功:
docker info
docker-compose --version
kevinqq@CN:/mnt/c/Users/xxx$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

至此,,已經(jīng)在WSL Ubuntu里完美配置Docker成功了,!

5. 進(jìn)階:使用Docker開(kāi)發(fā)時(shí)要注意Win10共享文件夾的問(wèn)題

Docker in Window里,只允許訪問(wèn)c:\Users\<id>\目錄下的東西,,Win+R - Bash打開(kāi)時(shí),,默認(rèn)目錄也是這個(gè)文件夾

WSL Ubuntu18里,默認(rèn)映射Win C盤(pán)為/mnt/c/,,需要手動(dòng)改為/c/

# Running Windows 10 17.09?
sudo mkdir /c
sudo mount --bind /mnt/c /c

測(cè)試一下docker-compose一個(gè)Flask網(wǎng)站:
https://docs./compose/gettingstarted/

kevinqq@CN-00009841:/c/Users/xxx/git$ git clone https://github.com/kevinqqnj/docker-compose-starter.git
kevinqq@CN-00009841:/c/Users/xxx/git$ cd docker-compose-starter 
kevinqq@CN-00009841:/c/Users/xxx/git/docker-compose-starter$ docker-compose up --build
Building web
Step 1/5 : FROM python:3.6-alpine
 ---> 1837080c5e87
Step 2/5 : ADD . /code
 ---> Using cache
 ---> 1c28f8605b6f
Step 3/5 : WORKDIR /code
 ---> Using cache
 ---> 3b36663d505b
Step 4/5 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> 5af3cbe591d4
Step 5/5 : CMD ["python", "app.py"]
 ---> Using cache
 ---> cf356692af43
Successfully built cf356692af43
Successfully tagged docker-compose-starter_web:latest
Starting docker-compose-starter_redis_1 ... done
Starting docker-compose-starter_web_1   ... done
Attaching to docker-compose-starter_web_1, docker-compose-starter_redis_1
...
redis_1  | 1:M 13 Jan 2019 07:45:08.470 * Ready to accept connections
web_1    |  * Serving Flask app "app" (lazy loading)
web_1    |  * Environment: production
web_1    |    WARNING: Do not use the development server in a production environment.
web_1    |    Use a production WSGI server instead.
web_1    |  * Debug mode: on
web_1    |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

此時(shí),,在Ubuntun里命令行訪問(wèn),已經(jīng)OK了:

kevinqq@CN-00009841:/c/Users/xxx$ curl http://localhost:5000
Hello World! I have been seen 1 times.
kevinqq@CN-00009841:/c/Users/xxx$ curl http://localhost:5000
Hello World! I have been seen 2 times.
kevinqq@CN-00009841:/c/Users/xxx$ curl http://localhost:5000
Hello World! I have been seen 3 times.

在Win10里訪問(wèn)localhost是不行的,,需要先查看Ubuntu IP地址:

kevinqq@CN-00009841:/c/Users/xxx$ ifconfig eth1
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.21.96.1  netmask 255.255.255.240  broadcast 172.21.96.15

打開(kāi)Win10瀏覽器,,輸入172.21.96.1:5000就看到Docker里的服務(wù)正常運(yùn)行了:

下一篇:用docker啟動(dòng)一個(gè)Sanic微服務(wù)框架(TBD)https://github.com/kevinqqnj/sanic-ms

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多