Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I run `docker-compose up` do I need a Dockerfile in the directory as well as a docker-compose.yml file?

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.

like image 537
Nick Avatar asked Mar 25 '19 19:03

Nick


People also ask

Do I need both Dockerfile and docker-compose?

Both the Dockerfile and docker-compose are important resources in the development and deployment of cloud-native applications. But knowing the difference between docker-compose and the Dockerfile is important. The Dockerfile is used to build images, while docker-compose helps you run them as containers.

What is difference between Dockerfile and docker-compose yml?

Dockerfile: A Dockerfile is a text document that contains all of the commands / build instructions, a user could call on the command line to assemble an image. This will be saved as a Dockerfile . (Note the lowercase 'f'.) Docker-Compose: Compose is a tool for defining and running multi-container Docker applications.

Does docker-compose override Dockerfile?

Docker-compose command doesn't override Dockerfile CMD.

What happens when you run docker-compose up?

The docker compose up command aggregates the output of each container (like docker compose logs --follow does). When the command exits, all containers are stopped. Running docker compose up --detach starts the containers in the background and leaves them running.


1 Answers

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
    
like image 143
Efrat Levitan Avatar answered Oct 02 '22 19:10

Efrat Levitan