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

Docker

Docker Problem Overview


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

Docker Solutions


Solution 1 - Docker

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 - Docker

This Works

docker build doronaviguy/helloworld -f SomeDockerFile .

Docker build Documentation

Solution 3 - Docker

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 - Docker

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 - Docker

This should work,

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

Solution 6 - Docker

You can acheive this also using docker-compose.

In your docker-compose.yml under the build section, you can specify the directory in which you store your dockerfile and its alternate-name as follow :

build:
  context: "/path/to/docker/directory"
  dockerfile: "dockerfile-alternate-name"

docker-compose

Solution 7 - Docker

Windows User should try below command:

> docker build -f absolute_docker_file_path dot

for example :

> docker build -f D:\Code\core-api\API_TEST.Dockerfile .

Solution 8 - Docker

My case is in the /tmp directory and there are a lot of files and docker try with others files althought I pass the -f <Dockerfile.foo>

The most clean and easy (for me) solution is (intead the dockerfeed from above answers):

cat DockerFile.debian.foo | docker build -t debian.foo -

Solution 9 - Docker

If you have multiple Dockerfile's, as could be the case in large projects, you could specify the respective fully-qualified Dockerfile to use.

docker build -t swagger_local -f /Users/123456/myrepos/storage/services/gateway/swagger/Dockerfile .

The command when run from /Users/123456/myrepos/storage creates a swagger_local image using the Dockerfile in a child project (services/gateway in my case )

Solution 10 - Docker

Let assume that you have successfully install docker toolbox including docker-compose and docker-machine. This is my docker-compose.yml

version: '2'
services: 
  web: ./www/python
  ports:
   - "5000:5000"

And this is under Dockerfile

FROM python:3.4-alpine
ADD ./www/python /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py"]

Make sure those files located precisely under root folder. When you run docker-compose up then you are going to build image for web.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondeepakView Question on Stackoverflow
Solution 1 - DockerAndrzej RehmannView Answer on Stackoverflow
Solution 2 - Dockerdoron aviguyView Answer on Stackoverflow
Solution 3 - DockerKen CochraneView Answer on Stackoverflow
Solution 4 - DockeritsafireView Answer on Stackoverflow
Solution 5 - DockerManoj Kumar SView Answer on Stackoverflow
Solution 6 - DockershaftView Answer on Stackoverflow
Solution 7 - DockerNikhil VatsView Answer on Stackoverflow
Solution 8 - Dockertres.14159View Answer on Stackoverflow
Solution 9 - DockerForeverLearnerView Answer on Stackoverflow
Solution 10 - DockerFaris RayhanView Answer on Stackoverflow