Reputation: 7490
I am trying to do a basic docker learning and building an image.
My directory structure currently looks like below:
/Documents/docker_test/
├── docker_python
├── hello_world.py
The file docker_python
is the docker file name. hello_world.py
is a basic hello_world python script I am trying to run it by default when the container is created of the image.
The contents of that docker file look like below:
### 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"]
When I run it using
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
Upvotes: 1
Views: 15163
Reputation: 4220
To make the build work immediatly, your build command should be:
docker build -f docker_python -t docker_python .
By default, the build command will look for a file named Dockerfile
in the build context that you supply (in your case you supply .
aka. the current working directory). If you want to override this default, use the -f switch and supply your filename. Note that the Dockerfile
always needs to be in the build context.
The docker build
syntax simplified:
docker build -f <dockerfile> -t <imagetag> <buildcontext>
If you rename the file docker_python
in your project, to just Dockerfile
, you can simply build with the command that you are already trying:
docker build -t docker_python .
The docker build reference is a worthwhile read if you want to learn more.
Update
Since you are having trouble with the maintainer LABEL now, I will include a full Dockerfile for you here:
### 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"]
I only replaced the double quotes in the line:
LABEL maintainer="Baktawar"
Update
Next issue seems to be with the numpy installation. And yes, this is indeed a known issue on alpine. I managed to solve the issue with the following 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"]
Apparently, numpy requires some native libraries to be able to install. I also upgraded pip for you, I got a warning about the version.
To your question, should you build like this:
docker build -f dockerfile -t docker_python .
If you Dockerfile
is named dockerfile
- the answer is "Yes". You can only ommit the -f
switch, if your Dockerfile
is named exactly Dockerfile
. It is case sensitive.
Upvotes: 3
Reputation: 392
That error is happening because, by default, docker build expects a file called Dockerfile. Since yours is called docker_python, you need to use the --file , -f option, and then pass the name of your file.
--file , -f Name of the Dockerfile (Default is ‘PATH/Dockerfile’)
Check the Official Docker Documentation for more information.
Upvotes: 0