Docker Compose 一鍵部署多節點爬蟲程序docker
目錄結構vim
[root@localhost ~]# tree compose_crawler/ compose_crawler/ ├── centos │ ├── curl.sh │ └── Dockerfile └── docker-compose.yml
一、建立DockerCompose項目目錄centos
mkdir compose_crawler
cd compose_crawler/
二、建立centos管理目錄bash
mkdir centos
cd centos
三、建立腳本模擬爬蟲文件curl
vim curl.shui
for i in {1..100}; do curl http://192.168.1.72 -o /dev/null sleep 1 done
# 添加執行權限 chmod +x curl.sh
四、建立Dockerfile文件url
vim Dockerfilespa
# 指定鏡像 FROM centos:6 # 指定管理員 MAINTAINER xiangsikai # 複製本地文件到容器內 COPY curl.sh / # 運行腳本文件 CMD ["/bin/bash", "curl.sh"]
五、項目目錄下建立docker-compose.yml文件code
vim docker-compose.ymlblog
# 指定服務版本號 version: '3' # 服務 services: # 服務名稱 curl-test: # 構建 build: # 指定目錄上下文構建鏡像 context: ./centos # 指定dockerfile文件名稱 dockerfile: Dockerfile
六、啓動dockercompose構建鏡像容器
# 後臺執行容器 docker-compose up -d
# 擴展添加容器數量 curl-test爲容器名 docker-compose scale curl-test=20
# 查看啓動容器數量 docker-compose ps
Name Command State Ports ------------------------------------------------------------------ compose_crawler_curl-test_1 /bin/bash curl.sh Exit 0 compose_crawler_curl-test_10 /bin/bash curl.sh Up compose_crawler_curl-test_100 /bin/bash curl.sh Up compose_crawler_curl-test_11 /bin/bash curl.sh Up compose_crawler_curl-test_12 /bin/bash curl.sh Up compose_crawler_curl-test_13 /bin/bash curl.sh Up compose_crawler_curl-test_14 /bin/bash curl.sh Up compose_crawler_curl-test_15 /bin/bash curl.sh Up compose_crawler_curl-test_16 /bin/bash curl.sh Up compose_crawler_curl-test_17 /bin/bash curl.sh Up compose_crawler_curl-test_18 /bin/bash curl.sh Up compose_crawler_curl-test_19 /bin/bash curl.sh Up compose_crawler_curl-test_2 /bin/bash curl.sh Up compose_crawler_curl-test_20 /bin/bash curl.sh Up