Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

How can I use docker-compose from Dockerfile image locally built?

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...