docker-compose: command not found on jenkins

瘦欲@ 提交于 2019-12-06 11:52:49

问题


I have a docker compose file

version: "3"
services:
  mysql:
    image: mysql:latest
    container_name: locations-service-mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USERNAME: root
      MYSQL_DATABASE: 'locations_schema'
    restart: always
    volumes:
      - mysql_data:/var/lib/mysql:rw

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    ports:
      - 8181:80
    environment:
      MYSQL_USERNAME: root
      MYSQL_ROOT_PASSWORD: root
      PMA_HOST: mysql
    depends_on:
      - mysql
    links:
      - mysql:mysql


  dropwizard:
    build:
      context : ../locations-service/
    ports:
          - 8080:8080
          - 8081:8081
    depends_on:
          - mysql
    links:
      - mysql:mysql
    restart: always
    container_name: locations-service

volumes:
  mysql_data:

And i've configure a jenkins job to execute this file by calling another shell file "environment.sh", but it attempts to execute the following error appears:

23:51:57 ./environment.sh: line 3: docker-compose: command not found
23:51:57 ./environment.sh: line 4: docker-compose: command not found
23:51:57 ./environment.sh: line 6: docker-compose: command not found
23:51:57  FAILED
23:51:57 
23:51:57 FAILURE: Build failed with an exception.
23:51:57 
23:51:57 * What went wrong:
23:51:57 Execution failed for task ':startDockerEnvironment'.
23:51:57 > Process 'command './environment.sh'' finished with non-zero exit value 127

How can i download and configure docker-compose in jenkins server, also there's no plugin available!, for docker-compose


回答1:


Probably your docker-compose doesn't exist in your $PATH env variable.

First you should remove any conflicting docker-compose -

rm /usr/local/bin/docker-compose

On most of the Linux systems, below is how I prefer installing docker & docker compose -

(Run commands as root)

curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh
curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
usermod -aG docker $YOUR_USER
systemctl enable docker

Exit the current tty & login back again with $YOUR_USER. This will always install latest docker engine CE & docker-compose(v1.17).




回答2:


In your environment.sh, do a printenv (or env) and an echo $PATH.

You can then check if the PATH as seen on the Jenkins agent does include the one for docker-compose.
If not, set it (in your script) before proceeding with the actual docker-compose commands.



来源:https://stackoverflow.com/questions/48481322/docker-compose-command-not-found-on-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!