Node JS Docker文件版本不正确

时间:2017-12-09 17:54:20

标签: node.js docker

我有一个简单的docker文件,它可以提取节点图像并创建一个运行我们应用程序的容器。请在我们的docker文件的第一行下面找到。

uname -a
Linux ip.1.2.3.4-aws #50-Ubuntu SMP Wed Nov 15 22:18:17 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

当我在容器内运行FROM node:8.9.3 FROM keymetrics/pm2:latest # Create app directory RUN mkdir -p /usr/app/test/src # Install app dependencies COPY ./package.json /usr/app/test/ WORKDIR /usr/app/test RUN npm install # Move source files to the containter COPY ./src/ /usr/app/test/src/ WORKDIR /usr/app/test/src RUN pm2 install pm2-logrotate RUN pm2 set pm2-logrotate:compress true RUN pm2 set pm2-logrotate:retain 2 ARG NODE=production ENV NODE_ENV ${NODE} EXPOSE 443 #CMD [ "npm", "start" ] CMD [ "pm2-docker", "start", "pm2.json" ] 时,它显示版本为9.2.0,这是最新的节点版本。

我们的主机是运行Ubuntu的EC2

 sudo docker build -t $CLIENT_APP_TAG --no-cache --label $APP_LABEL_NAME -f ./$CLIENT_APP_DOCLER_FILE .

 sudo docker build -t $SERVER_APP_TAG --no-cache --label $APP_LABEL_NAME -f ./$SERVER_APP_DOCLER_FILE .

 docker run -dit  --name "$CLIENT_APP_NAME"_"$APP_VERSION" -p $CLIENT_HOST_PORT:$CLIENT_CONTAINER_PORT $CLIENT_APP_TAG

 docker run -dit --name "$SERVER_APP_NAME"_"$APP_VERSION" -p $SERVER_HOST_PORT:$SERVER_CONTAINER_PORT $SERVER_APP_TAG

 **************************************************************************************************************************
 *                                Building new Image for Server application.                                              *
 **************************************************************************************************************************

Sending build context to Docker daemon    917kB
Step 1/18 : FROM node:8.9.3
 ---> f9e6e2b63af8
Step 2/18 : FROM keymetrics/pm2:latest
 ---> ecf82a5539fe
Step 3/18 : RUN mkdir -p /usr/app/test/src
 ---> Running in 12073977da7d
 ---> 260d59357d50
Removing intermediate container 12073977da7d
Step 4/18 : COPY ./package.json /usr/app/test/
 ---> 3c2ec0416378
Removing intermediate container 19e1cee36801
Step 5/18 : WORKDIR /usr/app/test
 ---> 2d2ef31590b8
Removing intermediate container 7319b8128a8d
Step 6/18 : RUN npm install
 ---> Running in 9cd9e93ca594
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN TestAppServer@0.0.1 No license field.

added 241 packages in 5.499s
 ---> b61b4b2182a6
Removing intermediate container 9cd9e93ca594
Step 7/18 : COPY ./src/ /usr/app/test/src/
 ---> 64a084bff28d
Removing intermediate container 0f332e0cab6c
Step 8/18 : WORKDIR /usr/app/test/src
 ---> d100f96f698a
Removing intermediate container 22fcf501f912
Step 9/18 : RUN mkdir -p /usr/app/test/logs
 ---> Running in 5cd102966889
 ---> 305d47b02bdc
