2016-05-08 19 views
1

初めての開発のためにドッカーを使用しようとしています。私はノードアプリケーションを持っています。私はドッカーからアプリケーションを実行したいです。Docker:マウントボリュームと実行ノードアプリケーション

FROM node:6.0.0-slim 
MAINTAINER pyprism 

# Prepare app directory 
RUN mkdir -p /src/ 

# Install dependencies 
WORKDIR /src/ 

VOLUME .:/src/ 

RUN npm install 

# Build the app 
# RUN npm build 

# Expose the app port 
EXPOSE 8000 

# Start the app 
CMD npm start 

とドッキングウィンドウ-コンファイル:ここに私のdockerfileです

web: 
    build: . 
    ports: 
    - '8000:8000' 

しかし、私はdocker-compose upを実行すると、私はこのエラーを得た:

Building web 
Step 1 : FROM node:6.0.0-slim 
---> 7bf50b1ad9da 
Step 2 : MAINTAINER pyprism 
---> Running in d1defd389fe6 
---> b684686c614d 
Removing intermediate container d1defd389fe6 
Step 3 : RUN mkdir -p /src/ 
---> Running in 36b64560f88f 
---> 8eb6847d67e4 
Removing intermediate container 36b64560f88f 
Step 4 : WORKDIR /src/ 
---> Running in 00d4c1fd2cf5 
---> 88a54e6af176 
Removing intermediate container 00d4c1fd2cf5 
Step 5 : VOLUME .:/src/ 
---> Running in dc0e9d9d973a 
---> b558f03ce63c 
Removing intermediate container dc0e9d9d973a 
Step 6 : RUN npm install 
---> Running in 09445786b71e 
npm info it worked if it ends with ok 
npm info using [email protected] 
npm info using [email protected] 
npm info lifecycle undefined~preinstall: undefined 
npm info linkStuff !invalid#1 
npm info lifecycle undefined~install: undefined 
npm info lifecycle undefined~postinstall: undefined 
npm info lifecycle undefined~prepublish: undefined 
npm WARN enoent ENOENT: no such file or directory, open '/src/package.json' 
npm WARN src No description 
npm WARN src No repository field. 
npm WARN src No README data 
npm WARN src No license field. 
npm info ok 
---> 8c544294e6c5 
Removing intermediate container 09445786b71e 
Step 7 : EXPOSE 8000 
---> Running in 965e192bc67e 
---> daaf52fac6ca 
Removing intermediate container 965e192bc67e 
Step 8 : CMD npm start 
---> Running in 890549e3aea7 
---> 19a3dc786cee 
Removing intermediate container 890549e3aea7 
Successfully built 19a3dc786cee 
WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`. 
Creating redux_web_1 
Attaching to redux_web_1 
web_1 | npm info it worked if it ends with ok 
web_1 | npm info using [email protected] 
web_1 | npm info using [email protected] 
web_1 | npm ERR! Linux 4.4.0-22-generic 
web_1 | npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start" 
web_1 | npm ERR! node v6.0.0 
web_1 | npm ERR! npm v3.8.6 
web_1 | npm ERR! path /src/package.json 
web_1 | npm ERR! code ENOENT 
web_1 | npm ERR! errno -2 
web_1 | npm ERR! syscall open 
web_1 | 
web_1 | npm ERR! enoent ENOENT: no such file or directory, open '/src/package.json' 
web_1 | npm ERR! enoent ENOENT: no such file or directory, open '/src/package.json' 
web_1 | npm ERR! enoent This is most likely not a problem with npm itself 
web_1 | npm ERR! enoent and is related to npm not being able to find a file. 
web_1 | npm ERR! enoent 
web_1 | 
web_1 | npm ERR! Please include the following file with any support request: 
web_1 | npm ERR!  /src/npm-debug.log 
redux_web_1 exited with code 254 
+1

なぜあなたは、ボリュームを使用していますか?変更を反映させるには、 'COPY'または' ADD'コマンドを使うべきです。あなたのアプリケーションを更新している間、保持したいデータのボリュームを使用します。 – blissini

+0

私は 'ADDを使用しようとしています。/src/'私の変更を反映していません。 – pyprism

+1

このレポをチェックしてください:https://github.com/b00giZm/docker-compose-nodejs-examples/tree/master/00-basic-express-generatorそして 'Dockerfile'と' docker-compose.ymlを見てください' – blissini

答えて

5

これは、dockerfileでVOLUME命令を使用する正しい方法ではありません。 「VOLUME命令は、指定された名前のマウントポイントを作成し、ネイティブのホストまたは他のコンテナから外部マウントされたボリュームを保持するものとしてマークしています」と書かれているので、やりたいことはありません。

VOLUME命令を指定する必要はなく、src directoyを作成する必要はありません。今、あなたはDockerfileディレクトリに移動することができますし、画像構築

FROM node:6.0.0-slim 
MAINTAINER pyprism 

# Install dependencies 
WORKDIR /src/ 

RUN npm install 

# Expose the app port 
EXPOSE 8000 

# Start the app 
CMD npm start 

:以下のように、あなたのローカルディレクトリをマウントするには、-vオプションを使用してコンテナを実行し

$docker build -t node . 

を以下のようにDockerfileを変更:

$docker run -p 8000:8000 -v path/to/code/dir:/src/ <image-name> 

これは/ srcにコードディレクトリをマウントします。

あなたがドッキングウィンドウのコンを使用したい場合は、単にドッキングウィンドウ-compose.ymlファイル内のボリュームを指定します。

web: 
    build: . 
    volumes: 
    - path/to/code/dir:/src/ 
    ports: 
    - '8000:8000' 
1

あなたはこのVOLUME .:/src/を行うことはできませんドッカーファイル。ドッカーファイルにホストのマウントポイントを指定するのは、ホストの依存関係をレンダリングするときと同じように正当な構文ではありません。ボリュームマッピング定義をdocker-compose.ymlファイルに移動します。

関連する問題