Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: cannot ping detached service in another step #321

Closed
mbana opened this issue Aug 6, 2018 · 6 comments
Closed

docker: cannot ping detached service in another step #321

mbana opened this issue Aug 6, 2018 · 6 comments

Comments

@mbana
Copy link

mbana commented Aug 6, 2018

Hi, please see below config.
I cannot seem to reach the services started in the docker-compose step.
Thanks,

cloudbuild.yaml:

steps:
- name: 'docker/compose:1.15.0'
  args: ['up', '-d','redis', 'mongo']
- name: 'docker/compose:1.15.0'
  args: ['ps']

- name: 'alpine'
  args: ['sh', '-c', 'while ! nc -v -z localhost 27017; do echo -e "\033[92m  ---> waiting for mongo ... \033[0m"; sleep 1; done']

docker-compose.yml:

version: "3"
services:
  redis:
    image: redis:alpine
    container_name: redis
    hostname: redis
    # networks:
    #   - some_network
    ports:
      - 6379:6379

  mongo:
    image: mongo:3.6-jessie
    container_name: mongo
    hostname: mongo
    # networks:
    #   - some_network
    ports:
      - 27017:27017

# networks:
#   some_network:

Output:

$  cloud-build-local --config=cloudbuild.yaml --dryrun=false .
2018/08/06 13:06:23 Warning: there are left over step containers from a previous build, cleaning them.
2018/08/06 13:06:25 Warning: a network is left over from a previous build, cleaning it.
2018/08/06 13:06:25 Warning: there are left over step volumes from a previous build, cleaning it.
2018/08/06 13:06:29 Warning: The server docker version installed (18.06.0-ce-rc3) is different from the one used in GCB (17.12.0-ce)
2018/08/06 13:06:29 Warning: The client docker version installed (18.06.0-ce-rc3) is different from the one used in GCB (17.12.0-ce)
Using default tag: latest
latest: Pulling from cloud-builders/metadata
Digest: sha256:1a4ae9cbfeb9eb982c8788f1db42f80555499000cd1ce5dbfe657af9955f8812
Status: Image is up to date for gcr.io/cloud-builders/metadata:latest
2018/08/06 13:06:40 Started spoofed metadata server
2018/08/06 13:06:40 Build id = localbuild_6608e461-da7a-4684-9860-e5d5141f62c3
2018/08/06 13:06:40 status changed to "BUILD"
BUILD
Starting Step #0
Step #0: Already have image (with digest): docker/compose:1.15.0
Step #0: Recreating redis ... 
Step #0: Recreating mongo ... 
Step #0: Recreating redis
Recreating mongo ... done
Recreating redis ... done
Step #0: 
Finished Step #0
Starting Step #1
Step #1: Already have image (with digest): docker/compose:1.15.0
Step #1: Name               Command               State            Ports           
Step #1: -------------------------------------------------------------------------
Step #1: mongo   docker-entrypoint.sh mongod      Up      0.0.0.0:27017->27017/tcp 
Step #1: redis   docker-entrypoint.sh redis ...   Up      0.0.0.0:6379->6379/tcp   
Finished Step #1
Starting Step #2
Step #2: Already have image (with digest): alpine
Step #2:   ---> waiting for mongo ... 
Step #2:   ---> waiting for mongo ... 
Step #2:   ---> waiting for mongo ... 
Step #2:   ---> waiting for mongo ... 
Step #2:   ---> waiting for mongo ... 
Step #2:   ---> waiting for mongo ... 
^Cmake: *** [ci] Interrupt: 2
@bendory
Copy link
Member

bendory commented Aug 6, 2018

See our documentation which explains that each build step attaches to a local Docker network named cloudbuild to enable inter-step network communication.

@bendory bendory closed this as completed Aug 6, 2018
@mbana
Copy link
Author

mbana commented Aug 6, 2018

Thanks for the link.

@bendory How would I connect to this network when using, say, the npm cloud-builders?

- name: 'gcr.io/cloud-builders/npm:node-8.11.0'
  args: ['test']

The tests require certain services to be up.

@bendory
Copy link
Member

bendory commented Aug 6, 2018

You can do that by using a docker run build step that executes the container with the args you need:

- name: 'gcr.io/cloud-builders/docker'
  args: [ 'run', '--network', 'cloudbuild', 'gcr.io/cloud-builders/npm', <...other args...> ]

@mbana
Copy link
Author

mbana commented Aug 6, 2018

@bendory thanks for that. Mounting volumes, however, doesn't seem to work. I tried the following locally hoping that /workspace will get mounted but it looks like it doesn't.

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: [
    'run',
    '--rm',
    '--network', 'cloudbuild',
    '--volume', '/workspace:/workspace',
    'node:8.11-alpine',
    'sh', '-c', 'pwd && ls -lah && ls -lah /workspace'
  ]

- name: 'gcr.io/cloud-builders/docker'
  args: [
    'run',
    '--rm',
    '--network', 'cloudbuild',
    'node:8.11-alpine',
    'sh', '-c', 'pwd && ls -lah && ls -lah /workspace'
  ]
