简体   繁体   English

使用Nodev4.4.7和Python3创建Docker容器

[英]Create Docker container with Nodev4.4.7 and Python3

Trying to create a docker image that has Python3 and Node v4.4.7 so that I can use it as a container for my project that needs both Python and that version of Node. 尝试创建具有Python3和Node v4.4.7的docker映像,以便可以将其用作需要Python和该版本的Node的项目的容器。

# Pull base image.
FROM python:3-onbuild

CMD [ "python", "./hello.py" ]
# Install Node.js
RUN \
cd /tmp && \
wget http://nodejs.org/dist/v4.4.7/node-v4.4.7.tar.gz && \
tar xvzf node-v4.4.7.tar.gz && \
rm -f node-v4.4.7.tar.gz && \
cd node-v* && \
./configure && \
CXX="g++ -Wno-unused-local-typedefs" make && \
CXX="g++ -Wno-unused-local-typedefs" make install && \
cd /tmp && \
rm -rf /tmp/node-v* && \
npm install -g npm && \
print '\n# Node.js\nexport PATH="node_modules/.bin:$PATH"' >>   /root/.bashrc

# Define working directory.
WORKDIR /data

# Define default command.
CMD ["bash"]

When I first tried it complained about not having a python script to run so added a basic python file: hello.py that just has this: 当我第一次尝试时,它抱怨没有python脚本运行,因此添加了一个基本的python文件: hello.py ,它具有以下内容:

print "Hello, Python!"

Then it complains about not having a requirements.txt file so added an empty requirements.txt 然后,它抱怨没有requirements.txt文件,因此添加了一个空的requirements.txt

Now when I run docker build -t isaacweathersnet/sampledockerimage . 现在当我运行docker build -t isaacweathersnet/sampledockerimage . it snafus during the node install with node-v4.4.0/benchmark/arrays/zero-int.js File "./configure", line 446 ''' ^ SyntaxError: Missing parentheses in call to 'print' The command '/bin/sh -c cd /tmp && wget http://nodejs.org/dist/v4.4.7/node-v4.4.7.tar.gz && tar xvzf node-v4.4.7.tar.gz && rm -f node-v4.4.7.tar.gz && cd node-v* && ./configure && CXX="g++ -Wno-unused-local-typedefs" make && CXX="g++ -Wno-unused-local-typedefs" make install && cd /tmp && rm -rf /tmp/node-v* && npm install -g npm && print '\\n# Node.js\\nexport PATH="node_modules/.bin:$PATH"' >> /root/.bashrc' returned a non-zero code: 1 在使用node-v4.4.0/benchmark/arrays/zero-int.js File "./configure", line 446 ''' ^ SyntaxError: Missing parentheses in call to 'print' The command '/bin/sh -c cd /tmp && wget http://nodejs.org/dist/v4.4.7/node-v4.4.7.tar.gz && tar xvzf node-v4.4.7.tar.gz && rm -f node-v4.4.7.tar.gz && cd node-v* && ./configure && CXX="g++ -Wno-unused-local-typedefs" make && CXX="g++ -Wno-unused-local-typedefs" make install && cd /tmp && rm -rf /tmp/node-v* && npm install -g npm && print '\\n# Node.js\\nexport PATH="node_modules/.bin:$PATH"' >> /root/.bashrc' returned a non-zero code: 1进行节点安装时,它node-v4.4.0/benchmark/arrays/zero-int.js File "./configure", line 446 ''' ^ SyntaxError: Missing parentheses in call to 'print' The command '/bin/sh -c cd /tmp && wget http://nodejs.org/dist/v4.4.7/node-v4.4.7.tar.gz && tar xvzf node-v4.4.7.tar.gz && rm -f node-v4.4.7.tar.gz && cd node-v* && ./configure && CXX="g++ -Wno-unused-local-typedefs" make && CXX="g++ -Wno-unused-local-typedefs" make install && cd /tmp && rm -rf /tmp/node-v* && npm install -g npm && print '\\n# Node.js\\nexport PATH="node_modules/.bin:$PATH"' >> /root/.bashrc' returned a non-zero code: 1

Found the solution on Github that had Python and Node. 在具有Python和Node的Github上找到解决方案。 No luck with Python 3+ but worked well with 2.7 https://github.com/nsdont/python-node/blob/master/Dockerfile Python 3+运气不好,但与2.7 https://github.com/nsdont/python-node/blob/master/Dockerfile兼容

FROM python:2.7

RUN \
cd /tmp && \
wget http://nodejs.org/dist/v4.4.7/node-v4.4.7.tar.gz && \
tar xvzf node-v4.4.7.tar.gz && \
rm -f node-v4.4.7.tar.gz && \
cd node-v* && \
./configure && \
CXX="g++ -Wno-unused-local-typedefs" make && \
CXX="g++ -Wno-unused-local-typedefs" make install && \
cd /tmp && \
rm -rf /tmp/node-v* && \
npm install -g npm && \
echo -e '\n# Node.js\nexport PATH="node_modules/.bin:$PATH"' >> /root/.bashrc

# Define working directory.
WORKDIR /data

# Define default command.
CMD ["bash"]

There are nodejs-python and python-nodejs (which is built on top of nodejy-python ). nodejs-pythonpython-nodejs (它们是在nodejy-python之上nodejy-python )。 It's worth to have a look into there. 值得一看。

python-nodejs provides Node 10.x , npm 6.x , yarn stable , Python latest , pip latest and pipenv latest . python-nodejs提供Node 10.xnpm 6.xyarn stablePython latestpip latestpipenv latest The versions used should be adjustable to your version needs. 使用的版本应可根据您的版本需求进行调整。 Use the Dockerfile as basis and adjust the RUN section 使用Dockerfile作为基础并调整RUN部分

RUN \
  echo "deb https://deb.nodesource.com/node_10.x stretch main" > /etc/apt/sources.list.d/nodesource.list && \
  wget -qO- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
  echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list && \
  wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
  apt-get update && \
  apt-get install -yqq nodejs yarn && \
  pip install -U pip && pip install pipenv && \
  npm i -g npm@^6 && \
rm -rf /var/lib/apt/lists/*

to the Node version you need. 到所需的Node版本。 The yarn (dependency management alternative to nmp ) and in case you need yarn) part can be removed. 可以除去yarn (如果需要纱线,可以使用nmp替代依赖管理)部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM