I can't deploy ofcial ubuntu/squid via docker-compose

When I run

docker run -d --name squid-container -e TZ=UTC -p 3128:3128 ubuntu/squid:latest
docker exec -it squid-container /bin/bash
cat /etc/squid/squid.conf

Works normally, the squid.conf file exists.

When I try to use via docker compose and mount the volume, I get a fatal error.

FATAL: Unable to open configuration file: /etc/squid/squid.conf: (2) No such file or directory

How do I make the /etc/squid directory inside the container available on my host so I can edit the squid confs?

My Conf:

services:
  proxy:
    image: ubuntu/squid:5.2-22.04_beta
    ports:
      - 0.0.0.0:3128:3128
    environment:
      - TZ=America/Sao_Paulo
    volumes:
      - ./etc:/etc/squid

Doesn’t look like you’re mounting any volumes in the first command, so it creates the default /etc/squid/squid.conf defined in the image

Does the host directory ./etc/ contain a correct squid.conf?

My apologies, I missed your question

How do I make the /etc/squid directory inside the container available on my host so I can edit the squid confs?

I would do this:

docker run --rm -v ./etc/squid:/host ubuntu/squid:5.2-22.04_beta cp -r /etc/squid /host

This would create a container with the default /etc/suid/squid.conf and copy it into /host, which ./etc/squid would be mounted to

Afterwards, you may want to modify the compose file like so:

volumes:
  - ./etc/squid:/etc/squid

And voilà

Thanks for the answer.
Via docker-compose can I run the command to copy squid.conf to my local machine?

cp -r /etc/squid /host

This should be a one-time thing, you shouldn’t need a compose file for a command you will only be using once

But, since I see there are errors in the command I sent you, due to the image having an entrypoint, here’s a compose file that should sync the default configuration files into the mounted directory:

services:
  proxy:
    image: ubuntu/squid:5.2-22.04_beta
    volumes:
      - ./etc/squid:/host
    entrypoint: ["cp", "-r", "/etc/squid", "/host"]

Apologies, completely missed it

The best way to do that would probably be using:

docker run -d --name copy-conf ubuntu/squid:5.2-22.04_beta
docker cp copy-conf:/etc/squid ./etc/squid