如何解决警告“使用子shell避免必须重新cd”

像这样的文件夹结构:

folder_01
├── folder_02├──Dockerfile_02
├── folder_03├──Dockerfile_03 & example.sh

在example.sh脚本中,我想使用cd导航回到folder_02,并使用dockerfile_02生成映像,然后导航回到当前目录(即{{1 }}) 这是我尝试过的:

folder_03

在intelliJ中,它警告了cd .. cd ./folder_02 docker build . -t image_name cd .. cd ./folder_03 ,我读了一些有关它的文档,但还没有解决方案,有人可以帮我吗?

iCMS 回答:如何解决警告“使用子shell避免必须重新cd”

您可以在子外壳(...)中调用命令:

(
   cd ./folder_02
   docker build . -t image_name
)
(
   cd ./folder_03
   something else
)

在要保留环境的脚本中,我使用pushd + popd

pushd ./folder_02 >/dev/null
docker build . -t image_name
popd >/dev/null

pushd ./folder_03 >/dev/null
something soemthing
popd >/dev/null
,

您可以像@KamilCuk所说的那样使用子外壳client = boto3.client('ssm',region_name='eu-west-2') commands = ['echo "hello world" > hello.txt'] #this would be replaced by the command to execute the python script instance_id = [id] #id being the instance id established from above response = client.send_command(DocumentName='AWS-RunShellScript',Parameters= 'commands':commands},InstanceIds=instance_id,)

(...)

(cd ../folder_02 && docker build . -t image_name )
(cd ../folder_03 && something else)

从Docker开始,您可以使用-f参数选择要使用的Dockerfile:

(cd ../folder_02; docker build . -t image_name )
(cd ../folder_03; something else)
本文链接:https://www.f2er.com/2295159.html

大家都在问