6. Introduction to Docker Networking
Activity 6.01: Leveraging Docker Network Drivers
Solution:
The following is the most common way to complete this activity according to best practices:
- Use the
docker network create
command to create a network for the NGINX web server. Call itwebservernet
and give it a subnet of192.168.1.0/24
and a gateway of192.168.1.1
:$ docker network create webservernet --subnet=192.168.1.0/24 --gateway=192.168.1.1
This should create the
bridge
network,webservernet
. - Use the
docker run
command to create an NGINX web server. Use the-p
flag to forward port8080
on the host to port80
on the container instance:$ docker run -itd -p 8080:80 --name webserver1 --network webservernet nginx:latest
This will start the
webserver1
container in thewebservernet
network. - Use the
docker run
command to start an Alpine Linux container namedmonitor
inhost
networking mode. This way, you will know that the container has access to the host ports...