Docker- Production Workflow

Contents

Some notes about the development, testing and deployment workflow of docker


In Development In Production
1
2
3
Docker Container

  npm run start
1
2
3
Docker Container

  npm run build

for development
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
FROM node:alpine

WORKDIR '/app'

COPY package.json .
RUN npm install

COPY . .

CMD ["npm", "run", "start"]

Could be run using
1
2
docker build -f Dockerfile.dev .
docker run -p 3000:3000 <imageID>
1
docker run -p 3000:3000 -v /app/node_modules -v $(pwd):/app <imageID>
  1. Map the pwd into the ‘/app’ folder
  2. Put a bookmark on the node_modules folder, do not map to outside folder
1
winpty docker run -it -p 3000:3000 -v /app/node_modules -v "/$(PWD)":/app CONTAINER_ID
1
docker run -it -p 3000:3000 -v /app/node_modules -v ${pwd}:/app CONTAINER_ID


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
version: '3'
services:
  web:
    stdin_open: true
    environment:
      - CHOKIDAR_USEPOLLING=true
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - '3000:3000'
    volumes:
      - /app/node_modules
      - .:/app


1
docker run -it <imageID> npm run test

1
docker exec -it <containerID> npm run test

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
version: '3'
services:
  web:
    stdin_open: true
    environment:
      - CHOKIDAR_USEPOLLING=true
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - '3000:3000'
    volumes:
      - /app/node_modules
      - .:/app
  tests:
    stdin_open: true
    build:
      context: .
      dockerfile: Dockerfile.dev
    volumes:
      - /app/node_modules
      - .:/app
    command: ['npm', 'run', 'test']

1
2
docker ps
docker attach <tests_containerID>


1
2
3
4
5
6
7
8
9
FROM node:alpine
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
RUN npm run build

FROM nginx
COPY --from=0 /app/build /usr/share/nginx/html

To run

1
2
docker build .
docker run -p 8080:80 <imageID>
No comment yet.
Powered By Valine
v1.4.14