在docker中正确使用Stripe CLI



我想在docker中使用Stripe CLI。我不得不提一下,我是码头新手。我已经从dockerHub加载了stripe/stripe-cli。

docker run --rm -it stripe/stripe-cli:latest.

docker image ls还显示该映像在本地可用。但是docker ps没有显示我条带CLI容器?这是对还是错?

当我跑docker run -it stripe/stripe-cli login

我必须在浏览器中使用Stripe进行身份验证。这是输出:

Your pairing code is: xxxx-xxxx-xxx-xxxxx
This pairing code verifies your authentication with Stripe.
To authenticate with Stripe, please go to: https://dashboard.stripe.com/stripecli/confirm_auth?t=5ifDAxXxXxXxXxX
⣾ Waiting for confirmation... > Done! The Stripe CLI is configured for Mike's Test Stripe with account id add1_xxx
Please note: this key will expire after 90 days, at which point you'll need to re-authenticate.

我是我成功但我仍然不能使用stripe-cli之后呢?我错过了什么?

我认为这里也应该有一个docker组合解决方案。这是我的工作设置:

框架:Django 4

Python: 3.9

version: "3.9"

services:
stripe-cli:
image: stripe/stripe-cli
container_name: stripe-cli
command: "listen --api-key ${STRIPE_API_KEY} --device-name ${STRIPE_DEVICE_NAME} --forward-to web:8000/payment/webhook/"
env_file:
- stripe_cli.env

web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"

.env文件的内容(请记住,它应该保存在机器的本地)。不要提交这个文件。在本地创建)

STRIPE_API_KEY = rk_test_somelongkey***************
STRIPE_DEVICE_NAME = Name

请注意以下几点:

在"web:8000"中,'web'是django项目的服务名

要保留配置,您需要使用绑定挂载(-v属性)。在https://stripe.com/docs/cli/login上,您可以看到配置存储在.config/stripe/config.toml中,因此我们可以从本地磁盘挂载~/.config/stripe

docker run --rm -v ~/.config/stripe:/root/.config/stripe -it stripe/stripe-cli:latest login
Your pairing code is: asd-asd
This pairing code verifies your authentication with Stripe.
To authenticate with Stripe, please go to: https://dashboard.stripe.com/stripecli/confirm_auth?t=asdasdasdasd
⢿ Waiting for confirmation... > Done! The Stripe CLI is configured for asd with account id acct_asd
Please note: this key will expire after 90 days, at which point you'll need to re-authenticate.

所以现在我们可以重复而不需要再次登录

docker run --rm -v ~/.config/stripe:/root/.config/stripe -it stripe/stripe-cli:latest customers list

如果你的目的是简单地测试你的webhook,按照他们的文档说的做:

由于Docker容器是临时的,如果不定义数据卷,就不能使用stripe-cli登录。您可以使用——api-key标志。

docker run --rm -it stripe/stripe-cli:latest listen --api-key sk_test_XXXXXX --forward-to localhost/stripe_hook

docker run--rm选项表示容器退出后将被移除。并且命令确实会退出,除非它侦听到某些东西,例如listen

注意,这个docker镜像的默认entrypoint/bin/stripe;也就是说,它需要stripe cli命令中的一个。

docker run --rm stripe/stripe-cli:latest customers list(如stripe customers list,否则)

看看它的Dockerfile是怎么写的,我想它的目的是作为一次性的命令执行,而不是bash类型的交互平台。

一个简单的解决方案似乎是使用STRIPE_API_KEY--api-key选项。设置这个env var后,您可以使用任何命令,即使没有login

最新更新