gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 19:10:09 26 4
gpt4 key购买 nike

尝试创建一个具有 Python3 和 Node v4.4.7 的 docker 镜像,以便我可以将其用作需要 Python 和该版本 Node.js 的项目的容器。

# 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"]

当我第一次尝试时,它提示没有运行 python 脚本,所以添加了一个基本的 python 文件: hello.py就是这样:
print "Hello, Python!"

然后它提示没有 requirements.txt文件所以添加了一个空的 requirements.txt
现在当我运行 docker build -t isaacweathersnet/sampledockerimage .它在 Node 安装过程中出现困惑
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

最佳答案

在 Github 上找到了具有 Python 和 Node.js 的解决方案。 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"]

关于python - 使用 Nodev4.4.7 和 Python3 创建 Docker 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40872544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com