Skip to content

Deploy multiple vhost websites in Docker

Suyog Nepal ask a question in the Facebook group, here is the question:

I have multiple websites running via virtual host I want to deploy using the same websites via docker is it possible.

I’m very happy to help them to solve the question, so I write down this article.

I created two vhost websites on my CentOS 7 testing environments: and as vhost1 config file is similar to vhost2, only vhost1 config file is listed.

log_format www.vhost1.comm '$remote_addr - $remote_user [$time_local] $request'
        '$status $body_bytes_sent $http_referer '
        '$http_user_agent $http_x_forwarded_for';
        access_log  /var/log/;

server {
	listen       80;
	index index.html index.htm index.php;
	root  /var/www/www_vhost1_com;

nginx and vhost configuration files path:

[root@prod vhost]# tree /etc/nginx/
├── conf
│   └── vhost
│       ├──
│       └──
├── fastcgi.conf
├── fastcgi.conf.default
├── fastcgi_params
├── fastcgi_params.default
├── koi-utf
├── koi-win
├── mime.types
├── mime.types.default
├── nginx.conf
├── nginx.conf.default
├── scgi_params
├── scgi_params.default
├── uwsgi_params
├── uwsgi_params.default
└── win-utf

Set up multiple vhosts in Docker

Download nginx image, for docker installation, you can check the docker official website.

docker pull nginx

Run docker

docker run  --name mynginx -d -p 80:80 -v /var/www/:/var/www/ -v /etc/nginx/:/etc/nginx/ --privileged=true nginx

-p: This binds port 80 of the container to TCP port 80 on the host machine
-d: run container in the background
–name: Assign a name to the container
-v: The -v flag mounts the current working directory into the container
--privileged flag gives all capabilities to the container, he container can then do almost everything that the host can do

Verify and Access

Edit your hosts file to map IP and domain.

we have successfully access the vhost1 and vhost2 website.


image 1

Leave a Reply