docker command not found when executed over bitbucket ssh pipeline

Viewed 2077

I'm using bitbucket pipeline to deploy my laravel application, when I push to my repo it start to build and it works perfectly until the docker exec command which will send inline command to execute inside the php container, I get the error

bash: line 3: docker: command not found

which is very wired because when I run the command directly on the same server at the same directory it works perfectly, docker is installed on the server and as you can see inside execute.sh docker-compose works with no issues however when running over the pipeline I get the error, notice the pwd to make sure the command executed in the right directory.

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 

Inside execute.sh it looks like this :

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

And the output from bitbucket pipeline build result looks like this :

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
2 Answers

Are you defining docker as a service in the bitbucket pipeline, according to the documentation, with a top level definitions entry? Like so:

definitions:
  services:
    docker:
      memory: 512  # reduce memory for docker-in-docker from 1GB to 512MB

Alternatively docker is included and ready to use directly in the image the pipeline is running, then you might try removing the service key from your step as that could be conflicting with the docker installed on the image (and since you haven't instantiated the docker service via the top level definitions entry I've posted above, the pipeline may end up in a state where it thinks docker isn't setup.

Related