我有一个使用以下 CMD 构建的 Docker 映像
# Dockerfile
...
CMD ["nginx", "-g", "daemon off;"]
Run Code Online (Sandbox Code Playgroud)
当我的任务定义不包含entryPoint或者command任务成功进入运行状态时。
{
"containerDefinitions": [
{
"image": "<myregistry>/<image>",
...
}
]
}
Run Code Online (Sandbox Code Playgroud)
我需要在此容器的某些实例中运行代理,因此我使用entrypoint此任务来运行我的代理。问题是当我entryPoint向任务定义添加参数时,容器启动并立即停止。
这就是我正在做的添加entryPoint:
{
"containerDefinitions": [
{
"image": "<myregistry>/<image>",
...
"entryPoint": [
"custom-entry-point.sh"
],
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是以下内容custom-entry-point.sh:
#!/bin/bash
/myagent &
echo "CMD is: $@"
exec "$@"
Run Code Online (Sandbox Code Playgroud)
为了证实我对 CMD 被删除的怀疑,日志仅显示:
CMD is:
Run Code Online (Sandbox Code Playgroud)
如果我使用参数将 Dockerfile 中的 CMD 数组添加到任务定义中command,则它可以正常工作并且任务将启动:
{
"containerDefinitions": [
{
"image": "<myregistry>/<image>", …Run Code Online (Sandbox Code Playgroud) 我有20个处于"web"角色的服务器.由于更改会影响共享存储,因此我只需要对其中一个执行任务.我目前的解决方案是解决这个问题(下面).寻找更好的方法,我没有大量的红宝石或帽子经验.
task :checkout_project_properties do
num_runs = 0
on roles(:web), in: :sequence do
if num_runs > 0
abort('Only running on one server. Exiting')
end
execute("checkout-project-properties #{uc_stage} #{repo} #{branch}")
num_runs += 1
end
end
Run Code Online (Sandbox Code Playgroud) 大多数tar文件都会提取到自己的子文件夹中(因为编写开源实用程序的人是很棒的人).
有些提取到我的cwd中,这使一切变得混乱.我知道有一种方法可以查看tar中的内容,但我想写一个bash脚本,基本上保证我不会最终将15个文件提取到我的主文件夹中.
有什么指针吗?
伪代码:
if [listing of tar files] has any file that doesn't have a '/' in it:
mkdir [tar filename without extension]
tar xzvf [tar filename] into [the new folder]
else:
tar xzvf [tar filename] into cwd
Run Code Online (Sandbox Code Playgroud)
编辑:
两种解决方案都很棒,我之所以选择以下解决方案是因为我要求使用bash脚本,而且它不依赖于额外的软件.
但是,在我自己的机器上,我使用的是aunpack,因为它可以处理更多,更多的格式.
我使用它与shell脚本一起下载和解压缩.这是我正在使用的:
#!/bin/bash
wget -o temp.log --content-disposition $1
old=IFS
IFS='
'
r=`cat temp.log`
rm temp.log
for line in $r; do
substring=$(expr "$line" : 'Saving to: `\(.*\)'\')
if [ "$substring" != "" ]
then
aunpack $substring
rm $substring
IFS=$old
exit …Run Code Online (Sandbox Code Playgroud)