为什么我需要Docker for nodejs?

我对Docker相对来说比较新。 这真是太神奇了。

那么,我明白,像PHP这样的语言。 我认为使用Docker确实有意义,因为PHP环境。

但是,为什么我需要使用docker的Node.js,而我可以简单地'npm安装'和'npm开始',我都完成了。

我想我在这里错过了一些东西。 我错过了什么?

值得注意的主要问题是所有的应用程序都依赖于机器构build。 简单的应用程序(在节点或PHP或任何其他)可以在控制台上启动,但他们仍然需要一个服务器和一个包pipe理器。

该列表可能包含以下任何一项:

  • 基本服务器的select是为了平衡速度,图像大小,安全方式或更新谨慎性(Ubuntu的function,CentOS谨慎,Alpine的图像大小等)
  • 运行时软件,如PHP,Apache,NginX,Node等
  • 服务器写入权限设置在内部caching文件夹上
  • 安装一个特定版本的cURL
  • 本地caching或队列安装(Redis,Memcache等)
  • 安装了特定的PHP扩展,如数据库扩展(或另一种语言的系统等效)
  • 用户帐户
  • 包装pipe理软件,如Composer和NPM
  • 您的应用程序,从版本控制或生成服务器获取
  • 为您的应用程序安装软件包
  • 安装字体
  • 设置时区和本地化

这里是我最近写的一个Dockerfile(用于一套相对简单的functiontesting):

 # Docker build script for the Command Agent system FROM ubuntu # Do a system update RUN apt-get update && apt-get install -y # Basic dependencies RUN apt-get install -y git openssl # Install PHP # Composer needs openssl, json, phar, iconv/mbstring # Composer recommends zlib # PHPUnit needs dom, mbstring RUN apt-get install -y php php-json php-phar php-mbstring php-dom php-zip # @todo What names are php-ssl and php-zlib under? # Install SSH server # Expect is to handle tty automation # Netcat is required to send messages RUN apt-get install -y openssh-server expect netcat RUN adduser --disabled-password --gecos "" nonpriv # It looks like passwordless access does not work unless the user has a password! RUN echo 'nonpriv:Password123' | chpasswd # We need to be able to ask for a root password (so lets give it one) RUN echo 'root:Password123' | chpasswd # Copy over installation scripts COPY install /tmp/install RUN chmod u+rx /tmp/install/_*.sh && \ chown -R nonpriv:nonpriv /tmp/install # Install Composer # See https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md RUN cd /tmp && sh /tmp/install/composer.sh # Copy dependendencies COPY composer.json /root/command-agent/composer.json COPY composer.lock /root/command-agent/composer.lock # Install deps using Composer (include dev deps) # @todo Don't run composer as root, https://getcomposer.org/root RUN cd /root/command-agent && php /tmp/composer.phar install # Apply patch to PHPUnit. This is a bit hacky, but the only way I can see to # fully turn off output buffering. Unfortunately these methods are private, # so standard approaches to removing them (an override method) would not work. # The only other alternative is using runkit, and I think that might be +more+ # hacky :) COPY patch /root/command-agent/patch RUN patch -p1 \ /root/command-agent/vendor/phpunit/phpunit/src/Framework/TestCase.php \ /root/command-agent/patch/disable_ob.patch # Copy code COPY bin /root/command-agent/bin COPY src /root/command-agent/src COPY test /root/command-agent/test COPY entry-point.sh /root/command-agent/entry-point.sh COPY expect.sh /root/command-agent/expect.sh COPY phpunit.xml /root/command-agent/phpunit.xml RUN ln -s /root/command-agent/vendor/bin/phpunit /root/command-agent/phpunit # Allow non-priv user to read/exec root files RUN chown -R root:nonpriv /root && \ chmod -R gw /root && \ chmod -R g+rx /root # This should be privileged access only COPY test/functional/assets/agent_auth /root/.agent_auth COPY test/functional/assets/agent_auth_wrong /root/.agent_auth_wrong COPY test/functional/assets/bad_perms_agent_auth /root/.bad_perms_agent_auth RUN chmod 400 /root/.agent_auth* # Run tests ENTRYPOINT ["sh", "/root/command-agent/entry-point.sh"] 

这是相当漫长的,当然我不想重复每一次重新部署。