Command entry in detached step breaks service

I don’t know if this is intended or a bug, but detached steps are not able to have commands, otherwise service is not accessible by other steps. At very least this should be mentioned in documentation, along where detaching is described.

Is this a bug?

detached steps are able to have commands. I created a live example that you can reference.

Here is the yaml:
https://github.com/drone/hello-world/blob/e129ea553a176b61a9f9fc38c10d7e45e10d5255/.drone.yml

Here is the corresponding pipeline execution:
https://cloud.drone.io/drone/hello-world/272/1/2

No, I meant if commands are run, the service is not reachable, messes with network

With command, service in step is not reachable:

kind: pipeline
type: docker
name: default

steps:
  - name: web
    image: nginx:alpine
    detach: true
    commands:
    - echo foo

  - name: test
    image: alpine:3
    commands:
    - sleep 5
    - ping web

If we comment out command, it becomes reachable:

kind: pipeline
type: docker
name: default

steps:
  - name: web
    image: nginx:alpine
    detach: true
#    commands:
#    - echo foo

  - name: test
    image: alpine:3
    commands:
    - sleep 5
    - ping web

When you use the commands section it overrides the default container entrypoint with your shell commands (see docs.drone.io/pipeline/docker/syntax/steps/#commands). This means that, in your example, nginx is not going to automatically start because the entrypoint (which launches nginx) is being overridden. This can be solved by starting nginx from the commands section.

kind: pipeline
type: docker
name: default

steps:
  - name: web
    image: nginx:alpine
    detach: true
    commands:
    - /docker-entrypoint.sh nginx -g daemon off

  - name: test
    image: alpine:3
    commands:
    - sleep 5
    - ping web

(the above example replicates the docker entrypoint as defined in the Dockerfile. I did not test the above command so you may need to adjust to get it working)

I am having a similar issue. The issue for me is not that the server is not responding, but that the name resolution (dns) breaks when I add a command to my service.

I don’t know if @appletea is experiencing the same problem, but ping should not be affected by whether nginx has started or not.

@bradrydzewski if you have the time could you try to run this configuration:

---
kind: pipeline
type: docker
name: testing drone network connectivity

services:
  - name: foo
    image: remote-docker-hub.artifactory.danskenet.net/nginx:latest
    commands:
    - /docker-entrypoint.sh nginx -g daemon off
steps:
  - name: bar
    image: remote-docker-hub.artifactory.danskenet.net/alpine:3
    commands:
      - sleep 5
      - ping foo -c 3

The expected result is:
ping: bad address ‘foo’

If you reach the same result try to remove the command for the service. The expected result would then be ping responses.

I am running version 1.9.0, maybe this issue is not present in later releases

BR

I tested using the official redis image in this below yaml:

kind: pipeline
name: default

steps:
- name: test
  image: redis
  commands:
  - sleep 5
  - redis-cli -h redis ping
  - redis-cli -h redis set FOO bar
  - redis-cli -h redis get FOO

services:
- name: redis
  image: redis
  commands:
  - /usr/local/bin/docker-entrypoint.sh redis-server

I then executed the yaml and was able to successfully connect to redis from the pipeline step:

[redis:1] latest: Pulling from library/redis
[test:2] latest: Pulling from library/redis
[test:3] Digest: sha256:cd0c68c5479f2db4b9e2c5fbfdb7a8acb77625322dd5b474578515422d3ddb59
[redis:4] Digest: sha256:cd0c68c5479f2db4b9e2c5fbfdb7a8acb77625322dd5b474578515422d3ddb59
[redis:5] Status: Downloaded newer image for redis:latest
[test:6] Status: Downloaded newer image for redis:latest
[test:7] + sleep 5
[redis:8] + /usr/local/bin/docker-entrypoint.sh redis-server
[redis:9] 10:C 12 Aug 2021 13:41:48.966 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
[redis:10] 10:C 12 Aug 2021 13:41:48.966 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=10, just started
[redis:11] 10:C 12 Aug 2021 13:41:48.966 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
[redis:12] 10:M 12 Aug 2021 13:41:48.967 * monotonic clock: POSIX clock_gettime
[redis:13] 10:M 12 Aug 2021 13:41:48.967 * Running mode=standalone, port=6379.
[redis:14] 10:M 12 Aug 2021 13:41:48.967 # Server initialized
[redis:15] 10:M 12 Aug 2021 13:41:48.969 * Ready to accept connections
[test:16] + redis-cli -h redis ping
[test:17] PONG
[test:18] + redis-cli -h redis set FOO bar
[test:19] OK
[test:20] + redis-cli -h redis get FOO
[test:21] bar

We can therefore rule out the assertion that detached steps are not able to have commands, since the above test proves otherwise.

1 Like

Thank you for taking the time to test this. I can confirm that your configuration works, which means my problems lie elsewhere