gpt4 book ai didi

amazon-web-services - 在EC2用户数据中运行docker-compose

转载 作者:行者123 更新时间:2023-12-02 20:55:38 25 4
gpt4 key购买 nike

我有一个包含dokcer compose的EC2 linux2实例。我希望实例在每次实例启动时启动docker服务,导航到正确的文件夹,然后运行docker-compose up -d(三行):

sudo service docker start
cd APP
docker-compose up -d
here所示,在实例停止时将其输入到用户数据中应该可以:
#!/bin/bash
sudo service docker start
cd APP
docker-compose up -d
但是它什么也没做。 aws doc也具有以下脚本:
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0

--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config
cloud_final_modules:
- [scripts-user, always]

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"

#!/bin/bash
/bin/echo "Hello World" >> /tmp/testfile.txt <<<<<<<<------- ACTUAL USER SCRIPT
--//
当我粘贴三行而不是hello world行时,只有第一行(启动docker服务)起作用。
我是Linux的新手,所以可能是我所缺少的小东西。
谢谢
编辑
谢谢大家的帮助,问题实际上是dir APP的路径。

最佳答案

entering this to the user data when the instance is stopped should work


遗憾的是,第一次尝试将无效。这是因为当新实例 启动时, UserData executes only

When I paste my three lines instead of the hello world line, only the first one


第二次尝试失败,因为此脚本在 root文件夹(文件系统的 根目录)中作为/运行。因此,除非您的APP使用/APP,否则将无法使用。

关于amazon-web-services - 在EC2用户数据中运行docker-compose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63153521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com