Running Nginx in Docker
Let's see our Nginx Docker config in action.
Initial situation
- No Docker Containers running
- No Docker Images
- You have a Terminal Session in the Proxyserver directory
- Docker Network already started
$ ls -la
total 8
drwxr-xr-x 4 bert staff 128 Nov 21 13:40 .
drwxr-xr-x 12 bert staff 384 Nov 20 10:26 ..
drwxr-xr-x 5 bert staff 160 Nov 21 12:57 deployment
-rw-r--r-- 1 bert staff 547 Nov 21 12:56 docker-compose.yml
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Starting Docker-compose
$ docker-compose up
The terminal will be locked because we run this without the "-d" option (for 'Detach') This command results in the following output:
$ docker-compose up
Pulling proxyserver (nginx:1.21.4)...
1.21.4: Pulling from library/nginx
eff15d958d66: Pull complete
1e5351450a59: Pull complete
2df63e6ce2be: Pull complete
9171c7ae368c: Pull complete
020f975acd28: Pull complete
266f639b35ad: Pull complete
Digest: sha256:097c3a0913d7e3a5b01b6c685a60c03632fc7a2b50bc8e35bcaa3691d788226e
Status: Downloaded newer image for nginx:1.21.4
Creating proxyserver ... done
Attaching to proxyserver
proxyserver | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
proxyserver | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
proxyserver | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
proxyserver | 10-listen-on-ipv6-by-default.sh: info: can not modify /etc/nginx/conf.d/default.conf (read-only file system?)
proxyserver | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
proxyserver | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
proxyserver | /docker-entrypoint.sh: Configuration complete; ready for start up
And on another terminal window the Docker commands show a running Container:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 1.21.4 ea335eea17ab 4 days ago 141MB
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b78ac1eb5c5e nginx:1.21.4 "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, :::80->80/tcp proxyserver
Testing the ProxyServer
The Container itself is listening on Port 80, and it is mapped to port 80 on the Host.
Start a browser and go to http://127.0.0.1/ (default port is 80)
So, what do we have so far:
A Nginx Proxyserver running in a Docker Container.
The Nginx configuration does not do any proxy'ing yet, all requests are going to the catch-all empty website.
Next section of this tutorial will fix that.