turnbullpress / dockerbook-code

The code and configuration examples from The Docker Book (http://www.dockerbook.com)
930 stars 581 forks source link

nodejs container fails based on nodejs image #52

Closed brunojppb closed 5 years ago

brunojppb commented 5 years ago

Book version: v18.03.1-ce

When generating the nodejs image on Chapter 6: Building services with Docker, based on the book snippet, the nodejs version installed is 4.
the express app don't run on it.

Current book snippet

FROM ubuntu:16.04
LABEL maintainer="james@example.com"
ENV REFRESHED_AT 2016-06-01
RUN apt-get -yqq update
RUN apt-get -yqq install nodejs npm
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN mkdir -p /var/log/nodeapp
ADD nodeapp /opt/nodeapp/
WORKDIR /opt/nodeapp
RUN npm install
VOLUME [ "/var/log/nodeapp" ]
EXPOSE 3000
ENTRYPOINT [ "nodejs", "server.js" ]

To run the app container, I had to update node version to 10

My Dockerfile update

FROM ubuntu:16.04
LABEL maintainer="bruno@example.com"
ENV REFRESHED_AT 2018-12-02

RUN apt-get -yqq update
RUN apt-get -yqq install curl build-essential
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash
# nodejs package already includes npm
RUN apt-get install -y nodejs

# check node version
RUN echo $(nodejs -v)
# Create logs folder
RUN mkdir -p /var/log/nodeapp
# Add our local nodeapp folder to opt
ADD nodeapp /opt/nodeapp/
# use opt path as our working directory
WORKDIR /opt/nodeapp/
# install app dependencies
RUN npm install
# map the logs folder to a persistent volume in the host machine
VOLUME [ "/var/log/nodeapp" ]
# expose express app port
EXPOSE 3000
# fire-up node app
ENTRYPOINT [ "nodejs", "server.js" ]
jamtur01 commented 5 years ago

Thanks! This is already fixed in the current code.