How do I build a dockerfile if the name of the dockerfile isn't Dockerfile?

I am able a build a Dockerfile like

docker build -t deepak/ruby .

But for a Dockerfile which is not named Dockerfile

# DOCKER-VERSION 0.4.8

FROM deepak/ruby

MAINTAINER Deepak Kannan "[email protected]"

RUN ./bin/rails s

let us say it is called Dockerfile.app which we build with

docker build -t deepak/app Dockerfile.app

then i get the error

Uploading context 0 bytes
Error build: EOF
EOF

Solution 1:

Notice there is a dot . at the end of both commands.

docker build -f MyDockerfile .

Or with a tag:

docker build -t mysuperimage -f MyDockerfile .

Solution 2:

This Works

docker build doronaviguy/helloworld -f SomeDockerFile .

Docker build Documentation

Solution 3:

The last parameter to docker build is the build path, when you put . it means this is the path where you will find the Dockerfile. When you change it to Dockerfile.app it will then try and look for Dockerfile.app/Dockerfile, which isn't correct.

I'm not sure if it will still work, but you used to be able to do this.

$ docker build -t deepak/app - < Dockerfile.app

Try that and see if it helps, if not, maybe open a docker issue to add this feature back in, or update the documentation on how to use a Dockerfile with a different name.

More info here: http://docs.docker.io/en/latest/commandline/command/build/

Solution 4:

Try dockerfeed. It uses the docker feature to build a context via stdin. I wrote the script to address exactly your problem I was facing myself.

To replace a Dockerfile with a different one you do it like this:

dockerfeed -d Dockerfile.app . | docker build -t deepak/ruby -

And voilà. Dockerfeed is doing the same as docker build. It packs the source with its Dockerfile but lets you swap out the old Dockerfile with the desired one. No files are created in the process, no source is changed. The generated tar archive is piped into docker, which in turn sends it down to the docker daemon.

Update: This was a valid answer in the old days when there was no -f switch available. With docker version 1.5 this option was introduced. Now you can build provide a different Dockerfile like this:

docker build -f other-Dockerfile .

Solution 5:

This should work,

docker build -t <tag-name> -f <file-name> .