fredrik
fredrik

Reputation: 10291

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:

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.

Upvotes: 3

Views: 2675

Answers (1)

dnephin
dnephin

Reputation: 28150

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.

Upvotes: 7

Related Questions