docker-compose gives ERROR: Cannot locate specified Dockerfile: Dockerfile

Viewed 118214

I've cloned a docker setup which uses docker-compose. One remote developer confirms it works so my problem seems to be with my setup.

I ran docker-compose up, but that currently gives me this:

$ docker-compose up
Creating volume "mycompanydocker_mysql-data" with local driver
Creating volume "mycompanydocker_redis-data" with local driver
Creating volume "mycompanydocker_app-data" with local driver
Creating volume "mycompanydocker_mongo-data" with local driver
mycompanydocker_redis_1 is up-to-date
mycompanydocker_mongo_1 is up-to-date
mycompanydocker_mysql_1 is up-to-date
Building app
ERROR: Cannot locate specified Dockerfile: Dockerfile

My docker-compose.yml looks like this:

version: '2'

services:
  mysql:
    build: mysql/.
    env_file: env
    expose:
    - 3306
    ports:
    - "3306:3306"
    volumes:
    - mysql-data:/var/lib/mysql

  mongo:
    build: mongo/.
    env_file: env
    expose:
    - 27017
    ports:
    - "27017:27017"
    volumes:
    - mongo-data:/data/db

  redis:
    build: redis/.
    env_file: env
    expose:
    - 6379
    ports:
    - "6379:6379"
    volumes:
    - redis-data:/data

  app:
    build: app/.
    env_file: env
    expose:
     - 80
    ports:
    - "80:80"
    volumes:
    # To mount a local directory, change this
    # To use a docker volume
    - app-data:/app
    # local app
    # - ./mycompany:/app
    depends_on:
    - mysql
    - mongo
    - redis

volumes:
  app-data:
    driver: local
  mysql-data:
    driver: local
  redis-data:
    driver: local
  mongo-data:
    driver: local

and the tree looks like this:

$ tree
.
├── README.rst
├── app
│   ├── Dockerfile
│   ├── bin
│   │   ├── setup.sh
│   │   ├── start-nginx.sh
│   │   ├── start-rqworker.sh
│   │   ├── start.sh
│   │   └── update.sh
│   ├── etc
│   │   ├── nginx
│   │   │   └── sites-available
│   │   │       └── app
│   │   ├── supervisor
│   │   │   └── conf.d
│   │   │       └── supervisord.conf
│   │   └── supervisord.conf
│   └── ssh
│       └── id_rsa
├── docker-compose.yml
├── env
├── mongo
│   └── Dockerfile
├── mysql
│   └── Dockerfile
└── redis
    └── Dockerfile

The thing I don't understand is that docker-compose seems to find all Dockerfiles, except for the one in the app folder. I've got the following installed on OSX 10.11.2:

  • Docker version 1.10.3, build 20f81dd
  • docker-compose version 1.6.2, build 4d72027

I'm just starting out with Docker and I'm kinda stuck here. Does anybody know what could possibly be wrong or how I can debug this? All tips are welcome!

[EDIT]
I forgot to mention that there is no hidden .dockerignore file:

$ ls -la
total 56
drwx------@   11 kramer  staff    374 25 mrt 14:13 .
drwx------+ 1134 kramer  staff  38556 26 mrt 17:27 ..
-rw-r--r--@    1 kramer  staff   8196 26 mrt 08:14 .DS_Store
-rw-r--r--@    1 kramer  staff     23 24 mrt 15:29 .gitignore
-rw-r--r--@    1 kramer  staff   3879 24 mrt 15:29 README.rst
drwxr-xr-x@    7 kramer  staff    238 25 mrt 14:26 app
-rw-r--r--@    1 kramer  staff    868 25 mrt 17:50 docker-compose.yml
-rw-r--r--@    1 kramer  staff    219 24 mrt 15:29 env
drwxr-xr-x@    3 kramer  staff    102 24 mrt 15:29 mongo
drwxr-xr-x@    3 kramer  staff    102 24 mrt 15:29 mysql
drwxr-xr-x@    3 kramer  staff    102 24 mrt 15:29 redis

and the .gitignore file doesn't contain anything special either (don't know if it matters):

$ cat .gitignore
.project
.pydevproject
13 Answers

I had this problem on Windows with a docker-compose.yml created by a Visual Studio template. The template was created as:

build:
  context: .
  dockerfile: <ProjectFolder>\Dockerfile

And I was getting error: Cannot locate specified Dockerfile: <ProjectFolder>\Dockerfile. I changed the \ to / and it started working for me (i.e. <ProjectFolder>/Dockerfile). Maybe that will help if anyone has this error on Windows.

Inside the docker-compose.yml file to do the change, in order to meet the Dockerfile:

app:
  build: ./app

You need to specify the docker file name properly and it is case sensitive. I had uppercase letter in DockerFile and so it cannot find them. Hope it helps someone, who struggled like me. Better to use the dockerfile attribute in docker compose file.

app:
    build:
      dockerfile: DockerFile

Tried several variations, for some unknown reason I had to use an absolute path for it to work

├── visit-count
|   ├── docker-compose.yml
│   ├── Dockerfile
│   ├── files
│   │   ├── index.js
│   │   ├── package.json

version: '3.5'
services:
  visit-count:
    build: 
      context: /Users/deltapeng/source/repos/visit-count/files/
      dockerfile: /Users/deltapeng/source/repos/visit-count/Dockerfile

But after I got above working, found that this relative path worked too.

version: '3.5'
services:
  visit-count:
    build: 
      context: ./files/
      dockerfile: ../

In my case it was wrong branch on git. Don't forget to set the specific branch if you build your image from remote context. Url for context should looks like this:

services:                                                                                                                                                                                                 
wss-home:                                                                                                                                                                                               
  build:                                                                                                                                                                                                
  context: "http://${LOGIN}:${PASSWD}@host/path/to/repository.git#branch_name"                                                                                                        
  dockerfile: Dockerfile.prod

Had this problem with Visual Studio's automatically created docker-compose file and tried @crgolden solution but it didn't work.

I only get it to run after:

1) Renaming the file VS created from DockerFile to Dockerfile (notice the lower case 'f')
2) change the config to this:
services:
    ...
    <image-name>:
         build:
             context: <project_name>
             dockerfile: Dockerfile

wrong path, my shortest way on linux ubuntu when dockerfile and compose in same location

build: ./
  build: 
          context: ./
          dockerfile: DockerFile

this might help for version:'3.8' for the current directory set up otherwise, have to specify dockerfile absolute path like

build: 
          context: .
          dockerfile: <project_directory>\DockerFile

I ran into this error because I had my docker-compose in a child directory. What I didn't realize is that in a docker-compose file:

  • The build context you specify is relative to where the docker-compose file is located (in the correct first screenshot, the build context moves up two directories from the docker compose file location and is at the base of the repository)
  • The dockerfile location you specify is relative to where the build context is set (in the correct first screenshot, I need to go down two directories, into service/deploy, to find the Dockerfile because I just set the context two directories up)

enter image description here

What I was doing before which was resulting in the error: "Cannot locate specified Dockerfile":

enter image description here

I hope this helps someone out!

I had faced the same issue on ubuntu vm. I did the following steps:

sudo apt-get remove docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

I hope this will resolve this issue.

build:
context: ./
dockerfile: DockerFile

just add

build:
context: ./
dockerfile: DockerFile.dockerfile

Related