13

Do I absolutely need to have a Dockerfile in my directory when using the command docker-compose up? I don't believe a Dockerfile is necessary but want to be sure.

If I only have a docker-compose.yml file using pre-built images, there would be no need for a Dockerfile.

Correct me please! Thanks in advance.

Nick
  • 155
  • 2
  • 11
  • You re right, Dockerfile is not necessary. Docker Compose uses YAML file, typically named docker-compose.yml to define what your mutliple-container application should look like. – ppichier Mar 25 '19 at 21:55

1 Answers1

19

docker-compose lets you choose between the 2 options

  • build the container from a specified image:

    services:
      example:
        image: your/imagename
    
  • build the container out of a Dockerfile:

    services:
      example:
        build: 
          context: path/to/Dockerfile/dir
          dockerfile: Dockerfile #here you specify the name of your Dockerfile file
    
Efrat Levitan
  • 5,181
  • 2
  • 19
  • 40
  • 2
    nope, option three is to define a single compose file does all the job. in that case a docker file is not needed. but ofc it is not very tidy. Put each container defination in the seprate docker files are cleaner. – Junchen Liu Feb 23 '21 at 22:05