Skip to content

Optimized Dockerfile for refactoring & production #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: step3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*npm-debug.*
17 changes: 17 additions & 0 deletions test-database/startup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
REM This bat file should be run only in command prompt [cmd]; will fail in PowerShell
REM Run the MySQL container, with a database named 'users' and credentials
REM for a users-service user which can access it.
echo "Starting DB..."
docker run --name db -d ^
-e MYSQL_ROOT_PASSWORD=123 ^
-e MYSQL_DATABASE=users -e MYSQL_USER=users_service -e MYSQL_PASSWORD=123 ^
-p 3306:3306 ^
mysql:latest

REM Wait for the database service to start up.
echo "Waiting for DB to start up..."
docker exec db mysqladmin --silent --wait=50 -uusers_service -p123 ping || exit 1

REM Run the setup script.
echo "Setting up initial data..."
docker exec -i db mysql -uusers_service -p123 users < setup.sql
22 changes: 15 additions & 7 deletions users-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# Use Node v4 as the base image.
FROM node:4

# Add everything in the current directory to our image, in the 'app' folder.
ADD . /app
# Add our user and group first to make sure their IDs get assigned consistently
RUN groupadd -r app && useradd -r -g app app

# Install dependencies
RUN cd /app; \
npm install --production
# To reduce the build time during development we ensure non-changing layers comes first
#Creating a workdirectory
WORKDIR /app

# Expose our server port.
EXPOSE 8123

# Run our app.
CMD ["node", "/app/index.js"]
# Set the default command to run when a container starts
CMD ["npm", "start"]

# Install app dependencies
COPY package.json /app
RUN npm install --production

# Using the recommended COPY command instead of ADD. COPY everything
# in the current directory to our image, in the 'app' folder.
COPY . /app