I would like to create a Dockerfile that runs the squid proxy service on Google Cloud. I'm a bit confused with the ENTRYPOINT:
FROM ubuntu:latest
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
ENV SQUID_CACHE_DIR=/var/spool/squid
ENV SQUID_LOG_DIR=/var/log/squid
RUN apt-get install -y squid apache2-utils
COPY ./etc/squid/passwd /etc/squid
COPY ./etc/squid/squid.conf /etc/squid
EXPOSE 3128/tcp
WORKDIR /root
ENTRYPOINT service squid start && bash
Squid is a background service, so I had to tack on the "bash" command to keep the container up and running. Is there a more proper way of keeping the container up and running?
The container works correctly when I run it locally:
docker run -d --name docker_squid -p 3128:3128 --rm -t docker_squid bash
and
curl -x http://localhost:3128 -L https://www.example.com
However when I build and run the image on google cloud, it appears that the squid process keeps restarting, so it's ignoring the bash statement entirely. Any thoughts?
In which cases would it be more appropriate to use:
CMD service squid start && tail -F /var/log/squid/access.log
Generally you should assume that commands like service
just don’t work in Docker. You want the container’s primary process to be the service itself, which generally means running the server process directly. The Squid FAQ suggests an invocation something like
CMD ["squid", "-NCd1"]
where in particualr the -N
option causes it to run as a foreground non-daemon process.
(You should also prefer the JSON-ish form for CMD
and ENTRYPOINT
if you can. While many people prefer ENTRYPOINT
I always use CMD
if it’s an option, for being easier to override at docker run
time, and for allowing a pattern of an entrypoint script that does pre-startup initialization and then runs the CMD
.)