无法使用Docker compose和Jenkins构建服务

时间:2020-10-11 06:24:38

标签: docker-compose dockerfile

我正在尝试在其中构建我的docker compose文件,特别是mongodb服务。

这是我的docker compose文件

version: '3.7'

services:

    mongodb:
        image: mongo:latest
        container_name: mongodb
        restart: always
        environment:
            MONGO_INITDB_ROOT_USERNAME: user
            MONGO_INITDB_ROOT_PASSWORD: password
            MONGO_INITDB_DATABASE: ToDoTasks2
        ports:
            - 27017:27017
        volumes:
            - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
        healthcheck:
            test:  mongo admin -u user -p password
            interval: 2s
            timeout: 5s
            retries: 5
    
    express:
        container_name: express-api
        restart: always
        build:
            context: ./server
            dockerfile: Dockerfile
        ports: 
            - 3000:3000
        depends_on: 
            mongodb:
                    condition: service_healthy
        environment:
            WAIT_HOSTS: mongodb:27017

从Bit bucket中获取代码后,我在Shell中运行以下命令

curl -L --fail https://github.com/docker/compose/releases/download/1.27.4/run.sh -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
pwd
cd /var/jenkins_home/workspace/BuildContainers
ls
docker-compose build mongodb

即使我的文件名正确,这也是我得到的错误

Checking out Revision e2ab6e14aa9e5f2de4912328aae54630061d4311 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f e2ab6e14aa9e5f2de4912328aae54630061d4311 # timeout=10
Commit message: "Removed unnecesasry file"
 > git rev-list --no-walk e2ab6e14aa9e5f2de4912328aae54630061d4311 # timeout=10
[BuildContainers] $ /bin/sh -xe /tmp/jenkins388125135510120648.sh
+ curl -L --fail https://github.com/docker/compose/releases/download/1.27.4/run.sh -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   630  100   630    0     0   2388      0 --:--:-- --:--:-- --:--:--  2395

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
100  2090  100  2090    0     0   1156      0  0:00:01  0:00:01 --:--:--  1383
+ chmod +x /usr/local/bin/docker-compose
+ pwd
/var/jenkins_home/workspace/BuildContainers
+ cd /var/jenkins_home/workspace/BuildContainers
+ ls
Jenkinsfile
docker-compose.yml
mongo-init.js
server
+ docker-compose build mongodb

        Can't find a suitable configuration file in this directory or any
        parent. Are you in the right directory?

        Supported filenames: docker-compose.yml, docker-compose.yaml
        
Build step 'Execute shell' marked build as failure
Finished: FAILURE

如果有人可以帮助解决此问题,我将非常感谢。我已经尝试了很久了

0 个答案:

没有答案