How to use Stripe CLI with Docker?

I would not like to advertise a foreign service here, but I will post a short development bootstrap for setting up your local environment with Stripe and Docker.

Stripe has pretty nice documentation about all possible implementations of payment for your products.

What comes very useful to me is their stripe-cli tool that allows you to implement webhooks integration with your application. Usually, you will need to choose some ssh tunneling tool for your machine like Ngrok to be able to do some local E2E testing. With stripe-cli you can do it for free.

Example how to use it

This is an example of my Docker Swarm YAML file that I am using for my local environment.

version: '3.7'

services:
  stripe-cli:
    image: stripe/stripe-cli
    environment:
      STRIPE_API_KEY: ${STRIPE_API_KEY}
      STRIPE_DEVICE_NAME: ${STRIPE_DEVICE_NAME}
    command:
      listen --forward-to ${STRIPE_FORWARD_TO}
    networks:
      - inbound

networks:
  inbound:
    external: true

If you will be composing docker-compose.yml your YAML file will look similar to this:

version: '3.7'

services:
  app:
    image: "your-image/app-123" # aka php:8.2-apache

  stripe-cli:
    image: stripe/stripe-cli
    environment:
      STRIPE_API_KEY: ${STRIPE_API_KEY}
      STRIPE_DEVICE_NAME: ${STRIPE_DEVICE_NAME}
    command:
      listen --forward-to app/api/v1/stripe/webhook 

I would like to appreciate the effort of companies that offers some helpful tools for developers. And for sure, there is no doubt that this is properly calculated as a good investment and I agree.

Anyway, I wish you painless implementation of any remote service.

Tags: #docker #random , Created: 21. 8. 2022
Created by Martin Krizan (2024)