Getting `docker-compose run` to not do anything

Viewed 453

I'm making a devops script that runs

docker-compose run --no-deps my_service

For the sole reason of running diagnostic operations in the container, without running the actual container command. (Since it might be resource-intensive, or might fail altogether.)

I figured I'll override the entrypoint with some kind of no-op that runs forever.

The runs forever part is important, because if I'll just use echo or cat or anything, the process will finish immediately and I won't be able to use docker exec on my container.

I tried

--entrypoint "tail -f /dev/null"

But no luck. It seems that --entrypoint doesn't let you enter arguments for your command.

Do you know whether that's supposed to be possible or not?

Another funny hack I tried which kind of worked is --entrypoint yes which made the entrypoint be Linux's yes utility, which just output y in an infinite loop.
This worked fine for 2 hours, until I ran out of harddrive space and had to delete everything.

If you've got an idea for a common Linux command like yes that just waits forever, and doesn't print an infinite amount of text, let me know.

2 Answers

What about watch? This works:

# Dockerfile
FROM busybox

ENTRYPOINT ["echo","hello"]
# docker-compose.yml
version: '3'
services:
  test:
    build:
      context: .

Then:

$ docker-compose run --entrypoint="watch -n2 ls" test

[EDIT]: You can even set -n to 100000 if you don't want your container to do much... BTW, I tried with tail -f /dev/null and it seems to work, what is the version of docker-compose and docker?

I use standard trick for development environment

version: '2.4'
services:
  app:
    build: .
    ports:
      - 4000:4000
    command: tail -f /dev/null
    volumes:
      - ./:/srv/app:cached

The main part here is command: tail -f /dev/null.

Then you just docker-compose up and on the second terminal enter into it with docker-compose exec app sh (or bash instead of sh).

If you want to just run the container then just run is with sh/bash.

You can run it as docker run --entrypoint tail -it elixir:alpine as well if you need to redefine entrypoint and just "hang" it.

Related