github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/docs/_docs/02_testing-best-practices/iterating-locally-using-docker.md (about)

     1  ---
     2  layout: collection-browser-doc
     3  title: Iterating locally using Docker
     4  category: testing-best-practices
     5  excerpt: >-
     6    If you're writing scripts (i.e., Bash, Python, or Go), you should be able to test them locally using Docker. Docker containers typically build 10x faster and start 100x faster than real servers.
     7  tags: ["testing-best-practices", "docker"]
     8  order: 209
     9  nav_title: Documentation
    10  nav_title_link: /docs/
    11  ---
    12  
    13  For most infrastructure code, your only option is to deploy into a real environment such as AWS. However, if you're
    14  writing scripts (i.e., Bash, Python, or Go), you should be able to test them locally using Docker. Docker containers
    15  typically build 10x faster and start 100x faster than real servers, so using Docker for testing can help you iterate
    16  much faster.
    17  
    18  Here are some techniques we use with Docker:
    19  
    20  - If your script is used in a Packer template, add a [Docker
    21    builder](https://www.packer.io/docs/builders/docker.html) to the template so you can create a Docker image from the
    22    same code. See the [Packer Docker Example](https://github.com/gruntwork-io/terratest/tree/master/examples/packer-docker-example) for working sample code.
    23  
    24  - We have prebuilt Docker images for major Linux distros that have many important dependencies (e.g., curl, vim,
    25    tar, sudo) already installed. See the [test-docker-images folder](https://github.com/gruntwork-io/terratest/tree/master/test-docker-images) for more details.
    26  
    27  - Create a `docker-compose.yml` to make it easier to run your Docker image with all the ports, environment variables,
    28    and other settings it needs. See the [Packer Docker Example](https://github.com/gruntwork-io/terratest/tree/master/examples/packer-docker-example) for working sample code.
    29  
    30  - With scripts in Docker, you can replace _some_ real-world dependencies with mocks! One way to do this is to create
    31    some "mock scripts" and to bind-mount them in `docker-compose.yml` in a way that replaces the real dependency. For
    32    example, if your script calls the `aws` CLI, you could create a mock script called `aws` that shows up earlier in the
    33    `PATH`. Using mocks allows you to test 100% locally, without external dependencies such as AWS.