How to run Dockerfile inside Docker-Compose.yml?

Asked

Viewed 412 times

1

This is a generic skeleton of a Docker-Compose.yml file

version: '3'
services: 
   db:
      image: mongo:3.4
  backend:
      image: node:8.1
      volumes:
        -./backend:/backend
      ports:
      - 3000:3000
      command: bash -c "cd /backend && npm i && node app"
  frontend:
      image: nginx:1.13
      volumes:
        - ./frontend:/usr/shared/nginx/html
      ports:
        - 80:80 

Assuming the Dockerfile file is on the same root as the Docker-Compose.yml file as I could run Dockerfile through the Docker-Compose.yml file ?

I’m open to questions

  • 1

    Instead of "image" put "build: ."

  • @Andersoncarloswoss thank you so much for helping me, would you put your suggestion? Because you explaining so I can not have idea, please!

1 answer

1


Docker Compose version 3 has the option build to inform a local Dockerfile to mount the container image.

version: "3"
services:
    myapp:
        build: .

This will mount the image of the conatainer myapp from the Dockerfile file in the same directory, because the . indicates the path of this file. If it is in another directory you can do something like:

version: "3"
services:
    myapp:
        build: ./myapp/

If you do not want the Dockerfile file used, but a file with another name, you can specify the name with dockerfile:

version: "3"
services:
    myapp:
        build: .
        dockerfile: Dockerfile-test

And if next to that you use the option image, image will be mounted using the name and tag indicated in this option.

version: "3"
services:
    myapp:
        build: .
        image: myapp:1.0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.