首页 > 解决方案 > Docker 错误:错误检查上下文:'can't stat '/home/xyz/docker_experiments''

问题描述

我在 Ubuntu 机器上运行 docker [Docker version 17.06.2-ce, build a04f55b]。

只需从 docker 执行一个非常简单的练习即可构建 docker 映像:https ://docs.docker.com/get-started/part2/#apppy

在运行以下命令

sudo docker build -t friendlyhello .

我收到以下错误

error checking context: 'can't stat '/home/xyz/docker_experiments''.

我知道这与 apparmour 和权限有关。

根据要求,这是 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"]

标签: dockerdockerfileubuntu-18.04

解决方案


可能是权限问题。

您可以尝试 2 件事:

  • 尝试删除 sudo。如果您在安装 Docker 时已正确配置它,则不需要在每个命令上都使用 sudo。如果我开始工作后遇到这个问题,我可以用代码更新这个答案。
  • 尝试将您的 dockerfile 从您的 ubuntu 目录移出到您已设置并有权访问的目录中。尝试 chmodding 该目录,以便您拥有所需的所有访问权限。

mkdir /docker/test cp . /docker/test cd /docker/test sudo docker build -t friendlyhello .


推荐阅读