bash - 通过bitbucket ssh管道执行时找不到docker命令

标签 bash docker ssh pipeline bitbucket-pipelines

我正在使用bitbucket管道部署我的laravel应用程序,当我将其推送到我的仓库时,它开始构建,并且可以很好地工作,直到docker exec命令将发送内联命令在php容器中执行,我得到了错误

bash: line 3: docker: command not found

这是非常有线的,因为当我直接在同一目录下的同一台服务器上运行命令时,它运行良好,在服务器上安装了docker,并且您可以在execute.sh内部看到docker-compose可以正常工作。我收到错误的管道,请注意pwd以确保命令在正确的目录中执行。

bitbucket-pipelines.yml
image: php:7.3

pipelines:
  branches:
    testing:
      - step:
          name: Deploy to Testing
          deployment: Testing
          services:
            - docker
          caches:
            - composer
          script:
            - apt-get update && apt-get install -y unzip openssh-client
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            - composer require phpunit/phpunit
            - vendor/bin/phpunit laravel/tests/Unit
            - ssh do.server.net 'bash -s' < execute.sh 

在execute.sh内部,它看起来像这样:

cd /home/docker/docker-laravel
docker-compose build && docker-compose up -d
pwd
docker exec -ti php sh -c "php helpershell.php"
exit

而bitbucket管道构建结果的输出如下所示:
Successfully built 1218483bd067
Successfully tagged docker-laravel_php:latest
Building nginx
Step 1/1 : FROM nginx:latest
 ---> 4733136e5c3c
Successfully built 4733136e5c3c
Successfully tagged docker-laravel_nginx:latest
Creating php ... 
Creating mysql ... 
Creating mysql ... done
Creating php   ... done
Creating nginx ... 
Creating nginx ... done
/home/docker/docker-laravel
bash: line 3: docker: command not found

最佳答案

我认为发生这种情况的部分原因是因为docker-composedocker是两个单独的命令。仅仅因为一项工作并不意味着它们都能工作。另外,您可能要检查bitbucket-pipelines.yaml文件的缩进,因为yaml可能很挑剔。

有关示例结构,请参见此处:https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html

关于bash - 通过bitbucket ssh管道执行时找不到docker命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58489079/

相关文章:

linux - 使用 cut 显示来自上一个命令 linux 的信息

bash - 使用 sed 移动列

perl - 为什么 '$_' 与 Perl 单行代码中的 $ARGV 相同?

ssl - artifactory pro registry docker 镜像

apache2 - 访问 Docker 容器内的 cgi 脚本时出错,不允许操作 : Couldn't bind unix domain socket

linux - 通过 SSH 的 Perl IDE

linux - 了解虚拟机 IP 地址 ????基本?

perl - 如何查找具有小于特定计数的特定字符的行?

javascript - Vue + Docker + Nginx 应用程序在刷新浏览器后给出 404

使用多个命令的 Python paramiko 模块