How can docker-compose be used to build Dockerfiles?

Viewed 6133

I have such structure :

enter image description here

In my Makefile, I build the dockerfile:

sudo docker build --build-arg PHP_VERSION=7.4 -t kaiza/image-php74 - < dockerfile/Dockerfile.php

And kaiza/image-php74 is well created locally, if i do docker images, i get:

enter image description here

Then, in my docker-compose.php74.yml :

version: '2.4'

services:
  php7.4:
    image: "kaiza/image-php74"
    container_name: "kz-php74"
    hostname: "kz-php74"
    user: 1000:1000
...

But, when I run it

docker-compose -f docker-compose/php/docker-compose.php74.yml up --build -d

I get this error :

"pull access denied for kaiza/image-php74, repository does not exist or may require 'docker login': denied: requested access to the resource is denied"

Anyone have any idea how I can solve this without going through the registry solution (to keep everything local)?

Thanks.

1 Answers

docker-compose can be used as part of your workflow to build Dockerfiles.

A nice way to arrange this is to have a docker-compose.yml in the root, and then have a sub folder for each service.

docker-compose.yml

version: "3.8"

services:
  php7.4:
  image: kaiza/image-php74:latest
  build:
    context: php74
    dockerfile: Dockerfile
    args:
      PHP_VERSION: ${VERSION-7.3}

Assuming the relative path from the docker-compose to the php74 Dockerfile is php74/Dockerfile then:

docker-compose build php7.4 will build, and tag the image as kaiza/image-php74, and docker-compose up or docker-compose run php7.4 will build the image if requred, or use the locally built image if available.

The full reference for the build section is available on github

Related