0

I want to create docker image with Tor/aiohttp server to use as a proxy for HTTP requests (curl mostly). I've already prepared working Docker image (I can use external curl -x with it), the main problem with syntax.

What I need: I need to use this image like docker run test_image curl api.ipify.org. Main problem - I don't understand how to configure ENTRYPOINT/CMD correctly. I use supervisor to activate services (tor/aiohttp), so the last line of my Docker image is:

ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

Question: How can I configure Docker image (using ENTRYPOINT/CMD), so the image will run my curl request after activating services?

With current exec entrypoint (or shell form) it ignores curl. If I use cmd instead of entrypoint, curl works, but image ignores cmd, so services are not activated.

So need any advice about Docker logic/syntax, so I can make it work.

Cœur
  • 37,241
  • 25
  • 195
  • 267
sortas
  • 1,527
  • 3
  • 20
  • 29
  • 1
    Why is it important to run curl from within the container? Why is it important for the container to be running multiple services? – David Maze Dec 08 '18 at 17:28
  • It's an academic task with straight conditions. I have no problems with curl or running services, main question - how can I combine ENTRYPOINT with some external software (curl, or ping, or tracert, etc). – sortas Dec 08 '18 at 17:51

1 Answers1

2

You can run ENTRYPOINT as a shell script instead of a command:

https://success.docker.com/article/use-a-script-to-initialize-stateful-container-data

docker-entrpoint.sh

#!/bin/bash
set -e

/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
curl api.ipify.org

Dockerfile

FROM debian:stretch
...
COPY docker-entrypoint.sh /usr/local/bin/
RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]
DevOps Dan
  • 1,724
  • 11
  • 11
  • It works, but I need to use curl from "docker run", so I can specify url and so on from CLI. I can use env variables, of course, but, because of conditions, need to work with curl (or other software) from "docker run test_image curl http://someurl.com". – sortas Dec 08 '18 at 18:06
  • 2
    You can override the ENTRYPOINT at run time, but we're starting to break some Docker principals: `docker run --rm -it --entrypoint "curl http://google.com" test_image` – DevOps Dan Dec 08 '18 at 18:17
  • docker run test_image 'curl someurl.com' - no use – sortas Dec 08 '18 at 18:21
  • You can override the ENTRYPOINT at run time - I can, still I need to start services before using curl, so it can use service sockets as proxy. – sortas Dec 08 '18 at 18:22
  • No need to run curl WITH container, curl was on a new line, when I thought it was on the same :) – sortas Dec 08 '18 at 23:52