Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Docker multi-container example

Example python app using multiple docker containers

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set docker-cs-multi-container-app
cd pulumi-examples/docker-cs-multi-container-app

This example Pulumi application runs two containers locally, one Redis container and one built from the application in the App folder. The application queries the Redis database and returns the number of times the page has been viewed.

Prerequisites#

  1. Install Pulumi
  2. Install .NET
  3. Install Docker and have it running

Deploying the example#

  1. Create a new stack, which is an isolated deployment target for this example:

    Terminal window
    pulumi stack init dev
  2. Preview and deploy the app via pulumi up. The preview will take a few minutes, as it builds a Docker container.

    Terminal window
    pulumi up
    Updating (dev)
    View Live: https://app.pulumi.com/acmecorp/docker-cs-multi-container-app/dev/updates/1
    Type Name Status
    + pulumi:pulumi:Stack docker-cs-multi-container-app-dev created
    + ├─ docker:image:Image AppImage create
    + ├─ docker:index:RemoteImage RedisImage create
    + ├─ docker:index:Network network create
    + ├─ docker:index:Container RedisContainer create
    + └─ docker:index:Container AppContainer create
    Outputs:
    Url: "http://localhost:8080/Cache"
    Resources:
    + 6 created
    Duration: 21s
  3. View the endpoint URL, and run curl:

    Terminal window
    pulumi stack output
    curl $(pulumi stack output Url)
    Current stack outputs (1)
    OUTPUT VALUE
    Url http://localhost:8080/Cache
    I have been viewed 1 times
  4. Repeat the previous command multiple times to see the number of views increase.

Cleaning up#

Once you are done, you can destroy all of the resources, and the stack:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.