Skip to content

lentils/first-docker-website

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

First web project

This is my first crack at web development. I'll be following along Mozilla's guide and building off of that. This README will be working notes on things I discover along the way. Hopefully other newbies can also get some useful information from my example.

Docker

Another goal was to understand how web-servers work. Since Docker is the Hot New Thing, why not leverage it to make a standalone project?

Getting started with Docker

First, make sure you have a Docker runtime on your machine. On OSX, there is Docker toolbox. For a webserver, there is an official Apache image.

Testing locally

With docker-machine, you have a virtual machine which hosts the containers that execute your code. For a container that runs a webserver, you need to do 2 things before you can view the content in your browser:

  • Forward relevant ports from within the docker container
  • Identify the IP address of your docker-machine VM to connect to via the browser

Forward ports

Assuming you are using apache's httpd image, run your container like this:

docker run -it --rm -p 80:80 --name my-apache-app -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4

Notice the -p 80:80. This exposes port 80 in the running container to the outside world, so you can connect to it. See Docker docs for more.

Identify the docker-machine IP address

Get a list of all running Docker VMs and their IP addresses with docker-machine ls. If you are new to Docker, you probably just have one, labeled default. If you are running a Docker container with forwarded ports, you should be able to enter that address into your browser (don't specify a port), and see the content you want to serve.

Website plumbing

Interactive content usually requires some input from the user. That content generally has to go somewhere else to be processed. This requires routing.

CGI (Common Gateway Interface)

CGI seems like a lightweight way to work with content interactively. With the Apache container httpd, CGI scripts can be placed in /usr/local/apache2/cgi-bin. Then, specify the name of the script in the action attribute of a form element, like so:

<form action="my-cgi-script.py">

About

First web dev project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published