Docker Community Forums

Share and learn in the Docker community.

Using a file other than Dockerfile for building an image



I am trying to build an image from a file other than Dockerfile

[test@eilagcy1 Builds]$ docker build -f /home/test/Builds/filedoc -t mycont:v3

“docker build” requires exactly 1 argument(s).

See ‘docker build --help’.

Usage: docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

[test@eilagcy1 Builds]$ ls -ltr filed*

-rw-rw-r–. 1 test test 85 Dec 7 13:15 filedoc

[test@eilagcy1 Builds]$ cat filedoc

FROM alpine:latest

RUN apk add --update htop && rm -rf /var/cache/apk/*

CMD [“htop”]

[test@eilagcy1 Builds]$ pwd


[test@eilagcy1 Builds]$

What is wrong with the above command?


(Jedihomer Townend) #2

I believe you’re missing the final dot…

docker build -f /home/test/Builds/filedoc -t mycont:v3 .


(assuming you’re in the directory containing the files that will be put into the container)


If I am providing the full absolute path, then why is the final dot required?


(Jedihomer Townend) #4

You’re providing the full path to the Dockerfile…

Whenever I’ve built with a Dockerfile I’ve always built like

docker build -f Dockerfile .

I may be wrong, it’s just that that’s how I’ve always done it… According to the docs ( it’s:

docker build [options] path

Your -f is an option… so you need to pass in the only required argument which is the path…

It might be that you need to change your command to

docker build -f /home/test/Builds/filedoc -t mycont:v3 /home/test/Builds/ 

I don’t know that to be sure thought as I’ve always built from the directory I’m in…


The way you are using is correct as it searches for Dockerfile in current directory.

In my case my build instructions file is not the named as Dockerfile, and it is not in current path.

I will try to illustrate with example.

Hold on



I got that ,

if we use like the following , i.e from within tmp directory , we are using -f and referring to path outside the tmp directory, it will not work. using the below command , it needs to have the context in current directory path
[root@eilagcy1 tmp]# docker build -t testbuild53 -f /home/test/sectestbuildpath/instrfile .

other way to refer to the directory other than current directory is the following:
[root@eilagcy1 tmp]# docker build -t testbuild53 - < /home/test/sectestbuildpath/instrfile --> this works OK.