I will base my docker on the katacoda online tutorial. I will suppose you have the docker installed on a CentOS 7 system. We want to run a container that will be visible in our intranet, based on a nginx image. First we create a Dockerfile. Mine is looking like this:
Dockers/nginx ## > more Dockerfile FROM nginx:alpine COPY static-html-directory /usr/share/nginx/html
Then we build an image, that we will call webserver-image:v1
Dockers/nginx ## > docker build -t webserver-image:v1 . Sending build context to Docker daemon 4.608 kB Step 1 : FROM nginx:alpine Trying to pull repository docker.io/library/nginx ... alpine: Pulling from docker.io/library/nginx ff3a5c916c92: Pull complete b4f3ef22ce5b: Pull complete 8a6541d11dc3: Pull complete 7e869e2dcf68: Pull complete Digest: sha256:48947591194ac5a9dce1e110f9198 ---> 537527661905 Step 2 : COPY static-html-directory /usr/share/nginx/html ---> 933ca1ba4600 Removing intermediate container 53c4cc3ea6a3 Successfully built 933ca1ba4600
Now we will create a VLAN for the IP of the docker. On a console, I open the nm-connection-manager. I click on Add –> connection type VLAN, give it a name, choose an (online) working interface, give a VLAN id (a number) and a VLAN interface name. Then go to the IPv4 settings and give it an IP on the same subnet than the main machine. Basically, what I do is fill up that the same way the main interface +1 on the IP address (if the IP is free, of course). Let’s say our IP is 18.104.22.168, then the VLAN IP will be 22.214.171.124. Be aware of the netmask and route of your VLAN! You can test the VLAN is online by typing ifconfig -a, and ping 126.96.36.199. In my case, after a network restart, I’m now able to ping the address from another computer on my subnet.
Time to run the docker! We do so via one script, but in principle, there’s no difference if you simply copy and paste this on your command line:
docker run --name webserver \ -v /var/www/html/:/usr/share/nginx/html/ \ -d -p 188.8.131.52:80:80 \ webserver-image:v1
A little bit of info, in case it is not obvious: –name is the docker name, -v is linking /var/www/html with the nginx html folder, -d is to run the docker in the backround, -p is to give the port (+ the IP address) and the last parameter is the image used for the docker. We are ready to point a browser to 184.108.40.206. You should see this:
Even from the remote client on the same intranet. Now, if you do chmod 755 on /var/www/html/, copy some index.html and stop and start the container again:
docker stop webserver docker start webserver
you should see your index.html. We have our web server. Done!