【问题标题】:Is there a way to install the Firebase CLI in a python base docker image?有没有办法在 python 基础 docker 映像中安装 Firebase CLI?
【发布时间】:2020-04-30 15:48:24
【问题描述】:

我正在构建一个 python docker 映像,我需要在我的应用程序中使用 firebase CLI(通过 os.system 命令访问)。我正在尝试通过在 dockerfile 中运行它来安装它:

FROM python:3.6.8

RUN curl -sL https://firebase.tools | bash

docker build -t my_image/firebase获取此输出:

Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM python:3.6.8
 ---> 48c06762acf0
Step 2/2 : RUN curl -sL https://firebase.tools | bash
 ---> Running in 11536da1cdb4
-- Checking for existing firebase-tools on PATH...
-- Checking your machine type...
-- Links...
[Binary URL] https://firebase.tools/bin/linux/latest
-- Downloading binary...
bash: line 148: sudo: command not found
-- Setting permissions on binary...
bash: line 154: sudo: command not found
bash: line 163: firebase: command not found
Something went wrong, firebase has not been installed.
Please file a bug with your system information on Github.
https://github.com/firebase/firebase-tools/
-- All done!
The command '/bin/sh -c curl -sL https://firebase.tools | bash' returned a non-zero code: 1

如果有任何关于如何执行此操作的提示,我们将不胜感激。使用RUN npm install -g firebase-tools 不是一个选项,因为我正在构建python 图像。

【问题讨论】:

标签: python bash docker firebase-cli firebase-tools


【解决方案1】:

好的,找到了可行的解决方案。只需在 python 映像上安装 node,然后使用 npm 安装 firebase-CLI。

Dockerfile:

FROM python:3.6.8

RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
    && apt-get install -y nodejs

RUN npm install -g firebase-tools

现在我可以从 python 运行 firebase 命令了!

import os
command = 'firebase projects:list --token CI_TOKEN'
os.system(command)

有关将 firebase CLI 与持续集成结合使用的更多信息,请访问 here

【讨论】:

    【解决方案2】:

    在使用之前尝试安装 sudo 并授予用户(此处为“管理员”)sudo 权限:

    FROM python:3.6.8
    RUN apt-get update && apt-get install -y sudo
    RUN useradd admin && echo "admin:admin" | chpasswd && adduser admin sudo
    USER admin
    RUN curl -sL https://firebase.tools | bash
    

    改编自https://askubuntu.com/questions/906230/run-sudo-command-with-non-root-user-in-docker-container/1168971

    【讨论】:

    • Docker 中通常不需要sudo;在 Dockerfile 的上下文中,您可以简单地使用 USER root 切换到 root 用户,这通常是默认值。它也是少数在 Docker 中无法正常运行的管理命令之一(如果它要求输入密码,则没有密码可以提供)。
    • 根据建议运行代码,遇到此错误:sudo: no tty present and no askpass program specified 239 bash: line 163: firebase: command not found 240 Something went wrong, firebase has not been installed.
    • 寻找另一个选项来从节点构建 docker 镜像,使用 npm 安装 firebase cli,然后添加 python。
    猜你喜欢
    • 2018-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 2019-08-02
    • 2017-02-03
    • 2021-12-01
    • 1970-01-01
    相关资源
    最近更新 更多