Removing intermediate container 5cd102966889
Step 10/18 : RUN chmod 744 -R /usr/app/test/*
 ---> Running in 2bdb90b9ed35
 ---> 443be2f95f26
Removing intermediate container 2bdb90b9ed35
Step 11/18 : RUN pm2 install pm2-logrotate
 ---> Running in 10f9de92d7bb

                        -------------

__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
 _\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
  _\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
   _\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
    _\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
     _\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
      _\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
       _\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
        _\///______________\///______________\///__\///////////////__


                          Community Edition

            Production Process Manager for Node.js applications
                     with a built-in Load Balancer.


                Start and Daemonize any application:
                $ pm2 start app.js

                Load Balance 4 instances of api.js:
                $ pm2 start api.js -i 4

                Monitor in production:
                $ pm2 monitor

                Make pm2 auto-boot at server restart:
                $ pm2 startup

                To go further checkout:
                http://pm2.io/


                        -------------

[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
[PM2][Module] Installing module pm2-logrotate
[PM2][Module] Calling [YARN] to install pm2-logrotate ...
yarn add v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.1.3: The platform "linux" is incompatible with this module.
info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 135 new dependencies.
├─ amp-message@0.1.2
├─ amp@0.3.1
├─ ansi-regex@2.1.1
├─ ansi-styles@2.2.1
├─ anymatch@1.3.2
├─ argparse@1.0.9
├─ arr-diff@2.0.0
├─ arr-flatten@1.1.0
├─ array-unique@0.2.1
├─ async-each@1.0.1
├─ async-listener@0.6.8
├─ async@1.5.2
├─ balanced-match@1.0.0
├─ binary-extensions@1.11.0
├─ blessed@0.1.81
├─ brace-expansion@1.1.8
├─ braces@1.8.5
├─ chalk@1.1.3
├─ charm@0.1.2
├─ chokidar@1.7.0
├─ cli-table-redemption@1.0.1
├─ commander@2.11.0
├─ concat-map@0.0.1
├─ continuation-local-storage@3.2.1
├─ core-util-is@1.0.2
├─ cron-parser@2.4.3
├─ cron@1.3.0
├─ debug@3.1.0
├─ define-properties@1.1.2
├─ emitter-listener@1.1.1
├─ escape-regexp@0.0.1
├─ escape-string-regexp@1.0.5
├─ eventemitter2@1.0.5
├─ expand-brackets@0.1.5
├─ expand-range@1.8.2
├─ extend@3.0.1
├─ extglob@0.3.2
├─ fclone@1.0.11
├─ filename-regex@2.0.1
├─ fill-range@2.2.3
├─ for-in@1.0.2
├─ for-own@0.1.5
├─ foreach@2.0.5
├─ fs.realpath@1.0.0
├─ gkt@1.0.0
├─ glob-base@0.3.0
├─ glob-parent@2.0.0
├─ glob@7.1.2
├─ graceful-fs@4.1.11
├─ has-ansi@2.0.0
├─ iconv-lite@0.4.19
├─ inflight@1.0.6
├─ inherits@2.0.3
├─ interpret@1.1.0
├─ is-binary-path@1.0.1
├─ is-buffer@1.1.6
├─ is-dotfile@1.0.3
├─ is-equal-shallow@0.1.3
├─ is-extendable@0.1.1
├─ is-extglob@1.0.0
├─ is-glob@2.0.1
├─ is-nan@1.2.1
├─ is-number@2.1.0
├─ is-posix-bracket@0.1.1
├─ is-primitive@2.0.0
├─ is@3.2.1
├─ isarray@1.0.0
├─ isobject@2.1.0
├─ json-stringify-safe@5.0.1
├─ kind-of@3.2.2
├─ lazy@1.0.11
├─ lodash.findindex@4.6.0
├─ lodash.isequal@4.5.0
├─ lodash.merge@4.6.0
├─ lodash@4.17.4
├─ long-timeout@0.1.1
├─ methods@1.1.2
├─ micromatch@2.3.11
├─ minimatch@3.0.4
├─ minimist@0.0.8
├─ mkdirp@0.5.1
├─ moment-timezone@0.5.14
├─ moment@2.19.3
├─ ms@2.0.0
├─ mute-stream@0.0.7
├─ needle@1.6.0
├─ node-schedule@1.2.5
├─ normalize-path@2.1.1
├─ nssocket@0.6.0
├─ object-keys@1.0.11
├─ object.omit@2.0.1
├─ once@1.4.0
├─ parse-glob@3.0.4
├─ path-is-absolute@1.0.1
├─ path-parse@1.0.5
├─ pidusage@1.2.0
├─ pm2-axon-rpc@0.5.0
├─ pm2-axon@3.1.0
├─ pm2-deploy@0.3.9
├─ pm2-logrotate@2.4.0
├─ pm2-multimeter@0.1.2
├─ pm2@2.8.0
├─ pmx@1.5.5
├─ preserve@0.2.0
├─ process-nextick-args@1.0.7
├─ promptly@2.2.0
├─ randomatic@1.1.7
├─ read@1.0.7
├─ readable-stream@2.3.3
├─ readdirp@2.1.0
├─ rechoir@0.6.2
├─ regex-cache@0.4.4
├─ remove-trailing-separator@1.1.0
├─ repeat-element@1.1.2
├─ repeat-string@1.6.1
├─ resolve@1.5.0
├─ safe-buffer@5.1.1
├─ semver@5.4.1
├─ set-immediate-shim@1.0.1
├─ shelljs@0.7.8
├─ shimmer@1.2.0
├─ sorted-array-functions@1.0.0
├─ source-map-support@0.5.0
├─ source-map@0.6.1
├─ sprintf-js@1.1.1
├─ string_decoder@1.0.3
├─ strip-ansi@3.0.1
├─ supports-color@2.0.0
├─ tv4@1.3.0
├─ util-deprecate@1.0.2
├─ uuid@3.1.0
├─ vizion@0.2.13
├─ vxx@1.2.2
├─ wrappy@1.0.2
└─ yamljs@0.3.0
Done in 4.48s.
[PM2][Module] Module downloaded
[PM2][WARN] Applications pm2-logrotate not running, starting...
[PM2] App [pm2-logrotate] launched (1 instances)
== pm2-logrotate ==
┌────────────────┬─────────────────────┐
│ key            │ value               │
├────────────────┼─────────────────────┤
│ max_size       │ 10M                 │
│ retain         │ all                 │
│ compress       │ false               │
│ dateFormat     │ YYYY-MM-DD_HH-mm-ss │
│ workerInterval │ 30                  │
│ rotateInterval │ 0 0 * * *           │
│ rotateModule   │ true                │
└────────────────┴─────────────────────┘
[PM2][Module] Module successfully installed and launched
[PM2][Module] Edit configuration via: `pm2 conf`
┌──────────┬────┬──────┬─────┬────────┬─────────┬────────┬─────┬─────┬──────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
└──────────┴────┴──────┴─────┴────────┴─────────┴────────┴─────┴─────┴──────┴──────────┘
 Module activated
┌───────────────┬─────────┬────────────┬────────┬─────────┬─────┬─────────────┬──────┐
│ Module        │ version │ target PID │ status │ restart │ cpu │ memory      │ user │
├───────────────┼─────────┼────────────┼────────┼─────────┼─────┼─────────────┼──────┤
│ pm2-logrotate │ N/A     │ N/A        │ online │ 0       │ 0%  │ 22.629 MB   │ root │
└───────────────┴─────────┴────────────┴────────┴─────────┴─────┴─────────────┴──────┘
 Use `pm2 show <id|name>` to get more details about an app
 ---> cf75815d40cf
Removing intermediate container 10f9de92d7bb
Step 12/18 : RUN pm2 set pm2-logrotate:compress true
 ---> Running in 49bb4d0e6a32
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
[PM2][Module] Starting module pm2-logrotate
[PM2][WARN] Applications pm2-logrotate not running, starting...
[PM2] App [pm2-logrotate] launched (1 instances)
[PM2] Module pm2-logrotate restarted
== pm2-logrotate ==
┌────────────────┬─────────────────────┐
│ key            │ value               │
├────────────────┼─────────────────────┤
│ max_size       │ 10M                 │
│ retain         │ all                 │
│ compress       │ true                │
│ dateFormat     │ YYYY-MM-DD_HH-mm-ss │
│ workerInterval │ 30                  │
│ rotateInterval │ 0 0 * * *           │
│ rotateModule   │ true                │
└────────────────┴─────────────────────┘
 ---> 4b1ef47bfbf3
Removing intermediate container 49bb4d0e6a32
Step 13/18 : RUN pm2 set pm2-logrotate:retain 2
 ---> Running in 922668e67bf8
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
[PM2][Module] Starting module pm2-logrotate
[PM2][WARN] Applications pm2-logrotate not running, starting...
[PM2] App [pm2-logrotate] launched (1 instances)
[PM2] Module pm2-logrotate restarted
== pm2-logrotate ==
┌────────────────┬─────────────────────┐
│ key            │ value               │
├────────────────┼─────────────────────┤
│ max_size       │ 10M                 │
│ retain         │ 2                   │
│ compress       │ true                │
│ dateFormat     │ YYYY-MM-DD_HH-mm-ss │
│ workerInterval │ 30                  │
│ rotateInterval │ 0 0 * * *           │
│ rotateModule   │ true                │
└────────────────┴─────────────────────┘
 ---> da9cfb030216
Removing intermediate container 922668e67bf8
Step 14/18 : ARG NODE=production
 ---> Running in 6adf3b3448c4
 ---> 15ac281ba1c4
Removing intermediate container 6adf3b3448c4
Step 15/18 : ENV NODE_ENV ${NODE}
 ---> Running in cc0f9d075b5d
 ---> 56a2a3b5a1aa
Removing intermediate container cc0f9d075b5d
Step 16/18 : EXPOSE 443
 ---> Running in 87a5cb112a8b
 ---> dd76b918243e
Removing intermediate container 87a5cb112a8b
Step 17/18 : CMD pm2-docker start pm2.json
 ---> Running in 0776c21be437
 ---> ff81b9c101f3
Removing intermediate container 0776c21be437
Step 18/18 : LABEL com.app.Test ''
 ---> Running in 976599861b1d
 ---> db2ea4ba5fa2
Removing intermediate container 976599861b1d
Successfully built db2ea4ba5fa2
Successfully tagged Test-server:1.6.0


*********Successfully build Image for Server Application***************


 **************************************************************************************************************************
 *                                Starting containter for Server application.                                             *
 **************************************************************************************************************************

1a972236bf07744abf2a1813a3b00e22b1bb0f8597f88e43588b1fa24ff4f26f


*********Server Application Containter started successfully.***************

我们的Docker文件

ubuntu@(DEV):$docker ps -a

CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                                      NAMES
9ff46fa26446        test-client:1.6.0   "httpd-foreground"       6 minutes ago       Up 6 minutes        0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   test-client_1.6.0
1a972236bf07        test-server:1.6.0   "pm2-docker start ..."   6 minutes ago       Up 6 minutes        80/tcp, 43554/tcp, 0.0.0.0:9443->443/tcp   test-server_1.6.0


ubuntu@(DEV):$ docker exec -it 1a972236bf07 sh


/usr/app/test/server/src # node --version
v9.2.1
/usr/app/test/server/src #

我们从shell脚本内部构建映像,命令和输出位于

之下
  int countQA(char[][] c){

  int count=0;
  for(i=0;i<c.length-1;i++)
    for(j=0;j<c.length-1;j++){
      if(c[i][j]=='q'){
         if(c[i][j+1]=='a'){
         count++;}
         if(c[i+1][j]=='a'){
         count++;} 


                     }
                             }

           return count;}

构建映像并创建容器后。

/usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require': cannot load such file -- bundler (LoadError)

from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
        from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
        from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.16.0/exe/bundle:10:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-2.3.1/bin/bundle:23:in `load'
        from /usr/local/rvm/gems/ruby-2.3.1/bin/bundle:23:in `<main>'
        from /usr/local/rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
        from /usr/local/rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'

3 个答案:

答案 0 :(得分:0)

嗯 - 适合我:

➜  ~ docker run node:8 node --version
v8.9.3

我认为发生了两件事之一:

  1. Dockerfile中的某些内容正在升级节点
  2. 您没有在容器中运行node --version,而是错误地在本地计算机上运行它。
  3. 要么仔细检查你做了正确的事情并使用上面的命令,就像我一样 - 或者发布你的完整Dockerfile并让我们看看发生了什么。

答案 1 :(得分:0)

它是最有可能的第二个,Docker文件中的重复FROM或多或少被认为是一个bug而不是Docker的一个功能部分,虽然它看起来像是计划保持原样一些有限的用例:

Multiple FROMs - what it means

keymetrics / pm2:最新版本可能在节点v8.9.3

答案 2 :(得分:0)

感谢您的澄清。你是对的,它是第二个安装最新版本的Node JS的FROM。我删除了另一个FROM并将其更改为

{{1}}

现在一切都很好