Quick Webserver with Nginx and Docker

Need to serve files on localhost? Do it 10 seconds using nginx, docker, and the following one-liner

docker run --name webserver -d -p 8080:80 -v /some/content/to/serve:/usr/share/nginx/html nginx

See you files on your browser by navigating to localhost:8080. By default, the server will look for an index.html from the mounted volume so add one for a homepage. See here for more information about the nginx docker image

-d – Daemon mode. Runs the docker image in a background process

-v – Mount a volume. Maps files from your local machine to a location on the dockerfile. The above example takes the index.html and places it into the default location for nginx to serve files.

-p – Expose ports. Maps internal port 80 on docker to port 8080 of the host machine.

The result

Want to take it to the next level and serve these files over the web? Follow the steps here!

Dockerize your runnable application

Ever run into an issue with environments when running other peoples code? Don’t have the proper modules in your environment? Don’t want to modify your existing environment just to run a CLI program?

Dockerize it! Make the application runnable on any machine using docker. Using a default alpine program date as an example

Step 1: Create a Dockerfile wrapping your application

# Base image
FROM alpine
# Copy your runnable program with the COPY 
# docker command.

# The first argument of the ENTRYPOINT will be command executed when 
# the docker container is run
ENTRYPOINT ["date"] 

Step 2: Build the dockerfile

docker build .

Step: 3 Run the program with docker run

docker run [container-name] -h

Full example

Slack Stats

I wanted an app that showed how often messages in a slack channel were interacted with whether it be from messages in threads or slack reactions. The linked application is a docker program that downloads slack conversations and user information into a database to query for information and statistics.

Tech Stack

  • JavaScript
  • PostgreSQL
  • Docker / Docker Compose