Docker-compose文件
[root@localhost home]# cat docker-compose2.yml
version: '3'
services:
crawler1:
image: node:v2
network_mode: "host"
restart: always
container_name: node_core_6736
environment:
- TZ=Asia/Shanghai
volumes:
- /home/node_core_6736:/root
- /home/extra:/root/extra
command: python3 -u main.py
crawler2:
image: node:v2
network_mode: "host"
restart: always
container_name: node_core_6737
environment:
- TZ=Asia/Shanghai
volumes:
- /home/node_core_6737:/root
- /home/extra:/root/extra
command: python3 -u main.py
看起来你开始定义 services
下的 crawler1
服务,但没有继续写完整个服务定义。下面是 crawler1
服务的完整定义模板,基于你之前的 docker-compose.yml
:
version: '3'
services:
crawler1:
image: node:v2
network_mode: "host"
restart: always
container_name: node_core_6721
environment:
- TZ=Asia/Shanghai
volumes:
- /home/node_core:/root
- /home/extra:/root/extra
command: python3 -u main.py
解释:
image: node:v2
:指定服务使用node:v2
作为 Docker 镜像。network_mode: "host"
:服务使用宿主机的网络堆栈。restart: always
:当容器停止时自动重启。container_name: node_core_6721
:指定容器的名称为node_core_6721
。environment
:设置环境变量,TZ=Asia/Shanghai
指定时区为上海。volumes
:挂载宿主机上的/home/node_core
和/home/extra
到容器中的/root
和/root/extra
目录。command
:容器启动时执行python3 -u main.py
。
你可以继续定义其他服务(如 crawler2
)或根据需求进一步调整配置。
scp -r docker-compose2.yml root@172.16.0.35:/home
scp -r extra root@172.16.0.35:/home
scp -r node_core_6717 root@172.16.0.35:/home
scp -r /usr/local/bin/docker-compose root@172.16.0.35:/usr/local/bin
vim docker-compose2.yml
docker-compose -f docker-compose2.yml up -d
docker ps -a
docker logs -f --tail 200 node_core_6736
docker run --name=node_core_6736 -d -v /home/node_core_6736:/root -v /etc/localtime:/etc/localtime:ro --restart=always node:v2 python3 -u main1.py
docker run --name=node_core_6737 -d -v /home/node_core_6737:/root -v /etc/localtime:/etc/localtime:ro --restart=always node:v2 python3 -u main2.py
docker run --name=node_core_6738 -d -v /home/node_core_6738:/root -v /etc/localtime:/etc/localtime:ro --restart=always node:v2 python3 -u main3.py
docker run --name=node_core_6739 -d -v /home/node_core_6739:/root -v /etc/localtime:/etc/localtime:ro --restart=always node:v2 python3 -u main4.py
docker run --name=node_core_6740 -d -v /home/node_core_6740:/root -v /etc/localtime:/etc/localtime:ro --restart=always node:v2 python3 -u main5.py
评论
0 评论