title: docker-compose - COMPOSE_PROJECT_NAME, DockerHub and "service name". How to use it?
body: <p>I'm using <code>docker-compose</code> to built customised <code>nginx</code> and <code>php</code> images and then I'd like to <code>push</code> it to DockeHub.</p>
  
  <p>I'm using <code>COMPOSE_PROJECT_NAME</code> in an <code>.env</code> file to set a prefix image name:</p>
  
  <pre><code>COMPOSE_PROJECT_NAME=myapp
  </code></pre>
  
  <p>and <code>docker-compose.yml</code> is something like:</p>
  
  <pre><code>version: '3'
  services:
    php-fpm:
      build:
        context: ./php-fpm
        args:
           .....
        volumes:
           .....
        expose:
           .....
  
    nginx:
      build:
        context: ./nginx
        args:
           .....
        volumes:
           .....
        port:
           .....
  </code></pre>
  
  <p>Running <code>docker-compose up -d</code> the images name are:</p>
  
  <pre><code>myapp_nginx
  myapp_php-fpm
  </code></pre>
  
  <p>the container name are:</p>
  
  <pre><code>myapp_nginx_1
  myapp_php-fpm_1
  </code></pre>
  
  <p>Now, to push these images to DocekeHub I need to change image name adding the DockerHub "account" suffix:</p>
  
  <pre><code>myaccount/myapp_nginx
  myaccount/myapp_php-fpm
  </code></pre>
  
  <p>to solve this problem, I added the "image" option to <code>docker-compose.yml</code>:</p>
  
  <pre><code>version: '3'
  services:
    php-fpm:
      build:
        context: ./php-fpm
        args:
           .....
        volumes:
           .....
        expose:
           .....
        image: myaccount/${COMPOSE_PROJECT_NAME}_php-fpm
  
    nginx:
      build:
        context: ./nginx
        args:
           .....
        volumes:
           .....
        port:
           .....
        image: myaccount/${COMPOSE_PROJECT_NAME}_nginx
  </code></pre>
  
  <p>now, running <code>docker-compose push</code> the images are pushed to DockerHub.</p>
  
  <p>Ok, my question are:</p>
  
  <p>1) is there a way to insert DockerHub account name <code>myaccout</code> into <code>COMPOSE_PROJECT_NAME</code> variable? Something like: <code>COMPOSE_PROJECT_NAME=myaccount/myapp</code> to create automatically the image name like: <code>myaccount/myapp_nginx</code> and <code>myaccount/myapp_php-fpm</code>?</p>
  
  <p>2) is there a variable to get "service name" the retrieve the name <code>nginx</code> or <code>php-fpm</code>? 
  For example, into the <code>docker-compose.yml</code> file, I could set: <code>image: myaccount/${COMPOSE_PROJECT_NAME}_&lt;service_name&gt;</code> then If I change the "service name" from <code>nginx</code> to <code>nginx2</code> automatically the image will be <code>myaccount/myapp_nginx2</code></p>
  
  <p>3) is there a way to rename the images produced with <code>docker-compose</code> only to permit the <code>push</code>?</p>
  
  <p>Thank you</p>