如何在Docker(Laradock)中使用Deployer [英] How to use Deployer with Docker (Laradock)

查看:155
本文介绍了如何在Docker(Laradock)中使用Deployer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的带有Docker的Digital Ocean服务器(使用 Laradock ),并使我的Laravel网站运行良好.

I created a fresh Digital Ocean server with Docker on it (using Laradock) and got my Laravel website working well.

现在,我想使用 Deployer 使部署自动化.

Now I want to automate my deployments using Deployer.

我认为我唯一的问题是我无法让Deployer运行docker exec -it $(docker-compose ps -q php-fpm) bash;,这是我成功手动使用的命令,用于输入适当的Docker容器(使用SSH从本地计算机连接到Digital Ocean后服务器).

I think my only problem is that I can't get Deployer to run docker exec -it $(docker-compose ps -q php-fpm) bash;, which is the command I successfully manually use to enter the appropriate Docker container (after using SSH to connect from my local machine to the Digital Ocean server).

当Deployer尝试运行它时,出现以下错误消息:

When Deployer tries to run it, I get this error message:

➤ Executing task execphpfpm
[1.5.6.6] > cd /root/laradock && (pwd;)
[1.5.6.6] < /root/laradock
[1.5.6.6] > cd /root/laradock && (docker exec -it $(docker-compose ps -q php-fpm) bash;)
[1.5.6.6] < the input device is not a TTY
➤ Executing task deploy:failed
• done on [1.5.6.6]
✔ Ok [3ms]
➤ Executing task deploy:unlock
[1.5.6.6] > rm -f ~/daily/.dep/deploy.lock
• done on [1.5.6.6]
✔ Ok [188ms]

In Client.php line 99:

  [Deployer\Exception\RuntimeException (1)]
  The command "cd /root/laradock && (docker exec -it $(docker-compose ps -q php-fpm) bash;)" failed.

  Exit Code: 1 (General error)

  Host Name: 1.5.6.6

  ================
  the input device is not a TTY

以下是我的deploy.php的相关部分:

Here are the relevant parts of my deploy.php:

host('1.5.6.6')
        ->user('root')
        ->identityFile('~/.ssh/id_rsa2018-07-09')
        ->forwardAgent(true)
        ->stage('production')
        ->set('deploy_path', '~/{{application}}');

before('deploy:prepare', 'execphpfpm');

task('execphpfpm', function () {
    cd('/root/laradock');
    run('pwd;');
    run('docker exec -it $(docker-compose ps -q php-fpm) bash;');
    run('pwd');
});

我已经花了一天半的时间阅读无数的文章,并尝试了许多不同的变体.例如.用-i替换-it标志,或设置export COMPOSE_INTERACTIVE_NO_CLI=1或用docker-compose exec php-fpm bash;替换整个docker exec命令.

I've already spent a day and a half reading countless articles and trying so many different variations. E.g. replacing the -it flag with -i, or setting export COMPOSE_INTERACTIVE_NO_CLI=1 or replacing the whole docker exec command with docker-compose exec php-fpm bash;.

我希望我缺少相当简单的东西. Docker被广泛使用,并且Deployer似乎也很流行.

I expect that I'm missing something fairly simple. Docker is widely used, and Deployer seems popular too.

推荐答案

要使用Laravel Deployer,您应该通过ssh直接连接到工作区容器.

To use Laravel Deployer you should connect via ssh directly to the workspace container.

您可以公开容器的ssh端口: https://laradock.io/documentation/#access-workspace-via-ssh

You can expose the container's ssh port: https://laradock.io/documentation/#access-workspace-via-ssh

假设您已将容器ssh端口22转发到vm端口2222.在这种情况下,您需要将Deployer配置为使用端口2222.

Let's say you've forwarded container ssh port 22 to vm port 2222. In that case you need configure your Deployer to use the port 2222.

还请记住设置正确的安全SSH密钥,而不是默认密钥.

Also remember to set proper secure SSH keys, not the default ones.

这篇关于如何在Docker(Laradock)中使用Deployer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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