How to link docker containers to VM container with manifest?

TL; DR: is it possible to associate two containers with a container manifest?

I am trying to transfer the Guest Book application from Google Container Engine documents to vm container. I'm having trouble connecting two vms containers so the web application can access the redis service.

This works if I use the docker command line in an instance:

run the instance and ssh into it:

gcloud compute instances create guestbook-vm --image container-vm --machine-type g1-small gcloud ssh guestbook-vm 

create containers:

 sudo docker run -d --name redis -p 6379:6379 dockerfile/redis sudo docker run -d --name guestbook -p 3000:80 --link redis:redis -e "REDIS_MASTER_SERVICE_HOST=redis" -e "REDIS_MASTER_SERVICE_PORT=6379" brendanburns/php-redis 

I use -link to connect the guestbook to the redis container. Can this also be done with a container manifest?

this is my command:

 gcloud compute instances create guestbook-vm --image container-vm --machine-type g1-small --metadata-from-file google-container-manifest=containers.yaml 

EDIT: Alex's solution for using 127.0.0.1 is working fine, so the correct .yaml containers are:

 version: v1beta2 containers: - name: redis image: dockerfile/redis ports: - name: redis-server containerPort: 6379 hostPort: 6379 - name: guestbook image: brendanburns/php-redis ports: - name: http-server containerPort: 80 hostPort: 3000 env: - name: REDIS_MASTER_SERVICE_HOST value: 127.0.0.1 - name: REDIS_MASTER_SERVICE_PORT value: 6379 
+6
source share
1 answer

The link parameter is available in the container manifest , so unfortunately you cannot do this.

However, did you try to just set the REDIS_MASTER_SERVICE_HOST environment variable to 127.0.0.1? I believe this should allow the frontend container to talk to the redis container through the standard network stack.

+2
source

Source: https://habr.com/ru/post/982599/


All Articles