Jenkins构建部分中的Bash脚本
#!/bin/sh
docker build -t smstake:latest .
#Push to the private repository applying the proper tags for the image
docker tag smstake:latest reg01.dev.01cloud.com:5000/smstake:1.0.1
docker push reg01.dev.01cloud.com:5000/smstake:1.0.1
docker stack rm smstake
docker stack deploy -c docker-compose.yml smstake
问题是它在第一次构建时失败,并且发布了一些网络问题。如果再次构建,它将在另一个构建上成功运行。我该如何解决这个问题。
我得到的错误:
Removing service smstake_app
Removing service smstake_db
Removing service smstake_phpmyadmin
Removing network smstake_smstake
Creating service smstake_app
failed to create service smstake_app: Error response from daemon: network smstake_smstake not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
我们可以看到它在服务创建过程中删除服务 投掷网络没有找到问题。
这是我的docker-compose.yml
version: '3.4'
networks:
smstake:
ipam:
config:
- subnet: 10.0.10.0/24
services:
db:
image: mysql:5.7
networks:
- smstake
ports:
- "3306"
env_file:
- configuration.env
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
volumes:
- mysql_data:/var/lib/mysql
deploy:
mode: replicated
replicas: 1
app:
image: smstake:latest
ports:
- 8000:80
networks:
- smstake
depends_on:
- db
deploy:
mode: replicated
replicas: 1
placement:
constraints:
- node.role == manager
phpmyadmin:
image: phpmyadmin/phpmyadmin
networks:
- smstake
depends_on:
- db
environment:
PMA_HOST: db
PMA_PORT: 3306
MYSQL_USER: *****
MYSQL_PASSWORD: *****
ports:
- '8082:80'
deploy:
mode: replicated
replicas: 1
volumes:
mysql_data:
答案 0 :(得分:5)
问题是在docker stack rm smstake
中没有立即删除网络,但在此命令启动后docker stack deploy -c docker-compose.yml smstake
。
您可以等待网络真正删除,然后再次部署堆栈,如下所示:
docker stack rm smstake
while [ $(docker network ls | grep smstake_smstake | wc -c) -ne 0 ] ; do sleep 1 ; done
docker stack deploy -c docker-compose.yml smstake
只要网络while
仍然存在,smstake_smstake
就会执行。