From 5c38feba719dd639e23452296f0162fcf3841761 Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 15 Dec 2016 17:39:35 +0100 Subject: [PATCH 1/2] Nginx: complex config easier to read (I hope) --- nginx/content.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nginx/content.md b/nginx/content.md index cdffe506d..d39ec7da9 100644 --- a/nginx/content.md +++ b/nginx/content.md @@ -38,7 +38,7 @@ Then you can hit `http://localhost:8080` or `http://host-ip:8080` in your browse ## complex configuration ```console -$ docker run --name some-nginx -v /some/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx +$ docker run --name my-custom-nginx-container -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx ``` For information on the syntax of the Nginx configuration files, see [the official documentation](http://nginx.org/en/docs/) (specifically the [Beginner's Guide](http://nginx.org/en/docs/beginners_guide.html#conf_structure)). @@ -48,20 +48,23 @@ Be sure to include `daemon off;` in your custom configuration to ensure that Ngi If you wish to adapt the default configuration, use something like the following to copy it from a running Nginx container: ```console -$ docker cp some-nginx:/etc/nginx/nginx.conf /some/nginx.conf +$ docker run --name tmp-nginx-container -d nginx +$ docker cp tmp-nginx-container:/etc/nginx/nginx.conf /host/path/nginx.conf +$ docker rm -f tmp-nginx-container ``` -As above, this can also be accomplished more cleanly using a simple `Dockerfile`: +As above, this can also be accomplished more cleanly using a simple `Dockerfile` (in `/host/path/`): ```dockerfile FROM nginx COPY nginx.conf /etc/nginx/nginx.conf ``` -Then, build with `docker build -t some-custom-nginx .` and run: +Then, build with `docker build -t custom-nginx .` and run: + ```console -$ docker run --name some-nginx -d some-custom-nginx +$ docker run --name my-custom-nginx-container -d custom-nginx ``` ### using environment variables in nginx configuration From f9601a3845621a4fb50e5ad8b1c7797888d33894 Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 15 Dec 2016 17:41:26 +0100 Subject: [PATCH 2/2] Nginx: Preciser "-g daemon off;" -> fixes https://github.com/nginxinc/docker-nginx/issues/126 --- nginx/content.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nginx/content.md b/nginx/content.md index d39ec7da9..a333e0d7d 100644 --- a/nginx/content.md +++ b/nginx/content.md @@ -43,8 +43,6 @@ $ docker run --name my-custom-nginx-container -v /host/path/nginx.conf:/etc/ngin For information on the syntax of the Nginx configuration files, see [the official documentation](http://nginx.org/en/docs/) (specifically the [Beginner's Guide](http://nginx.org/en/docs/beginners_guide.html#conf_structure)). -Be sure to include `daemon off;` in your custom configuration to ensure that Nginx stays in the foreground so that Docker can track the process properly (otherwise your container will stop immediately after starting)! - If you wish to adapt the default configuration, use something like the following to copy it from a running Nginx container: ```console @@ -60,8 +58,9 @@ FROM nginx COPY nginx.conf /etc/nginx/nginx.conf ``` -Then, build with `docker build -t custom-nginx .` and run: +If you add a custom `CMD` in the Dockerfile, be sure to include `-g daemon off;` to `CMD` that Nginx stays in the foreground so that Docker can track the process properly (otherwise your container will stop immediately after starting)! +Then, build with `docker build -t custom-nginx .` and run: ```console $ docker run --name my-custom-nginx-container -d custom-nginx