win7安裝Docker並部署CentOS+寶塔環境

安裝docker Toolbox

win7系統需要安裝docker Toolbox來使用。
docker Toolbox國內鏡像下載地址:http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/

安裝好後桌面會多出三個圖標,分別是:Oracle VM VirtualBox,Kitematic (Alpha),Docker Quickstart Terminal。

雙擊Docker Quickstart Terminal圖標來啓動 Docker Toolbox 終端。稍等片刻後,會顯示:

代表docker環境已經安裝成功。宿主主機IP爲:192.168.99.100

運行hello world

在終端中輸入命令:

docker run hello-world

顯示結果如下:

$ docker run hello-world
 Unable to find image 'hello-world:latest' locally
 Pulling repository hello-world
 91c95931e552: Download complete
 a8219747be10: Download complete
 Status: Downloaded newer image for hello-world:latest
 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 Engine CLI client contacted the Docker Engine daemon.
  2. The Docker Engine daemon pulled the "hello-world" image from the Docker Hub.
     (Assuming it was not already locally available.)
  3. The Docker Engine daemon created a new container from that image which runs the
     executable that produces the output you are currently reading.
  4. The Docker Engine daemon streamed that output to the Docker Engine CLI client, which sent it
     to your terminal.

 To try something more ambitious, you can run an Ubuntu container with:
  $ docker run -it ubuntu bash

 For more examples and ideas, visit:
  https://docs.docker.com/userguide/

拉取centos7鏡像

如果需要安裝最新的centos鏡像,請將7改爲:latest
更多的centos鏡像:https://hub.daocloud.io/repos/bf207788-d7de-4044-bdeb-521a998f748b

在終端輸入以下命令:

docker pull daocloud.io/centos:7

設置共享文件夾

首先在G:\soft\目錄下,新建一個docker文件夾用作共享文件夾,然後在docker文件夾裏新建一個www文件夾,用於後面安裝寶塔面板。

雙擊打開Oracle VM VirtualBox,找到運行的虛擬機,打開設置->共享文件夾,將默認的共享文件夾修改爲G:\soft\docker,勾選自動掛載:

設置完成後重啓虛擬機。

重新雙擊打開Docker Quickstart Terminal,通過以下命令進入虛擬機:

docker-machine ssh default

切換root用戶:

sudo -i

查看磁盤掛載情況:

df -h

exit退回到Docker Quickstart Terminal

運行centos7容器

docker run -dit --privileged=true -p 8888:8888 -p 888:888 -p 21:21 -p 3306:3306 -p 80:80 -v /docker/www:/www --name=centos7 daocloud.io/centos:7 /usr/sbin/init

-p: 指定端口映射,格式爲:主機(宿主)端口:容器端口
–name :爲容器指定一個名稱
-v: 綁定本地文件夾。/docker/www對應的是宿主機的G:/soft/docker/www目錄 /www是容器的目錄

如果提示G:\soft\Docker Toolbox\docker.exe: Error response from daemon: cgroups: cannot f ind cgroup mount destination: unknown.這個錯誤
解決辦法:
1、執行docker-machine ssh進入Linux虛擬機。
2、執行sudo mkdir /sys/fs/cgroup/systemd
3、執行sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
4、刪除容器,重新啓動:

docker stop <容器id>
docker rm centos7
docker run -dit --privileged --name=centos7 daocloud.io/centos:7 /usr/sbin/init

進入centos容器交互界面

docker exec -it centos7 /bin/bash

安裝wget

yum install -y wget

安裝寶塔

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

構建新鏡像

將安裝好寶塔的容器打包爲新的鏡像,便於以後使用:
退出容器:

ctrl+D

執行命令:

docker commit -a "hj" -m "centos & bt" centos7  centos7bt

-a :提交的鏡像作者;
-c :使用Dockerfile指令來創建鏡像;
-m :提交時的說明文字;
-p :在commit時,將容器暫停。
centos7爲容器名
centos7bt爲新的鏡像名

構建新容器

docker run -dit --privileged -p 8888:8888 -p 888:888 -p 21:21 -p 3306:3306 -p 80:80 --name=centos7bt centos7bt /usr/sbin/init

-p: 指定端口映射,格式爲:主機(宿主)端口:容器端口
–name :爲容器指定一個名稱

訪問寶塔面板

http://192.168.99.100:8888

其他常用命令

啓動容器

docker start <容器ID>

更多資料

原文:http://www.884358.com/win7-docker-install/
docker常用命令:http://www.884358.com/docker-cmds/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章