Docker for QA
Setup postman collection to run in container
Install docker desktop for 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. These tests created for 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 inside container
5. Create image based on this docker file. node_newman is the name of new image that will be stored locally
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
An alternative way to setup all needed soft to container we could use following docker file
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 (Node + Mongo) application will be used as an example.
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.
2. Create image based on this docker file. node-app is the name of new image and latest is a tag.
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
To check that container is running use the following command.
4. Node app can now be accessed by the address http://localhost:3000/. But is still required DB to work properly.
5. Create docker-compose file inside the same folder.
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
It will create the containers and then start them.
Now the application is available here http://localhost:3001/accounts
Last updated
Was this helpful?