How to determine the name of an image built using docker-compose

I use docker-compose to create my development environment. I want to create a specific image, but I do not know how to set a name for this image.

wildfly: build: /path/to/dir/Dockerfile container_name: wildfly_server ports: - 9990:9990 - 80:8080 environment: - MYSQL_HOST=mysql_server - MONGO_HOST=mongo_server - ELASTIC_HOST=elasticsearch_server volumes: - /Volumes/CaseSensitive/development/wildfly/deployments/:/opt/jboss/wildfly/standalone/deployments/ links: - mysql:mysql_server - mongo:mongo_server - elasticsearch:elasticsearch_server 

When I execute docker-compose , everything is fine, but I get a random name for the new image. = Is it possible to set a name for the assembly image?

+57
docker docker-compose orchestration
Aug 26 '15 at 15:21
source share
5 answers

For the Docker version 2 file format, you can create and tag an image for one service, and then use the same inline image for another service.

In my case, I want to create an elastic search cluster with two nodes, they need to use the same image, but is configured to work differently. I also want to create my own custom elasticsearch image from my own Docker file. So here is what I did (docker-compose.yml):

 version: '2' services: es-master: build: ./elasticsearch image: porter/elasticsearch ports: - "9200:9200" container_name: es_master es-node: image: porter/elasticsearch depends_on: - es-master ports: - "9200" command: elasticsearch --discovery.zen.ping.unicast.hosts=es_master 

You can see that in the first definition of the es-master service, I use the build option to create an image from the Docker file in the directory. / elasticsearch. I mark an image with the name "porter / elasticsearch" with the option "image". Then I refer to this constructed image in the definition of the “es-node” service with the option “image”, as well as “depend_on” to make sure that another container “es-master” is built and launched first.

+62
Feb 26 '16 at 21:35
source share
— -

Option 1: specifying a default image name

The name of the image created by docker-compose depends on the default folder name, but you can override it with the --project-name argument:

 $ docker-compose --project-name foo build bar $ docker images foo_bar 

Option 2: Specify Image Name

Once docker-compose 1.6.0 is missing, you can specify build: and image: to have an explicit image name (see arulraj.NET answer ).

Option 3. Creating an image from a container

The third is to create an image from the container:

 $ docker-compose up -d bar $ docker commit $(docker-compose ps -q bar) foo_bar $ docker-compose rm -f bar 
+27
Feb 02 '16 at 16:26
source share

Like docker-compose 1.6.0 :

Now you can specify both the assembly and the image if you are using the new file format. docker-compose build build the image and mark it with the name you specified, and docker-compose pull will try to pull it out.

So your docker-compose.yml will be

 version: '2' services: wildfly: build: /path/to/dir/Dockerfile image: wildfly_server ports: - 9990:9990 - 80:8080 

To update docker-compose

 sudo pip install -U docker-compose==1.6.0 
+19
Nov 27 '15 at 6:49
source share

Depending on your use case, you can use an image that has already been created and specify its name in docker-compose .

We have a production case where our CI server creates the name Docker with the name. ( docker build -t <specific_image_name> . ). As soon as the specified name is specified, our docker-compose will always create a specific image. This allows you to use several different features:

1- You can guarantee that wherever you run your docker-compose , you will always use the latest version of this particular image.

2- You can specify several named images in your docker-compose file and let them automatically connect through the previous build step.

So, if your image is already built, you can name the image using docker-compose . Remove build and specify image:

 wildfly: image: my_custom_wildfly_image container_name: wildfly_server ports: - 9990:9990 - 80:8080 environment: - MYSQL_HOST=mysql_server - MONGO_HOST=mongo_server - ELASTIC_HOST=elasticsearch_server volumes: - /Volumes/CaseSensitive/development/wildfly/deployments/:/opt/jboss/wildfly/standalone/deployments/ links: - mysql:mysql_server - mongo:mongo_server - elasticsearch:elasticsearch_server 
+13
Aug 27 '15 at 10:18
source share

after creating the image, do the following:

docker tag <image id> mynewtag:version

after that you will see that your image will no longer be called <none> when you go docker images .

+4
Aug 26 '15 at 15:55
source share



All Articles