Docker Lesson 6 — Creating a Production-Grade Workflow

Yao-Shang Tseng
Sep 9, 2018 · 2 min read

It’s the note for Docker and Kubernetes: The Complete Guide
https://www.udemy.com/docker-and-kubernetes-the-complete-guide/

Development  ->  Testing  ->  Deployment -> ...(circle)--
Dev - Create / Change features
- Make changes on a non-master branch

* Push to github
* Create Pull Request to merge with master
Test - Code pushed to Travis CI
- Tests run

* Merge PR with master
Prod - Code pushed to Travis CI
- Tests run

- Deploy to AWS Elastic Beanstalk
--Something to notice...
- Last diagram didn't mention anything about Docker!
- Docker is a tool in a normal development flow
- Docker makes some of these tasks a lot easier
--npm run start => Starts up a development server. For development
use only
npm run test => Runs tests associated with the project
npm run build => Builds a production version of the application
--In Development
- Docker Container
- npm run start
In Production
- Docker Container
- npm run build

--
$ docker build -f <dockerfilename> .EXAMPLE:$ docker build -f Dockerfile.dev .--volume
# -v /app/node_modules => put a bookmark on the node_modules
folder
# -v $(pwd):/app => Map the pwd into the '/app' folder
$ docker run -p 3000:3000 -v /app/node_modules -v $(pwd):/app <image_id>--$ docker run -it b8cv8ddjsufos npm run test--$ docker attach <container id>--$ docker exec -it <container id> sh

Practice Steps

Build Phase

  • Use node:alpine
  • Copy the package.json file
  • Install dependencies
  • Run npm run build
  • Start nginx

Run Phase

  • Use nginx
  • Copy over the result of npm run build
  • Start nginx
DockerfileFROM node:alpine as builder
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
FROM nginx
COPY --from=builder /app/build /usr/share/nginx/html

--
$ docker build .
$ docker run -p 8080:80 9c476209a066
--
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade