Mat*_*zer 5 bitbucket node.js docker docker-compose bitbucket-pipelines
我正在尝试在 bitbucket 管道内使用 docker-compose 来构建多个微服务并对它们运行测试。但是我收到以下错误:
Step 19/19 : COPY . .
Service 'app' failed to build: failed to copy files: failed to copy directory: Error processing tar file(exit status 1): Container ID 166535 cannot be mapped to a host ID
Run Code Online (Sandbox Code Playgroud)
截至目前,我的docker-compose.yml如下所示:
version: '2.3'
services:
app:
build:
context: .
target: dev
ports:
- "3030:3030"
image: myapp:dev
entrypoint: "/docker-entrypoint-dev.sh"
command: [ "npm", "run", "watch" ]
volumes:
- .:/app/
- /app/node_modules
environment:
NODE_ENV: development
PORT: 3030
DATABASE_URL: postgres://postgres:@postgres/mydb
Run Code Online (Sandbox Code Playgroud)
我的 Dockerfile 如下:
# ---- Base ----
#
FROM node:10-slim AS base
ENV PORT 80
ENV HOST 0.0.0.0
EXPOSE 80
WORKDIR /app
COPY ./scripts/docker-entrypoint-dev.sh /
RUN chmod +x /docker-entrypoint-dev.sh
COPY ./scripts/docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
COPY package.json package-lock.json ./
# ---- Dependencies ----
#
FROM base as dependencies
RUN npm cache verify
RUN npm install --production=true
RUN cp -R node_modules node_modules_prod
RUN npm install --production=false
# ---- Development ----
#
FROM dependencies AS dev
ENV NODE_ENV development
COPY . .
# ---- Release ----
#
FROM dependencies AS release
ENV NODE_ENV production
COPY --from=dependencies /app/node_modules_prod ./node_modules
COPY . .
CMD ["npm", "start"]
Run Code Online (Sandbox Code Playgroud)
在我的bitbucket-pipelines.yml中,我将管道定义为:
image: node:10.15.3
pipelines:
default:
- step:
name: 'install docker-compose, and run tests'
script:
- curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- docker-compose -v
- docker-compose run app npm run test
- echo 'tests done'
services:
- docker
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用不带 docker-compose 的 docker 时,此示例有效,将我的管道定义为:
pipelines:
default:
- step:
name: 'install and run tests'
script:
- docker build -t myapp .
- docker run --entrypoint="" myapp npm run test
- echo 'done!'
services:
- postgres
- docker
Run Code Online (Sandbox Code Playgroud)
我在 atlassian 社区中发现了这个问题(https://jira.atlassian.com/browse/BCLOUD-17319),但是我找不到解决方案来修复我损坏的用例。有什么建议么?
我会尝试使用已安装 docker-compose 的映像,而不是在管道期间安装它。
image: node:10.15.3
pipelines:
default:
- step:
name: 'run tests'
script:
- docker-compose -v
- docker-compose run app npm run test
- echo 'tests done'
services:
- docker
definitions:
services:
docker:
image: docker/compose:1.25.4
Run Code Online (Sandbox Code Playgroud)
尝试将其添加到您的bitbucket-pipelines.yml
如果它不起作用,docker请customDocker在定义和服务部分中重命名为。
如果它也不起作用,那么因为您不需要直接在管道中使用nodejs,所以尝试使用这种方法:
image: docker/compose:1.25.4
pipelines:
default:
- step:
name: 'run tests'
script:
- docker-compose -v
- docker-compose run app npm run test
- echo 'tests done'
services:
- docker
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9489 次 |
| 最近记录: |