Skip to content

Commit d84accc

Browse files
committed
Improve the Docker image
1. Bump Node version to 6.9 - the latest LTS 2. Include the `cpio` binary, used during building 3. Ignore node_modules and .git directories for faster builds 4. Run the tests and build during the image build, to make sure the image is not built if these break 5. Make npm run dev the default command 6. Add an entrypoint to automatically install Node modules if they do nott exist Signed-off-by: Antonis Kalipetis <akalipetis@gmail.com>
1 parent 10f5681 commit d84accc

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.git

Dockerfile

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
FROM node:4-onbuild
1+
FROM node:6.9
22
MAINTAINER Paris Kasidiaris <paris@sourcelair.com>
33

4-
EXPOSE 3000
4+
# Install cpio, used for building
5+
RUN apt-get update \
6+
&& apt-get install -y --no-install-recommends cpio \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Set the working directory
10+
WORKDIR /usr/src/app
11+
12+
# Set an entrypoint, to automatically install node modules
13+
COPY entrypoint.sh /entrypoint.sh
14+
ENTRYPOINT ["/entrypoint.sh"]
15+
16+
# First, install dependencies to improve layer caching
17+
COPY package.json /usr/src/app/
18+
RUN npm install
19+
20+
# Add the code
21+
COPY . /usr/src/app
22+
23+
# Run the tests and build, to make sure everything is working nicely
24+
RUN npm run test && npm run build
25+
CMD ["npm", "run", "dev"]

docker-compose.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '2'
2+
3+
services:
4+
web:
5+
build: ./
6+
volumes:
7+
- ./:/usr/src/app
8+
ports:
9+
- 3000:3000

entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#! /bin/bash
2+
3+
# Install Node modules, if the `node_modules` directory does not exist
4+
if [[ ! -d node_modules ]]; then
5+
npm install;
6+
fi
7+
8+
exec "$@"

0 commit comments

Comments
 (0)