[LINUX] Proxy server with Docker

Introduction

Build a proxy server with squid with Docker. I'm not doing anything special.

Target device and environment

Verification environment

Work content

Set masquerade in firewall

firewall-cmd --add-masquerade --zone=public --permanent
firewall-cmd --reload

Docker image preparation

Create an image so that it can be reused. Create an appropriate directory to put the Dockerfile and the configuration file.

mkdir -p /opt/docker/proxy
cd /opt/docker/proxy

Create a Dockerfile

/opt/docker/proxy/proxy.df


FROM centos:centos8
ENV TZ='Asia/Tokyo'
RUN ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime ; \
    dnf -y update ; dnf install -y squid ; \
    sed -i -e "s/http_port 3128/http_port 8080/" /etc/squid/squid.conf ;  \
    systemctl enable squid ; \
    dnf -y install rsyslog ;
COPY rsyslog.conf /etc
CMD [ "/usr/sbin/init" ]

Settings for syslog transfer

Transfer syslog to a remote location using the module ʻimfile that detects changes in the local log file. The forwarding destination is specified by UDP: 514 to the syslog server created in another entry. Since it belongs to the Docker network ʻinfraserv-network for network services, it is possible to transfer under the host name syslog.

/opt/docker/proxy/rsyslog.conf


module(load="imfile")
input(type="imfile"
      file="/var/log/squid/access.log"
      tag="pseudolog_squid_access_log"
      facility="local0"
      severity="notice")
:syslogtag, isequal, "pseudolog_squid_access_log" @syslog:514

Build an image from a Dockerfile to create a container

Once you have created the Dockerfile, build it.

docker build --force-rm -t infraserv:proxy . -f ./proxy.df && \
docker run --cap-add sys_admin --security-opt seccomp:unconfined  -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
  --network infraserv-network -it -d --name proxy --hostname proxy  -p 8080:8080 infraserv:proxy

If you get moss with dnf, the following command may work.

# firewall-cmd --add-masquerade --permanent
# firewall-cmd --reload

Operation check

Check with Diagnosis-kun, etc. http://taruo.net/e/

Recommended Posts

Proxy server with Docker
Tftp server with Docker
Creating a Flask server with Docker
Set up a Samba server with Docker
Start a simple Python web server with Docker
Use python with docker
Hello, World with Docker
Docker under proxy environment
Local server with python
I made a ready-to-use syslog server with Play with Docker
Implement PyTorch + GPU with Docker
PySpark life starting with Docker
Prepare python3 environment with Docker
Easy HTTP server with Python
Easy proxy login with django-hijack
Try Selenium Grid with Docker
Server management with Jupyter (1) import
Try building JupyterHub with Docker
Rails application building with Docker
Until you start Jupyter with Docker
Easy Slackbot with Docker and Errbot
Dynamic proxy with python, ruby, PHP
Build a deb file with Docker
Persist Flask API server with forever
Build Mysql + Python environment with docker
Deploy a Django application with Docker
Initialize Softether VPN server with GUI
Google App Engine development with Docker
Server construction with CONOHA VPS (CentOS)
Build PyPy execution environment with Docker
VPN server construction with Raspberry Pi
Service mesh learned with Docker Swarm
Rebuild Django's development environment with Docker! !! !! !!
Data science environment construction with Docker
Application development with Docker + Python + Flask
Build a CentOS Linux 8 environment with Docker and start Apache HTTP Server
Build a proxy server with nginx on multiple remote servers using Ansible
Access the Docker Remote API with Requests
Build Jupyter Lab (Python) environment with Docker
docker and PyCharm under proxy on windows
Web server for browser testing with Mocha
Create your own DNS server with Twisted
Dockerfile for RESTful MeCab server with mecab-ipadic-neologd
Django + Apache with mod_wsgi on Windows Server 2016
Build CGI Server running on Python 3 on Docker
Connect to MySQL with Python within Docker
Get a local DynamoDB environment with Docker
Let's scrape a dynamic site with Docker
Use cryptography library cryptography with Docker Python image
Create Python + uWSGI + Nginx environment with Docker
Make PLEN Control Server compatible with ViVi PLEN2
Dockerfile: Install Docker on your Linux server
[Linux] Build a jenkins environment with Docker
Send files via bastion server with scp
Launch environment with LineBot + Heroku + Docker + Python
[Golang] Create docker image with Github Actions
Run a Python web application with Docker
Create a web service with Docker + Flask
Automation of server monitoring etc. with Monit
Launch Flask application with Docker on Heroku
Build NGINX + NGINX Unit + MySQL environment with Docker