If you are modifying /etc/hosts in the Docker container itself, then only processes within the Docker container are going to be able to resolve that domain locally.
Thus, if you are using a browser on your Mac to access a port exposed by Docker, it knows nothing about the DNS override and will try to hit the real site -- which likely explains the message ...
Edit your hosts file:
sudo vi /etc/hosts
Add URLs you want to block. This should be sufficient:
# Block YouTube
Reset the Directory Service cache
Ping the the hosts for ...