为什么docker构建后node_modules为空? [英] Why node_modules is empty after docker build?

查看:299
本文介绍了为什么docker构建后node_modules为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的docker数据量空载在主机系统上?

Why my docker data volume is empty mounted on the host system?

docker组成时完成后,我可以执行docker容器并查看 node_modules 目录,在那里我可以看到所有安装成功的模块。但是当我在主机上检查 node_modules 目录时,什么也没看到,它是空的。

When the docker-compose up is done I can exec into the docker container and look at the node_modules directory, there I can see all the modules installed successfully. But when I check my node_modules directory on my host machine I see nothing, its empty.

这里是Dockerfile :

Here is the Dockerfile:

FROM ubuntu:14.04

WORKDIR /var/www/html

COPY src/package.json /var/www/html/package.json

# install curl, apache, php
RUN DEBIAN_FRONTEND=noninteractive \
apt-get -y update && \
apt-get -y install software-properties-common python-software-properties && \
add-apt-repository ppa:ondrej/php && \
apt-get -y update && \
apt-get install -y --force-yes \
curl \
apache2 \
php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl

# install PHPUnit
RUN curl -L https://phar.phpunit.de/phpunit.phar -o phpunit.phar && \
chmod +x phpunit.phar && \
mv phpunit.phar /usr/local/bin/phpunit

# install node js 6
RUN NVM_DIR="/root/.nvm" && \
    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash && \
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && \
    nvm install 6 && \
    npm install -g webpack && \
    npm install

COPY src/ /var/www/html

EXPOSE 80

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

这是我的docker-compose。 yml文件:

and here is my docker-compose.yml file:

version: "2"
services:
  db:
    image: mysql:5.7
    volumes:
      - "./.data/db:/var/lib/mysql"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: abc
      MYSQL_DATABASE: abc
      MYSQL_USER: abc
      MYSQL_PASSWORD: abc

  wordpress:
    build: .
    restart: always
    depends_on:
      - db
    links:
      - db
    ports:
      - "8000:80"
    volumes:
      - ./src:/var/www/html
      - /var/www/html/node_modules


推荐答案

您没有安装 node_modules 卷,它只是一个直接的数据卷。这意味着数据存储在您的主机上,但是将存储在Docker引擎程序存储区中的一个文件夹中。

You're not mounting the node_modules volume, it's just a straight data volume. That means the data is stored on your host, but it will be in a folder buried in the Docker engine's program store.

在Compose文件中:

In the Compose file:

volumes:
  - ./src:/var/www/html
  - /var/www/html/node_modules

第一个卷已装入,因此容器使用 ./ src 在主机上。第二个卷未挂载,因此它将位于主机上的 / var / lib / docker 中。

The first volume is mounted, so the container uses ./src on the host. The second volume isn't mounted, so it will be in /var/lib/docker on the host.

docker -v 相同-这相当于您的Compose文件,而 inspect 显示这些卷已安装在主机上:

It's the same with docker -v - this does the equivalent of your Compose file, and the inspect shows you where the volumes are mounted on the host:

> mkdir ~/host
> docker run -d -v ~/host:/vol-mounted -v /vol-not-mounted busybox
89783d441a74a3194ce9b0d57fa632408af0c5981474ec500fb109a766d05370
> docker inspect --format '{{json .Mounts}}' 89
[{
    "Source": "/home/scrapbook/host",
    "Destination": "/vol-mounted",
    "Mode": "",
    "RW": true,
    "Propagation": "rprivate"
}, {
    "Name": "55e2f1dd9e490f1e3ce53a859075a20462aa540cd72fac7b4fbe6cd26e337644",
    "Source": "/var/lib/docker/volumes/55e2f1dd9e490f1e3ce53a859075a20462aa540cd72fac7b4fbe6cd26e337644/_data",
    "Destination": "/vol-not-mounted",
    "Driver": "local",
    "Mode": "",
    "RW": true,
    "Propagation": ""
}]

这篇关于为什么docker构建后node_modules为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