How to define docker image name from within docker-compose.yml?

I’ve got a directory called thing with my docker compose project:

thing
├── Dockerfile
└── docker-compose.yml

The contents of docker-compose.yml:

  • Docker - Mount Directory From Container to Host
  • Elastic Beanstalk Docker - How to get container logs
  • Docker - Running watchify inside container does not work
  • kubernetes set list of all physical nodes
  • asyncio client server does not work inside docker
  • Can I connect directly to a docker swarm network?
  • master:
      build: .
    

    Whenver I run docker-compose build in this folder, this will produce a docker image called thing_master. I’d like to specify in docker-compose.yml another name for my image. Is this possible?

    – I know I can run docker-compose -p [image_name] build or set the environment variable COMPOSE_PROJECT_NAME, but that’s not what I wish to do.

  • How to switch from ascii postgresql database to utf8 on docker?
  • docker unable to compile program (possibly undefied macro AC_MSG_ERROR)
  • Jenkins - Dockerfile build upon another dockerfile in private repo
  • How do I clean up cached partial images from a broken Docker pull?
  • How to escape CMD in Dockerfile
  • SSL: how to get access to HTTPS in docker container
  • One Solution collect form web for “How to define docker image name from within docker-compose.yml?”

    This is now possible in Compose 1.6 (rc2 is out now).

    Using 1.6, you can have both build and image on the same service:

    version: "2"
    
    services:
      master:
        build: .
        image: my_image_name:my_tag
    

    Build will use the image name to tag the image.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.