> For the complete documentation index, see [llms.txt](https://interlink.gitbook.io/process/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://interlink.gitbook.io/process/qa-1/qa/setup-postman-collection-to-run-in-ci-cd.md).

# Docker for QA

## Setup postman collection to run in container

1. [Install docker desktop for Windows](https://hub.docker.com/editions/community/docker-ce-desktop-windows) in case you don't have one.

2\. Create or get existing postman collection with some tests. Export this collection to JSON. Note: in case postman environments were used - it should be also exported to JSON file.\
[Example collection + environment.](https://nas.in6k.com/share.cgi?ssid=0zOzukz)\
These tests created for [rest-meetup.in6k.com](https://rest-meetup.in6k.com/) service. Ask TSD to launch it if needed.

3\. Save both postman files in one folder.

4\. Create docker file and put into the same folder: \
**FROM** - docker image with newman installed.\
**RUN** - command to install [newman-reporter-html ](https://www.npmjs.com/package/newman-reporter-html)inside container

```
FROM postman/newman:alpine
RUN npm install --global newman-reporter-html
```

5\. Create image based on this docker file.\
**node\_newman** is the name of new image that will be stored locally

```bash
docker build -t node_newman .
```

6\. Run the following command in command line. It will mount your folder with collections **D:/docker\_workshop/** to the folder inside container **/etc/newman.**\
**-t node\_newman** tells that we're going to use our image.\
**run Docker.postman\_collection.json --environment="Docker\_workshop.postman\_environment.json"** - tells which collection to run and what environment file to use \
**--reporters html** - tells what tool to use for reports generation

```bash
docker run -v D:/docker_workshop/:/etc/newman -t andriis_newman run Docker.postman_collection.json --environment="Docker_workshop.postman_environment.json" --reporters html
```

An alternative way to setup all needed soft to container we could use following docker file

```bash
FROM node
RUN npm install --global newman newman-reporter-htmlextra
WORKDIR /etc/newman
ENTRYPOINT ["newman"]
```

As a base we take node and then install **newman** and **newman-reporter-htmlextra**\
**WORKDIR /etc/newman** - change current directory once after container is launched\
**ENTRYPOINT \["newman"]** - tells that all commands passed after docker run will be passed directly to newman

## Docker compose

In this section we'll describe how to run application (in our case node-mongoose-app) in container.

[node-mongoose](https://nas.in6k.com/share.cgi?ssid=0NihdBE) (Node + Mongo) application will be used as an example.

1. Go to the app folder and create docker file\
   **COPY . .** will copy all files from current local folder into the /node-app folder inside container.\
   **RUN npm install** will install all required dependencies for the app inside container.

```bash
FROM node:10.16.0
WORKDIR /node-app
COPY . .
RUN npm install
```

2\. Create image based on this docker file.\
&#x20;    **node-app** is the name of new image and **latest** is a tag.

```bash
docker build -t node-app:latest .
```

3\. Run application in a container.\
**node-app2** is a container name.\
**-p 3000:3000** ports mapping \<local port>:\<port inside container>\
**node-app:latest** - image that is running\
**npm start** - command to run node application

```bash
docker run -d --name node-app2 -p 3000:3000 node-app:latest npm start
```

To check that container is running use the following command.

```bash
docker ps
```

![](https://621469499-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lk33ExZ9AulnEh_PKUM%2F-MGIeyzzIvNyHi3fDmNZ%2F-MGIib6Y8pt5wP7jX5pq%2Fdocker_ps.png?alt=media\&token=f0bf554f-d8b9-49c9-8135-41d9f8f29f69)

4\. Node app can now be accessed by the address <http://localhost:3000/>. But is still required DB to work properly.

![](https://621469499-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lk33ExZ9AulnEh_PKUM%2F-MGIeyzzIvNyHi3fDmNZ%2F-MGIjkb7-QDXhXzM2zj9%2Flocalhost_app.png?alt=media\&token=ff0f9ab9-7e27-4589-a9e5-d16c1f6cc6cd)

5\. Create docker-compose file inside the same folder.

```bash
version: "2.1"
services: 
        db: 
            image: mongo
            container_name: mongo
            ports: 
                - 27017:27107
            environment: 
                - MONGO_INIT_DATABASE=test 
        app: 
            container_name: node-app
            build: .
            image: node-app:latest
            ports:
                - 3001:3000
            command: npm start
            depends_on:
                - db
        migrate:
            image: node-app:latest
            command: node ./migration/data-migration.js
            depends_on:
                - db
```

Here we have 3 services db, app and migrate.\
The first service to run is **db** as **app** and **migrate** depends on it (**depends\_on** key).\
DB will be started in a separate container with name **mongo.**\
Local port **27017** will be mapped to **27107** inside container.\
Default db name **test.**

App will be started in container **node-app**.\
**build: .** means that this container should be run using the docker file created previously.

Migration service will create all tables needed for the app.

6\. To run all containers use command&#x20;

```bash
docker-compose up
```

It will create the containers and then start them.

![](https://621469499-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lk33ExZ9AulnEh_PKUM%2F-MGIeyzzIvNyHi3fDmNZ%2F-MGIuDrqnc2xLagn_t0f%2Fdocker_compose.png?alt=media\&token=ade8df8b-74ad-41ed-a600-1d7e4280167d)

Now the application is available here <http://localhost:3001/accounts>
