Lab 3
Advanced Dockerfile
What if we need to expose additional ports that aren’t part of the base image? And we need different server listeners for that port?
Create directory lab3 and we’ll copy over the files lab2/conf/web.conf and lab2/html/index.html plus create two new files
mkdir lab3
cd lab3
cp /lab2/html/index.html .
cp /lab2/conf/web.conf .
touch app.html
touch Dockerfile
FROM nginx
RUN rm -f /etc/nginx/conf.d/default.conf
COPY web.conf /etc/nginx/conf.d/web.conf
COPY index.html /usr/share/nginx/html/index.html
COPY app.html /usr/share/nginx/html/app.html
EXPOSE 8333/tcp
Now we’ll need to modify the web.conf file for our new content
server {
listen 80;
server_name docweb.lab.lan;
root /usr/share/nginx/html;
index index.html;
location / {
}
}
server {
listen 8333;
server_name docweb.lab.lan;
root /usr/share/nginx/html;
index app.html
location / {
}
}
Now to create the app.html webpage
<html>
<head>
<title>app site</title>
</head>
<body>
application page
<p>app.html is not a normal index page.</p>
</body>
</html>
Almost there, we still need to complete a couple of steps. Our old volume container is still around and even if it’s not running, it’s using the docweb name and we don’t want that.
docker rm -f docweb
Time to create our new image
docker build -t docnew .
Once the image is ready, it’s time to run our new container
docker run -p 81:80 -p 82:8333 --name docweb -dit docnew
Navigate to