DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1

directory, and those changes are automatically shared to
any container using them. A quick example of this using
the nginx server should make this process clearer.


We can start with some HTML files that nginx can
display. I have a simple HTML file in a directory called
html under Documents on my local laptop running
Docker; in macOS, the path is ~/Documents/html. There
is a default directory where nginx looks for HTML files to
display to users connecting to the service:
/usr/share/nginx/html. You have to supply this mapping
with the -v or --volume flag when you launch your
container using the previous example. Here is what it
looks like:


Click here to view code image


$ docker container run --name test-nginx -p 80:80
-d -v
~/Documents/html:/usr/share/nginx/html nginx
d0d5c5ac86a2994ea1037bd9005cc8d6bb3970bf998e5867fe392c2f35d8bc1a

After you enter this long command, when you connect to
http://0.0.0.0, you see your own HTML content. The -v
flag maps your local directory to the shared directory on
the container, and from the container’s perspective,
those files are in /usr/share/nginx/html. Figure 13-27
shows the results of this container mapping to the
container host’s file system.

Free download pdf