RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 928833
Accepted
Battrip
Battrip
Asked:2020-01-06 07:01:02 +0000 UTC2020-01-06 07:01:02 +0000 UTC 2020-01-06 07:01:02 +0000 UTC

无法构建 docker 映像

  • 772

通过对 docker 的介绍:https ://docs.docker.com/get-started/part2/#dockerfile )。

我正在尝试构建一个 docker 映像,有 3 个文件:

  • 码头文件;
  • 要求.txt
  • 应用程序.py;

dockerfile 内容:

#Use an official Python runtime as a parent image
FROM python:2.7-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python", "app.py"]

内容要求:

Flask
Redis

应用内容:

from flask import Flask
from redis import Redis, RedisError
import os
import socket

# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)

app = Flask(__name__)

@app.route("/")
def hello():
    try:
        visits = redis.incr("counter")
    except RedisError:
        visits = "<i>cannot connect to Redis, counter disabled</i>"

    html = "<h3>Hello {name}!</h3>" \
           "<b>Hostname:</b> {hostname}<br/>" \
           "<b>Visits:</b> {visits}"
    return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80)

尝试使用命令为 Python 安装 Flask 和 Redis 库时 pip install -r requirements.txt

分发:

pip : Имя "pip" не распознано как имя командлета, функции, файла сценария или выполняемой программы. Проверьте правильность написания имени, а также наличие и правильность пути, после чего повторите попытку. строка:1 знак:1 + pip install -r requirements.txt + ~~~ + CategoryInfo : ObjectNotFound: (pip:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

现在问题如下:当命令docker build --tag=friendlyhello ..Gives错误:

无法准备上下文:无法评估 Dockerfile 路径中的符号链接:GetFileAttributesEx C:\docker\Dockerfile:系统找不到指定的文件。

docker
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    user177220
    2020-01-06T11:28:52Z2020-01-06T11:28:52Z

    关于第一个问题 - 将pip其安装在容器中:

    RUN apt-get update -y
    RUN apt-get install -y php5-mcrypt python-pip
    

    这是以防您的映像是在 Ubuntu 上构建的。如果不是,则应使用适当的包管理器。

    无法准备上下文:无法评估 Dockerfile 路径中的符号链接:GetFileAttributesEx C:\docker\Dockerfile:系统找不到指定的文件。

    检查Dockerfile当前目录中的内容。此外,文件应该以这种方式调用 - 使用大写字母。

    如果文件名称不同,您可以这样做:

    docker build -t friendlyhello -f ./Dockerfile.txt .
    
    • 1
  2. Ruslan
    2020-09-23T22:20:04Z2020-09-23T22:20:04Z

    您也可以尝试将完整路径写入 Dockerfile

    docker build -t friendlyhello "D:\project1"
    

    其中 project1 是 Dockerfile 所在的文件夹

    • 1

相关问题

  • 如何列出docker容器中的文件

  • 在 docker compose 中为容器分配 IP

  • 如何正确进入docker容器

  • Docker compose yml 说明

  • 大型 Docker 镜像

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    根据浏览器窗口的大小调整背景图案的大小

    • 2 个回答
  • Marko Smith

    理解for循环的执行逻辑

    • 1 个回答
  • Marko Smith

    复制动态数组时出错(C++)

    • 1 个回答
  • Marko Smith

    Or and If,elif,else 构造[重复]

    • 1 个回答
  • Marko Smith

    如何构建支持 x64 的 APK

    • 1 个回答
  • Marko Smith

    如何使按钮的输入宽度?

    • 2 个回答
  • Marko Smith

    如何显示对象变量的名称?

    • 3 个回答
  • Marko Smith

    如何循环一个函数?

    • 1 个回答
  • Marko Smith

    LOWORD 宏有什么作用?

    • 2 个回答
  • Marko Smith

    从字符串的开头删除直到并包括一个字符

    • 2 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5