Tuesday 8 December 2015

Ability to specify image_name in docker-compose yml file

Update 20/12/2015: It turned put that the team behind Compose is already working on that. There is a pending pull request doing the same in a slightly different way (see details here). This will be part of Compose 1.6.0 release and you should really use that as it will be the officially supported version.


Docker Compose is a great tool for bringing together multi-container application environments with a simple, readable definition file and a single command.

As we have the ability to specify container_name  in the docker-compose.yml file, one logical addition would be to be able to specify the image name of the images built via the build command (generally, the equivalent of running docker build --tag=(tagname) . ).

Normally, auto-generated names in the form of (project)_(name) are totally fine, but it's kind of a pain if you frequently push images built with compose into a registry (as you have to use docker tag manually before pushing those images into the registry).

An example yml file would be:

apikeys:

  build: ./api_keys

  image_name: "dbonev/apikeys"

  container_name: "apikeys"

  ports:

    - "4343:4343"

data_api:

  build: ./data_collection

  image_name: "dbonev/data_api"

  container_name: "data_api"

  ports:

    - "4242:4242"
Using docker-compose up/build on this file would then create an image tagged with dbonev/apikeys, ready to be pushed into the dbonev/apikeys repository.
db@db-VirtualBox:~/node/proton$ docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
dbonev/apikeys       latest              7c8c510b33b9        7 seconds ago       434.1 MB
dbonev/data_api      latest              15537693d7e8        35 hours ago        437 MB
Unfortunately, compose doesn't offer such ability as of the time of this writing. As I am using the tool on a daily basis, I slightly tweaked docker-compose code to allow this.
The image_name branch on my git repo fork of docker-compose does exactly this.