如何停止当前使用bash脚本运行docker?

2024-05-12 20:38:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有刮刀,使用刮屑飞溅使用码头集装箱。我需要使用另一个bash脚本启动和停止容器

run_docker.sh
#! /bin/bash
echo "run docker"
sudo docker run -itt -p 8050:8050 --rm scrapinghub/splash

Tags: dockerrmrunecho脚本bashbin集装箱
1条回答
网友
1楼 · 发布于 2024-05-12 20:38:07

添加另一个bash脚本,该脚本将运行scraper并停止docker容器

stop_docker_container.py
#! /bin/bash

cd critic_reviews/critic_reviews/spiders

echo "run merlinin-review..."
scrapy crawl merlinin-review
echo "merlinin, done..."

echo "run purexbox-review..."
scrapy crawl purexbox-review
echo "purexbox, done..."

con_id=$(eval "docker ps -q  filter ancestor=scrapinghub/splash")
docker stop "$con_id"
echo "docker container killed..."
echo "done process!!!"

变量con_id将返回当前正在运行的docker容器id,并将用于停止它

con_id=$(eval "docker ps -q  filter ancestor=scrapinghub/splash")
docker stop "$con_id"

我最近才买的。如果需要任何改进,请随时在下面发表评论。多谢各位

相关问题 更多 >