5

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

Now I want to automate my deployments using Deployer.

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).

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

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'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;.

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

halfer
  • 19,824
  • 17
  • 99
  • 186
Ryan
  • 22,332
  • 31
  • 176
  • 357
  • 1
    So far, I've figured out that instead using `run('cd /root/laradock && (docker exec -it $(docker-compose ps -q php-fpm) bash;)', ['tty' => true]);` leads my `deploy.php` script to successfully switch into the `php-fpm` container but pauses Deployer until I type "exit", at which point it unfortunately switches back out of the `php-fpm` container (and so fails). If I instead use `run('cd /root/laradock && (docker exec -i $(docker-compose ps -q php-fpm) bash;)');`, that command seems to be completely ignored; the dir remains as `/root` at the top level of the server rather than in a container. – Ryan Jul 11 '18 at 14:48
  • See also https://stackoverflow.com/questions/32878795/run-command-inside-of-docker-container-using-ansible where they use `docker exec container-name bash -l -c` . You can use it to run commands inside the workspace container – rhand Jan 05 '19 at 00:33

3 Answers3

1

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

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

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.

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

halfer
  • 19,824
  • 17
  • 99
  • 186
0

You should try

docker-compose exec -T php-fpm bash;

The -T option will

Disable pseudo-tty allocation. By default docker-compose exec allocates a TTY.

DinoAmino
  • 93
  • 6
  • 1
    Thanks, but I already tried that. See my question. `-it` includes the `T` option already. – Ryan Jul 19 '18 at 16:28
0

In my particular case I had separate containers for PHP and Composer. That is why I could not connect to the container via SSH while deploying.

So I configured the bin/php and bin/composer parameters like this:

set('bin/php', 'docker exec php php');
set('bin/composer', 'docker run --volume={{release_path}}:/app composer');

Notice that here we use exec for a persistent php container which is already running at the moment and run to start a new instance of composer container which will stop after installing dependencies.

Kolyunya
  • 5,973
  • 7
  • 46
  • 81