Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose with name other than dockerfile

I have used docker to create CLI interfaces where I test my code. These are named reasonably as:

proj_root/.../docks/foo.dockerfile
proj_root/.../docks/bar.dockerfile

Because there is more than one dock involved, the top level "Dockerfile" at the project root is unreasonable. Although I can't copy ancestor directories when building in docker, I can clone my entire repo.

So my project architecture works for me.


Next, I look up docker-compose because I need to match my docker cards up against a postgres db and expose some ports.

However, docker-compose seems to be anchored to the hard-coded '"Dockerfile" in the current working directory' user concept from the perspective of the command line interface.

But! I see the error message implies the tool is capable of looking for an arbitrarily named dockerfile:

ERROR: Cannot locate specified Dockerfile: Dockerfile

The question is: how do I set docker-compose off looking for foo.dockerfile rather than ./Dockerfile?

like image 647
Chris Avatar asked Aug 16 '19 16:08

Chris


People also ask

Can Docker Compose work without Dockerfile?

Thanks in advance. You re right, Dockerfile is not necessary. Docker Compose uses YAML file, typically named docker-compose.

Does Docker compose replace Dockerfile?

No—Docker Compose does not replace Dockerfile. Dockerfile is part of a process to build Docker images, which are part of containers, while Docker Compose is used for orchestrating.

Can Dockerfile be named something else?

You may name your Dockerfiles however you like. The default filename is Dockerfile (without an extension), and using the default can make various tasks easier while working with containers.

What do I name a docker compose file?

The default filename is docker-compose. yml . You can name the manifest name as you like, but you have to pass the filename in the docker-compose command.


2 Answers

In your docker-compose, under the service:

services:
  serviceA:
    build: 
      context: <folder of your project>
      dockerfile: <path and name to your Dockerfile>
like image 188
Mihai Avatar answered Oct 21 '22 05:10

Mihai


As mentioned in the documentation of docker-compose.yml, you can overwrite the Dockerfile filename within the build properties of your docker-compose services.

For example:

version: 3
services:
  foo:
    image: user/foo
    build:
      context: .../docks
      dockerfile: foo.Dockerfile
  bar:
    image: user/bar
    build:
      context: .../docks
      dockerfile: bar.Dockerfile
like image 44
ErikMD Avatar answered Oct 21 '22 05:10

ErikMD