Coder Social home page Coder Social logo

dockertom's Introduction

dockertom

This is a sample TOM to show how it can be used with Docker.

The TOM was created by following the getting started guide with the credentials:

  • User: tom-user
  • Password: password

and the modifications laid out below.

Dockerizing existing projects will require some project specific modifications that differ slightly from this example.

Dependencies

Modifications

All of the modifications listed below have already been made to this repository except Create database directory.

Create database directory

Since Docker containers are ephemeral and the TOM has a database that should be persisted, we need to put our database in a volume.

First, we'll create a directory in our project that we can use as a volume in our container:

mkdir storage

Change database path

Now we need to tell the TOM where to find the database by updating an element in the DATABASES section of settings.py:

'NAME': os.path.join(BASE_DIR, 'storage', 'db.sqlite3'),

Migrate database

Now that we've updated the location of where the TOM will look for the database, let's migrate the databases in the storage directory:

./manage migrate

Web server

In order to allow others to access our TOM, we need to serve it with a web server. Gunicorn is a popular Python web server that we'll use in this example.

pip install gunicorn gevent

Serve static files

Although we have setup a web server for our TOM, it's not able to server static files to users (e.g. images). We can serve static files using WhiteNoise.

Note that other applications are better suited to serve static files such as Nginx when a TOM is deployed using system packages (e.g. DNF, apt-get) or container orchestration (e.g. Kubernetes).

pip install whitenoise

Docker

Build image

To build a Docker image for our TOM, we need to give it a name and a unique tag. Do not use the default latest tag for production deployments. The latest tag is error prone and makes debugging deployments very, very difficult. "Latest is a proliferating ball of confusion that should be avoided like a ravine full of venomous snakes". The command below uses the git tag of the repo as the tag of the Docker image:

TAG="$(git --describe --always)"
docker build --tag "dockertom:${TAG}"

Run image

Now run the created image:

docker run --interactive --tty --rm --name dockertom --publish 8080:8080 --volume "${PWD}/storage:/tom/storage "dockertom:${TAG}"

Access your TOM by going to http://localhost:8080!

Automation

Typing the commands above to build and run your Docker image can become very repetitive and is not reproducible. To make development easier and production more reliable, the commands should be automated. This has been done using a Makefile in this project which requires Make to be installed.

Everything needed to build and run a Docker image can be done by simply running:

make

in the root of this project.

dockertom's People

Stargazers

Joshua Liberman avatar  avatar

Watchers

James Cloos avatar Mark Bowman avatar Rachel Street avatar George Silvis avatar

Forkers

ygrange

dockertom's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.