我对Docker比较陌生。而且非常棒。
嗯,我理解像PHP这样的语言。我认为使用Docker确实有意义,因为PHP环境。
但是为什么我需要在Node.js上使用docker,而我可以简单地'npm install'和'npm start'而且我已经完成了。
我相信我在这里错过了一些东西。我错过了什么?
答案 0 :(得分:0)
值得注意的要点是所有应用程序都依赖于机器构建。可以在控制台上启动简单的应用程序(在Node或PHP或任何东西中),但它们仍然需要服务器和包管理器。
该列表可能包含以下任何内容:
这是我最近写的一个Dockerfile(用于一组相对简单的功能测试):
# 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 g-w /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"]
这是非常冗长的,当然我每次进行全新部署时都不想重复。