How to assign image name to images created by docker-compose

Hits: 449

I was giving up trying to figure out how to assign an image name to images created by docker-compose. BY default the image names are a bit annoying and not good for pushing to a docker registry. Apparently all you need to do is to use the image tag.

When you download an image in docker-compose this tag designates the image to be downloaded. But when used in combination with build context using a Dockerfile to build, the image tag miraculously designates the image name of your choice.

version: '3.7'
services:
    nginx:
        image: personal-nginx:latest
        build: 
          context:/personal-nginx
          dockerfile/Dockerfile