如何在我的Docker容器中核对所有内容并启动新的?

时间:2018-02-20 14:27:26

标签: docker docker-compose dockerfile webpack-dev-server yarnpkg

(我显然还没有完全掌握Docker的概念,所以当我错误地/不准确地使用术语时,请纠正我。)

我的存储空间不足,所以我运行docker system prune来清理我的系统。然而,在那之后不久(可能是立即),我在容器中启动Webpack dev服务器后开始遇到分段错误。我在这一点上的猜测是,这是由于某些npm包必须重建,但由于一些旧的手工艺品仍然挥之不去,它没有这样做?如果我在容器外运行Webpack dev服务器,我没有遇到分段错误:

web_1       | [2] Project is running at http://0.0.0.0:8000/
web_1       | [2] webpack output is served from /
web_1       | [2] 404s will fallback to /index.html
web_1       | [2] Segmentation fault (core dumped)
web_1       | [2] error Command failed with exit code 139.

因此,我想知道docker system prune是否真的删除了我之前运行的Docker图像的相关内容,或者我是否可以进行一些额外的清理。

我的Dockerfile是一个跟随,其中./stacks/frontend是运行Webpack dev服务器的目录(通过yarn start):

FROM node:6-alpine
LABEL Name="Flockademic dev environment" \
      Version="0.0.0"
ENV NODE_ENV=development
WORKDIR /usr/src/app
# Needed for one of the npm dependencies (fibers, when compiling node-gyp):
RUN apk add --no-cache python make g++
COPY ["package.json", "yarn.lock", "package-lock.json*", "./"]
# Unfortunately it seems like Docker can't properly glob this at this time:
# https://stackoverflow.com/questions/35670907/docker-copy-with-file-globbing
COPY ["stacks/frontend/package.json", "stacks/frontend/yarn.lock", "stacks/frontend/package-lock*.json", "./stacks/frontend/"]
COPY ["stacks/accounts/package.json", "stacks/accounts/yarn.lock", "stacks/accounts/package-lock*.json", "./stacks/accounts/"]
COPY ["stacks/periodicals/package.json", "stacks/periodicals/yarn.lock", "stacks/periodicals/package-lock*.json", "./stacks/periodicals/"]
RUN yarn install # Also runs `yarn install` in the subdirectories
EXPOSE 3000 8000
CMD yarn start

这是docker-compose.yml中的部分:

version: '2'

services:
  web:
    image: flockademic
    build: 
      context: .
      dockerfile: docker/web/Dockerfile
    ports:
      - 3000:3000
      - 8000:8000
    volumes:
    - .:/usr/src/app/:rw
    # Prevent locally installed node_modules from being mounted inside the container.
    # Unfortunately, this does not appear to be possible for every stack without manually enumerating them:
    - /usr/src/app/node_modules
    - /usr/src/app/stacks/frontend/node_modules
    - /usr/src/app/stacks/accounts/node_modules
    - /usr/src/app/stacks/periodicals/node_modules
    links:
      - database
    environment:
      # Some environment variables I use

我对于没有清楚了解发生了什么感到有点沮丧:)有关如何完全重启(以及我出错的概念)的任何建议都将受到赞赏。

1 个答案:

答案 0 :(得分:1)

显然docker system prunesome additional options,并且正确的方法是docker system prune --all --volumes。对我而言,关键可能是--volumes,因为那些可能会包含必须重建的缓存包。

分段错误现在消失了\ o /