cloud-build-local --config=cloudbuild.yaml --dryrun=false .
2018/08/06 19:00:08 Warning: The server docker version installed (18.06.0-ce-rc3) is different from the one used in GCB (17.12.0-ce)
2018/08/06 19:00:08 Warning: The client docker version installed (18.06.0-ce-rc3) is different from the one used in GCB (17.12.0-ce)
Using default tag: latest
latest: Pulling from cloud-builders/metadata
Digest: sha256:1a4ae9cbfeb9eb982c8788f1db42f80555499000cd1ce5dbfe657af9955f8812
Status: Image is up to date for gcr.io/cloud-builders/metadata:latest
2018/08/06 19:00:34 Started spoofed metadata server
2018/08/06 19:00:34 Build id = localbuild_478a3f90-ca58-400a-967f-e07fd58082c0
2018/08/06 19:00:34 status changed to "BUILD"
BUILD
Starting Step #0
Step #0: Already have image (with digest): gcr.io/cloud-builders/docker
Step #0: /
Step #0: total 64
Step #0: drwxr-xr-x    1 root     root        4.0K Aug  6 18:00 .
Step #0: drwxr-xr-x    1 root     root        4.0K Aug  6 18:00 ..
Step #0: -rwxr-xr-x    1 root     root           0 Aug  6 18:00 .dockerenv
Step #0: drwxr-xr-x    1 root     root        4.0K Jul  6 16:02 bin
Step #0: drwxr-xr-x    5 root     root         340 Aug  6 18:00 dev
Step #0: drwxr-xr-x    1 root     root        4.0K Aug  6 18:00 etc
Step #0: drwxr-xr-x    1 root     root        4.0K Jul  6 15:55 home
Step #0: drwxr-xr-x    1 root     root        4.0K Jul  5 14:47 lib
Step #0: drwxr-xr-x    5 root     root        4.0K Jul  5 14:47 media
Step #0: drwxr-xr-x    2 root     root        4.0K Jul  5 14:47 mnt
Step #0: drwxr-xr-x    3 root     root        4.0K Jul  6 16:02 opt
Step #0: dr-xr-xr-x  237 root     root           0 Aug  6 18:00 proc
Step #0: drwx------    1 root     root        4.0K Jul  6 15:55 root
Step #0: drwxr-xr-x    2 root     root        4.0K Jul  5 14:47 run
Step #0: drwxr-xr-x    2 root     root        4.0K Jul  5 14:47 sbin
Step #0: drwxr-xr-x    2 root     root        4.0K Jul  5 14:47 srv
Step #0: dr-xr-xr-x   13 root     root           0 Aug  6 18:00 sys
Step #0: drwxrwxrwt    1 root     root        4.0K Jul  6 16:02 tmp
Step #0: drwxr-xr-x    1 root     root        4.0K Jul  6 16:02 usr
Step #0: drwxr-xr-x    1 root     root        4.0K Jul  5 14:47 var
Step #0: drwxr-xr-x    2 root     root          40 Aug  6 18:00 workspace
Step #0: total 4
Step #0: drwxr-xr-x    2 root     root          40 Aug  6 18:00 .
Step #0: drwxr-xr-x    1 root     root        4.0K Aug  6 18:00 ..
Finished Step #0
Starting Step #1
Step #1: Already have image (with digest): gcr.io/cloud-builders/docker
Step #1: /
Step #1: total 64
Step #1: drwxr-xr-x    1 root     root        4.0K Aug  6 18:00 .
Step #1: drwxr-xr-x    1 root     root        4.0K Aug  6 18:00 ..
Step #1: -rwxr-xr-x    1 root     root           0 Aug  6 18:00 .dockerenv
Step #1: drwxr-xr-x    1 root     root        4.0K Jul  6 16:02 bin
Step #1: drwxr-xr-x    5 root     root         340 Aug  6 18:00 dev
Step #1: drwxr-xr-x    1 root     root        4.0K Aug  6 18:00 etc
Step #1: drwxr-xr-x    1 root     root        4.0K Jul  6 15:55 home
Step #1: drwxr-xr-x    1 root     root        4.0K Jul  5 14:47 lib
Step #1: drwxr-xr-x    5 root     root        4.0K Jul  5 14:47 media
Step #1: drwxr-xr-x    2 root     root        4.0K Jul  5 14:47 mnt
Step #1: drwxr-xr-x    3 root     root        4.0K Jul  6 16:02 opt
Step #1: dr-xr-xr-x  237 root     root           0 Aug  6 18:00 proc
Step #1: drwx------    1 root     root        4.0K Jul  6 15:55 root
Step #1: drwxr-xr-x    2 root     root        4.0K Jul  5 14:47 run
Step #1: drwxr-xr-x    2 root     root        4.0K Jul  5 14:47 sbin
Step #1: drwxr-xr-x    2 root     root        4.0K Jul  5 14:47 srv
Step #1: dr-xr-xr-x   13 root     root           0 Aug  6 18:00 sys
Step #1: drwxrwxrwt    1 root     root        4.0K Jul  6 16:02 tmp
Step #1: drwxr-xr-x    1 root     root        4.0K Jul  6 16:02 usr
Step #1: drwxr-xr-x    1 root     root        4.0K Jul  5 14:47 var
Step #1: ls: /workspace: No such file or directory
Finished Step #1
2018/08/06 19:00:40 status changed to "ERROR"
ERROR
ERROR: build step 1 "gcr.io/cloud-builders/docker" failed: exit status 1
2018/08/06 19:00:42 Build finished with ERROR status
make: *** [ci] Error 1

@joaoritter
Copy link

@bendory , why don't the docs you referenced use docker run with the --network flag?

image

@joaoritter
Copy link

Nevermind, I understand now. This helped a lot -> https://github.com/Philmod/gcb-docker-compose

k0uki pushed a commit to OLTAInc/cloud-builders that referenced this issue Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants