nginx on Docker

Docker Desktop

Realizing I didn’t really remember my setup for my raspberry pi instance and the fact that I didn’t have a sandbox install, I decided to test it out locally… And since the laptop got repaired, I didn’t have Docker installed anymore. So I installed the latest version: [[Docker Desktop]]@4.12.0. Didn’t bother with a docker.com account, although I should have one. I’m also doing this for purely edutainment purposes so no licensing!

Ran through the built in tutorial. Useful refresher and highly recommended.

Using the default Image:

nginx on Docker 🌐

Most basic install run it with a name of `some-nginx`, pulling the default `nginx` image… doesn’t actually do anything. It’s running, but not listening so you can’t use it.

```console
$ docker run --name some-nginx -d nginx
```

-p 80:80 now maps port 80 to expose it.

```console
$ docker run --name some-nginx -p 80:80 -d nginx
```

Success! Serving up some content at `http://localhost/`

Pasted image 20220906200113

Map custom content

Of course, that’s the default content. So let’s create a ‘content’ directory and serve up our own content – good refresher on volumes.

Their example maps `/some/content` to the doc root for nginx: `/usr/share/nginx/html`

```console
$ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx
```

So let’s create a file:

```console
$ mkdir content
$ cd content
$ cat >> index.html
<html>
<head>
<title> Secure BFFs TEst</title>
</head>
<body>
<h1>
Secure BFFs Test
</h1>
Hello wrold!
</html>
^D

$ cd ..
```

This creates an `index.html` file under the `content` directory. Now let’s map it into the index:

```console
$ docker run --name some-nginx -v content:/usr/share/nginx/html:ro -p 80:80 -d nginx 
```

Whoops, what happened? Same output?
Path needs to be full qualified!

```console
$ docker run --name some-nginx -v /Users/jlin/projects/https/content:/usr/share/nginx/html:ro -d -p 80:80 nginx
```

Success!
Pasted image 20220906202847

Conclusion

You now have a local docker instance running a fetched `nginx` instance serving up your own custom content!

Comments

Powered by Facebook Comments