diff options
author | Christian Cleberg <hello@cleberg.net> | 2024-09-01 22:03:26 -0500 |
---|---|---|
committer | Christian Cleberg <hello@cleberg.net> | 2024-09-01 22:03:26 -0500 |
commit | a0578880ef14f54647d7cfd96382395ab1e3cddb (patch) | |
tree | 3b48908939708db6580a90d99bf88ff045311e9d /content/blog/2024-04-08-docker-local-web-server.org | |
parent | 17d0e7fa0f46eae4ef284af4593e33ad24da3bef (diff) | |
download | cleberg.net-a0578880ef14f54647d7cfd96382395ab1e3cddb.tar.gz cleberg.net-a0578880ef14f54647d7cfd96382395ab1e3cddb.tar.bz2 cleberg.net-a0578880ef14f54647d7cfd96382395ab1e3cddb.zip |
format 2024 blog posts
Diffstat (limited to 'content/blog/2024-04-08-docker-local-web-server.org')
-rw-r--r-- | content/blog/2024-04-08-docker-local-web-server.org | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/content/blog/2024-04-08-docker-local-web-server.org b/content/blog/2024-04-08-docker-local-web-server.org index 7333bef..f551450 100644 --- a/content/blog/2024-04-08-docker-local-web-server.org +++ b/content/blog/2024-04-08-docker-local-web-server.org @@ -3,43 +3,42 @@ #+description: #+slug: docker-local-web-server -When developing websites locally, I often use a simple Python web server -to observe the changes. +When developing websites locally, I often use a simple Python web server to +observe the changes. #+begin_src sh python3 -m http.server #+end_src -However, this approach has its limitations. For example, this approach -does not enable logging or access controls. You also need to customize -=SimpleHTTPServer= if you have advanced needs from your web server. +However, this approach has its limitations. For example, this approach does not +enable logging or access controls. You also need to customize =SimpleHTTPServer= +if you have advanced needs from your web server. -So, I went to find an alternative that is almost as easy and far more -extensible and found Docker Desktop to be a suitable replacement. +So, I went to find an alternative that is almost as easy and far more extensible +and found Docker Desktop to be a suitable replacement. * Docker Desktop ** Installation -[[https://www.docker.com/products/docker-desktop/][Docker Desktop]] is a -desktop GUI for the phenomenal Docker container software. This allows -you to manage containers, images, volumes, environments, and extensions -via an easy-to-use GUI. +[[https://www.docker.com/products/docker-desktop/][Docker Desktop]] is a desktop GUI for the phenomenal Docker container software. +This allows you to manage containers, images, volumes, environments, and +extensions via an easy-to-use GUI. To install, open the link above and click the =Download= button for your -platform. I'm going through this process on an M2 Macbook, so I -downloaded the Mac - Apple Chip version. +platform. I'm going through this process on an M2 Macbook, so I downloaded the +Mac - Apple Chip version. -Open the installer and follow the installation process until the -application finishes the installation process. +Open the installer and follow the installation process until the application +finishes the installation process. #+caption: Docker Desktop on macOS [[https://img.cleberg.net/blog/20240408-docker-local-web-server/docker-desktop.png]] ** Creating an Nginx Container -I prefer to use the command line to create containers, so the following -commands will be input via the terminal. +I prefer to use the command line to create containers, so the following commands +will be input via the terminal. The following command will create a container, using the =nginx= image: @@ -61,20 +60,20 @@ You can navigate to [[http://localhost:8000]] to see the resulting page. ** Customizing the Nginx Container -Now that I have a container running the Nginx web server, I need to link -some volumes so that I can modify the site configuration and provide the -web files to serve. +Now that I have a container running the Nginx web server, I need to link some +volumes so that I can modify the site configuration and provide the web files to +serve. Let's start with the new command, which adds two volumes: -1. =<your_content>:/usr/share/nginx/html=: This is the directory where - you will provide the web pages for the server to serve. +1. =<your_content>:/usr/share/nginx/html=: This is the directory where you will + provide the web pages for the server to serve. 2. =<your_config>:/etc/nginx/conf.d/default.conf=: This is the Nginx configuration file for your site. -To see the updates, you can delete the previous container in the GUI or -run =docker stop web= to stop the container. Once stopped, you can run -the new =docker run= command below. +To see the updates, you can delete the previous container in the GUI or run +=docker stop web= to stop the container. Once stopped, you can run the new +=docker run= command below. #+begin_src sh docker run -it -d -p 8000:80 --name web -v ~/Source/cleberg.net/.build:/usr/share/nginx/html -v ~/Source/cleberg.net/nginx-config.conf:/etc/nginx/conf.d/default.conf nginx @@ -107,16 +106,15 @@ server { * Customizing Deployment Actions -I am currently blogging with [[https://emacs.love/weblorg/][weblorg]], -which uses a custom =publish.el= file to build the static site. Within -this file, I have configured my deployment process to check for the -=ENV= variable in thesh and if it's set to =prod=, the script will set -the base URLs to =https://cleberg.net=. If not, it sets the base URLs to -=localhost:8000= (which matches the port used in the container above). +I am currently blogging with [[https://emacs.love/weblorg/][weblorg]], which uses a custom =publish.el= file to +build the static site. Within this file, I have configured my deployment process +to check for the =ENV= variable in thesh and if it's set to =prod=, the script +will set the base URLs to =https://cleberg.net=. If not, it sets the base URLs +to =localhost:8000= (which matches the port used in the container above). -Therefore, I have modified my =build.sh= script to build with -=localhost= URLs if =ENV= is not set to =prod=. It also prevents the -build process from sending the built files to the production web server. +Therefore, I have modified my =build.sh= script to build with =localhost= URLs +if =ENV= is not set to =prod=. It also prevents the build process from sending +the built files to the production web server. #+begin_src sh #!/bin/bash @@ -133,7 +131,6 @@ else fi #+end_src -You can modify the container in numerous ways and this approach allows -you to create complex scenarios for your web development purposes. I -highly recommend switching over to a container-based approach for -simple, local web development. +You can modify the container in numerous ways and this approach allows you to +create complex scenarios for your web development purposes. I highly recommend +switching over to a container-based approach for simple, local web development. |