QA must learn Docker practical guide: complete teaching on test environment management, containerized testing, and CI/CD integration
Complete teaching of the Docker skills necessary for QA engineers, covering practical scenarios such as one-click startup of the test environment, containerized test execution, multi-environment management, CI/CD integration, etc., with instructions and setting examples that can be directly applied.
Last Updated:2026-05-24
Table of Contents
1. QA Why should you learn Docker?
Have you ever encountered these situations: "My test environment cannot be installed", "The staging environment has been modified by others", "This bug cannot be reproduced in my environment"? Docker solves these problems all at once. It packages the application and all dependencies into a "container". No matter which computer it is run on, the environment is exactly the same.
-
Environment Consistency: All Qa Test Environments Are Exactly The Same, No More Disputes About "It'S Okay On My Side"
-
One-Click Startup: Docker Compose Up Can Start The Complete Test Environment (Web + Db + Redis +...) With One Command
-
Environmental Isolation: Everyone Has Their Own Container Environment, Without Interfering With Each Other, And Without Fear Of Being Modified By Others.
-
Quick Reset: Something Wrong With Your Environment? Docker Compose Down && Docker Compose Up Rebuild A Clean One
-
Ci/Cd Integration: Use Docker To Run Tests In The Ci/Cd Pipeline, Which Is Completely Consistent With The Local Environment
2. Installation and basic concepts
Before you get started, you need to install Docker Desktop and understand three core concepts.
-
Installation: Go To Docker.Com To Download Docker Desktop (Supported By Mac/Windows/Linux), And You Can Use It After Installation.
-
Image: Just Like An Installation Cd, It Is A Template For Creating A Container. For Example, Postgres:16 Is The Image File Of Postgresql Version 16
-
Container: An Instance That Is Launched From An Image File, Just Like Installing It From A Cd To A Computer. Each Container Is An Independent Execution Environment
-
Docker Compose: Use One Yaml File To Define Multiple Containers (Web + Db + Redis), And Start Them All With One Command
-
Confirm Successful Installation: Docker --Version And Docker Compose Version
Tip
- Docker Desktop takes up a lot of memory (it is recommended that the computer has at least 8GB RAM). You can turn it off when not in use to save resources.
3. The most commonly used Docker commands for QA
QA only needs to use the following commands in daily life, and there is no need to learn how to create image files.
-
Start The Container: Docker Compose Up -D → Start All Services In The Background. -D Is Detach Mode (Does Not Occupy The Terminal)
-
Stop Containers: Docker Compose Down → Stop And Remove All Containers. Add -V To Clear Even Data
-
Check The Status: Docker Compose Ps → Check The Running Status Of All Containers (Whether They Are Healthy And Corresponding To The Port)
-
View Log: Docker Compose Logs Web → View The Log Of The Web Service. Add -F For Instant Tracking
-
Enter The Container: Docker Compose Exec Web Bash → Enter The Command Line Of The Web Container, Just Like Ssh Into The Server
-
Restart A Single Service: Docker Compose Restart Web → Only Restart Web, Without Affecting Other Services Such As The Database
-
Clean Up Space: Docker System Prune → Clean Up Unused Image Files And Containers To Free Up Disk Space
4. Practical combat: Using Docker Compose to build a test environment
The following is a typical QA test environment Docker Compose setup, including web application, database and Redis.
-
Docker-Compose.Yml Structure: Defines Services (Web, Db, Redis), Ports (External Port), Volumes (Data Persistence), Environment (Environment Variables)
-
Start The Complete Environment: Docker Compose Up -D → Start Web + Postgresql + Redis With One Command
-
Confirm That All Services Are Healthy: Docker Compose Ps Confirm That The Status Of All Containers Is Running/Healthy
-
Connection Test: Curl Http://Localhost:8080 To Test Whether The Web Responds Normally
-
Connect To The Database: Use Dbeaver To Connect To Localhost:5432 To Operate The Test Database
-
Reset The Environment: Docker Compose Down -V && Docker Compose Up -D → Completely Rebuild The Clean Environment
Tip
- Add docker-compose.yml to version control (Git) to ensure that all QA uses the same settings
- Environment variables (account and password, etc.) are managed using .env files, do not hard-code them in docker-compose.yml
5. Run automated tests in Docker
The biggest benefit of running tests with Docker is environment consistency - the results of running locally are the same as those running on CI/CD.
-
Execute The Test At One Time: Docker Compose Run --Rm Test Pytest Tests/ → Start A Temporary Container To Run Pytest, And It Will Be Automatically Removed After Running.
-
Parallel Testing: Use Multiple Containers To Run Different Test Suites At The Same Time To Shorten The Overall Testing Time
-
Browser Testing: Add Selenium Grid Or Playwright Container To Docker Compose And Run Ui Tests In The Container
-
Test Data Isolation: Use Docker Compose Down -V To Rebuild The Database Before Running Each Test To Ensure That Tests Do Not Interfere With Each Other.
-
Output Report: The Test Results Are Output To The Mounted Volume, Making It Easy To View The Report Outside The Container.
6. Multi-environment management: Dev/Staging/QA
Different environments have different settings (database connection, API URL, etc.), and Docker allows you to switch easily.
-
Use .Env Files To Switch: Create Three Files: .Env.Dev, .Env.Staging, And .Env.Qa. Specify When Starting: Docker Compose --Env-File .Env.Qa Up -D
-
Use The Override File: Docker-Compose.Override.Yml To Only Cover The Parts That Need To Be Changed, Leaving The Basic Settings Unchanged.
-
Environment Comparison: Run The Same Test In Containers In Different Environments And Compare The Differences In Results
-
Quick Switching: Alias Qa-Up='Docker Compose --Env-File .Env.Qa Up -D' → Customize Shortcut Commands To Switch Environments With One Click
7. Docker application in CI/CD
QA understands the role of Docker in CI/CD and can collaborate more effectively with DevOps teams.
-
Ci/Cd Test Process: Pr Establishment → Ci Starts The Docker Container → Runs Automated Testing → Produces Reports → Allows Merging If Passed
-
Github Actions Example: Use Services Block In .Github/Workflows To Define The Database And Redis Container Required For Testing
-
Automatic Deployment Of Test Environment: Each Pr Automatically Deploys An Independent Docker Environment For Manual Qa Testing, And The Pr Is Automatically Destroyed After Closing
-
Image File Version Tracking: Confirm That The Docker Image File Version Used By Ci/Cd Is Consistent With The Local One To Avoid "Ci Was Uploaded But Failed Locally"
Tip
- If your CI/CD test results are different from your local ones, 90% of the reasons are that the Docker image file version is inconsistent. Compare versions first
8. Frequently Asked Questions and Troubleshooting
QA The most common problems and solutions when using Docker.
-
Q: Port Conflict (Error: Port Is Already Allocated) → A: Use Docker Ps To Find The Container Occupying The Port, And Docker Stop To Stop It. Or Use Another Port
-
Q: The Container Stops Immediately After Starting → A: Docker Compose Logs Service_Name Look At The Log To Find The Reason. Usually The Setting Is Incorrect Or The Dependent Service Is Not Ready.
-
Q: Insufficient Disk Space → A: Docker System Prune -A Cleans Up All Unused Images And Containers. Regular Cleaning Is Important
-
Q: The Database Cannot Be Connected → A: Confirm That The Port Of The Db Container Is Correct And The Account Password Is Consistent With .Env. Test With Docker Compose Exec Db Psql -U User
-
Q: Docker Is Very Slow On Mac → A: Adjust Cpu And Memory Allocation In Docker Desktop Settings. You Can Also Consider Using Orbstack Instead (Faster And More Resource-Saving)
Key Takeaways
- 1 Docker solves the biggest pain point of QA - "it runs fine in my environment". The container ensures that everyone's test environment is consistent
- 2 After learning Docker, QA can start a complete test environment with one click and no longer rely on DevOps to help you set it up
- 3 This guide is organized according to the actual needs of QA. It does not cover all the functions of Docker, but only the parts that QA needs.
- 4 From basic instructions to Docker Compose multi-service orchestration, covering the complete scenarios of QA daily work
Related Links
Related Quick Guides
AI automated testing tools complete comparison 2026: Testim, mabl, Katalon AI and other 6 major tool reviews
An in-depth comparison of the top 6 AI automated testing tools in 2026, covering the functions, prices, and applicable scenarios of Testim, mabl, Katalon AI, Applitools, Codium AI, and Playwright AI.
AI-assisted testing practice: 5 scenarios to double your testing efficiency
From test case generation to visual regression, we will teach you step by step how to introduce AI tools into daily QA work, with practical steps and tool recommendations.
GitHub Copilot practical guide to writing test scripts: QA uses AI to write Playwright and Selenium tests
Teach QA engineers step-by-step how to use GitHub Copilot to write Playwright and Selenium automated test scripts, including Prompt techniques, practical cases, common pitfalls, and best practices.
General Disclaimer
The information provided on this site is for reference only. We do not guarantee its completeness or accuracy. Users should determine the applicability of the information on their own.