Raheel
Raheel

Reputation: 9024

Starting tor inside docker

FROM python:2

RUN echo "deb http://deb.torproject.org/torproject.org jessie main\ndeb-src http://deb.torproject.org/torproject.org jessie main" | tee -a /etc/apt/sources.list
RUN gpg --keyserver keys.gnupg.net --recv A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89
RUN gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | apt-key add -
RUN apt-get update -y
RUN apt-get install -y tor deb.torproject.org-keyring
RUN service tor start

After i spin up my container via docker-compose there is no tor process running inside container. which i check via ps aux

I have to go inside container and run command manually service tor start

What am i doing wrong here ?

Thanks

Upvotes: 4

Views: 3587

Answers (1)

Robert
Robert

Reputation: 36763

As Dan Lowe says:

RUN service tor start will start tor, write a new image layer, and exit. There's no CMD or ENTRYPOINT so this image, once built, won't start any processes at all.

Think docker stuff in two stages: build (Dockerfile) and run (docker run or docker-compose up). So there is one instruction in Dockerfile that tell docker what is the command to run when the container run (CMD), the others (RUN, etc) are for the image building.

FROM python:2

RUN echo "deb http://deb.torproject.org/torproject.org jessie main\ndeb-src http://deb.torproject.org/torproject.org jessie main" | tee -a /etc/apt/sources.list
RUN gpg --keyserver keys.gnupg.net --recv A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89
RUN gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | apt-key add -
RUN apt-get update -y
RUN apt-get install -y tor deb.torproject.org-keyring
CMD tor

Don't use service, with docker you need just foreground processes.

Upvotes: 4

Related Questions