cloud-builders-community
cloud-builders-community copied to clipboard
docker-compose - resolving hostname
Greetings!
I'm having trouble connecting to a container after it has been started via docker-compose
(following the GCB docs). I've also found some code to go with those steps from the docs here.
I'm likely just missing what the hostname becomes off of the docker-compose up
step (and it's not as simple as the container_name
).
Minimally reproducible compose is:
version: '3.4'
services:
web-server:
image: nginx
container_name: web-server
ports:
- "8080:80"
networks:
default:
external:
name: cloudbuild
and cloudbuild is
steps:
- name: 'docker/compose:1.22.0'
args: ['up', '-d']
- name: 'gcr.io/cloud-builders/docker'
args: ['run', 'byrnedo/alpine-curl', 'web-server:8080']
Thanks!
I'm also seeing closed #90, but that doesn't really help this current situation (the linked examples just show the host and port resolving to container_name
and the external port in the compose configuration).
Ah, so a couple of crucial observations here:
-
It is indeed
container_name
; but it's the internal port (which means mapping the port to the docker host is superfluous). -
It's different for
gcr.io/cloud-builders/docker
steps because (speculating) GCB is doing less under-the-hood. In a docker run step, you can get in with--network=cloudbuild
(and port is still internal).
Example docker-compose.yml
:
version: '3.4'
services:
web-server:
image: nginx
container_name: web-server
networks:
default:
external:
name: cloudbuild
and cloudbuild.yml
with wget
:
steps:
- name: 'docker/compose:1.22.0'
args: ['up', '-d']
- name: 'gcr.io/cloud-builders/wget'
args: ['http://web-server:80']
and cloudbuild.yml
with docker run
:
steps:
- name: 'docker/compose:1.22.0'
args: ['up', '-d']
- name: 'gcr.io/cloud-builders/docker'
args: ['run', '--network=cloudbuild', 'byrnedo/alpine-curl', 'http://web-server:80']
Before closing this: does that all smell correct, or am I missing something?