我正在尝试做一个基本的码头工人学习和建立映像。
我的目录结构当前如下所示:
/Documents/docker_test/
├── docker_python
├── hello_world.py
文件docker_python
是docker文件名。 hello_world.py
是基本的hello_world python脚本,在创建图像容器时,我默认尝试运行它。
该docker文件的内容如下所示:
### Dockerfile
# Created by Baktawar
# Pulling from base Python image
FROM python:3.6.7-alpine3.6
# author of file
LABEL maintainer=”Baktawar”
# Set the working directory of the docker image
WORKDIR /app
COPY . /app
# packages that we need
RUN pip install numpy && \
pip install pandas && \
pip install jupyter
EXPOSE 8888
ENTRYPOINT ["python"]
CMD ["hello_world.py"]
当我使用
运行它时docker_test$ docker build -t docker_python .
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /Documents/docker_test/Dockerfile: no such file or directory
答案 0 :(得分:1)
要立即进行构建,您的构建命令应为:
docker build -f docker_python -t docker_python .
默认情况下,build命令将在您提供的构建上下文中查找名为Dockerfile
的文件(如果您提供.
,也就是当前工作目录)。如果要覆盖此默认值,请使用-f开关并提供文件名。请注意,Dockerfile
始终需要在构建上下文中。
简化了docker build
语法:
docker build -f <dockerfile> -t <imagetag> <buildcontext>
如果您将项目中的文件docker_python
重命名为Dockerfile
,则只需使用已经在尝试的命令即可进行构建:
docker build -t docker_python .
docker build reference是一本值得一读的书,如果您想了解更多。
更新
由于您现在在维护者LABEL方面遇到麻烦,因此我将在此处为您提供完整的Dockerfile:
### Dockerfile
# Created by Baktawar
# Pulling from base Python image
FROM python:3.6.7-alpine3.6
# author of file
LABEL maintainer="Baktawar"
# Set the working directory of the docker image
WORKDIR /app
COPY . /app
# packages that we need
RUN pip install numpy && \
pip install pandas && \
pip install jupyter
EXPOSE 8888
ENTRYPOINT ["python"]
CMD ["hello_world.py"]
我只替换了该行中的双引号:
LABEL maintainer="Baktawar"
更新
下一个问题似乎与numpy安装有关。是的,这确实是高山上的已知问题。我设法通过以下Dockerfile解决了这个问题:
### Dockerfile
# Created by Baktawar
# Pulling from base Python image
FROM python:3.6.7-alpine3.6
# author of file
LABEL maintainer="Baktawar"
# Set the working directory of the docker image
WORKDIR /app
COPY . /app
# Install native libraries, required for numpy
RUN apk --no-cache add musl-dev linux-headers g++
# Upgrade pip
RUN pip install --upgrade pip
# packages that we need
RUN pip install numpy && \
pip install pandas && \
pip install jupyter
EXPOSE 8888
ENTRYPOINT ["python"]
CMD ["hello_world.py"]
显然,numpy需要一些本机库才能安装。我还为您升级了点子,我收到了有关版本的警告。
对于您的问题,您是否应该像这样构建:
docker build -f dockerfile -t docker_python .
如果您Dockerfile
被命名为dockerfile
-答案是“是”。如果您的-f
恰好命名为Dockerfile
,则只能省略Dockerfile
开关。这是区分大小写的。
答案 1 :(得分:0)
发生该错误的原因是,默认情况下,docker构建需要一个名为 Dockerfile 的文件。由于您的名为docker_python,因此需要使用-file,-f 选项,然后传递文件名。
--file , -f Name of the Dockerfile (Default is ‘PATH/Dockerfile’)
检查Official Docker Documentation以获得更多信息。