1

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.

# 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:

print "Hello, Python!"

Then it complains about not having a requirements.txt file so added an empty requirements.txt

Now when I run 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

isaac weathers
  • 1,436
  • 4
  • 27
  • 52
  • 1
    you have 2 CMD in your Dockerfile, only the last one will be used. Maybe it should be RUN instead? Read http://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile – user2915097 Nov 29 '16 at 18:40
  • Thanks. That was probably it. Ended up using a different version of Python and a few mods and it worked. – isaac weathers Nov 29 '16 at 20:16

2 Answers2

1

Found the solution on Github that had Python and Node. No luck with Python 3+ but worked well with 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"]
isaac weathers
  • 1,436
  • 4
  • 27
  • 52
1

There are nodejs-python and python-nodejs (which is built on top of 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. The versions used should be adjustable to your version needs. Use the Dockerfile as basis and adjust the RUN section

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. The yarn (dependency management alternative to nmp) and in case you need yarn) part can be removed.

thinwybk
  • 4,193
  • 2
  • 40
  • 76