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

南笙酒味 提交于 2019-12-06 16:31:49

问题


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

回答1:


Here is how to specify dockerfile. Sorry I cannot do it in comments as formatting is not supported over there.

https://docs.docker.com/compose/compose-file/#context

app:
    build:
      context: app
      dockerfile: Dockerfile



回答2:


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.




回答3:


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

app:
  build: ./app



回答4:


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



回答5:


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



回答6:


Is path where you expect the Dockerfile? You can check using the --verbose flag like:

docker-compose --verbose up | grep compose.cli.verbose_proxy.proxy_callable | grep path

for example:

compose.cli.verbose_proxy.proxy_callable: docker build <- 
(pull=False, cache_from=None, stream=True, nocache=False, labels=None,
tag='your_app',
buildargs={'some_build': '1901', 'addr': '0.0.0.0', 'corsdomain': '*',
'rpcport': '8545'}, forcerm=False, rm=True,

path='/Users/jmunsch/Desktop/dev/your_app/app?', # in the verbose output

dockerfile='Dockerfile')

in Dockerfile define the ARGS:

ARG some_flag=
ARG some_build=1900
ARG addr=0.0.0.0
ARG corsdomain="*"
ARG rpcport=8545

and in a compose file like :

build:
    context: ./your_app
    dockerfile: Dockerfile
    args:
      some_flag:       # --some_flag
      some_build: 1901 # --some_build 1901
      rpcaddr: 0.0.0.0 # --rpcaddr 0.0.0.0
      rpcport: 8545    # --rpcport 8545
      corsdomain: "*"  # --corsdomain


来源:https://stackoverflow.com/questions/36236491/docker-compose-gives-error-cannot-locate-specified-dockerfile-dockerfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!