Docker Custom container Name

We use Docker compose for multi container application. After starting all the containers, then if you run the docker ps, you will be able to see all the containers and its images and port details.

If you note down the container name, its something generated by Docker. If we want to use the custom name, then we should specify it as container_name in the Docker compose file. Refer the below example,


rest:
   image: rest_image:1.0
   container_name: mywebApp-rest 
   environment:
      log_driver: "json-file"
   ports:
     - 8081:8081
   log_opt:
      max-size: "10m"
      max-file: "5"    

web:    
    image: web_image:1.0
    container_name: mywebApp-web
    environment:
     - REST_URL=http://rest:8081
    log_driver: "json-file"
    ports:
      - 80:80
    log_opt:
       max-size: "10m"
       max-file: "5"
    links:
         - rest:rest

If you use docker-maven-plugin[https://github.com/fabric8io/docker-maven-plugin], then you have to specify the alias inside the tag. Specify it as below


 <run>
  <namingStrategy>alias</namingStrategy>  
  ...
  ...
   </run>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s