Docker 创建网络应该忽略现有网络 [英] Docker create network should ignore existing network

查看:22
本文介绍了Docker 创建网络应该忽略现有网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 docker 容器在名为 my_local_network 的本地网络中运行.为确保网络存在,每个构建脚本都以:

My docker containers are running in a local network, called my_local_network. To assure the network exists, every build script starts with:

docker network create --driver bridge my_local_network

这很好用.如果网络不存在,则创建它,如果不存在,则什么也不会发生.除了错误信息:

This works fine. If the network does not exist, it is created, if not, nothing happens. Except for the error message:

Error response from daemon: network with name my_local_network already exists

如果网络不存在,有没有办法告诉 docker 只创建网络?

Is there a way to tell docker only to create the network if it doesn't exist?

推荐答案

目前没有办法强制或忽略它,但你可以使用 shell 摆脱这个问题 -

Currently there is no way to force it OR ignore it but you can get rid of this problem using shell -

docker network create --driver bridge my_local_network ||是的

这样,每当您的构建脚本执行时,如果没有网络,它将创建一个网络,否则它将返回 true 而不会出现任何命令失败,以便构建脚本的其余部分可以执行.

This way whenever your build script executes, if there is no network it will create one else it will return true without any command failure so that rest of the build script can execute.

这篇关于Docker 创建网络应该忽略现有网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