{"id":20827344,"url":"https://github.com/realpython/django-docker-tests","last_synced_at":"2025-05-07T21:03:55.376Z","repository":{"id":20527564,"uuid":"23806656","full_name":"realpython/django-docker-tests","owner":"realpython","description":null,"archived":false,"fork":false,"pushed_at":"2014-09-08T20:19:04.000Z","size":108,"stargazers_count":4,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T21:03:50.812Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/realpython.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-08T20:18:10.000Z","updated_at":"2021-09-18T01:38:30.000Z","dependencies_parsed_at":"2022-09-10T22:40:13.755Z","dependency_job_id":null,"html_url":"https://github.com/realpython/django-docker-tests","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realpython%2Fdjango-docker-tests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realpython%2Fdjango-docker-tests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realpython%2Fdjango-docker-tests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realpython%2Fdjango-docker-tests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/realpython","download_url":"https://codeload.github.com/realpython/django-docker-tests/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252954409,"owners_count":21830902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T23:11:50.662Z","updated_at":"2025-05-07T21:03:55.354Z","avatar_url":"https://github.com/realpython.png","language":"Python","readme":"# Testing with Docker\n\nLet's look at a nice workflow for testing with Docker.\n\nTools we'll be using:\n\n1. Python/Django\n1. Docker\n1. Fig\n1. Github\n1. Jenkins\n1. Docker Hub\n\n## Docker Explained\n\n\"[Docker](https://www.docker.com/whatisdocker/) is an open-source engine that automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere.\"\n\nDocker provides the isolation of a virtual machine, wrapping the filesystem, processes, evironment variables, etc. into a nice container - but without all the overhead since it uses the host machine's kernal. Your app, processes, and code run in *containers*, while *images* save the state of the containers for easy recreation on other machines. Using the popular .git analagy, images are akin to repositores while containers are akin to a local clone.\n\n**Why use Docker?**\n\n1. Containers are isolated like a true VM. Forget about messing with virtualenv.\n1. Docker images are shareable and handle version control at the system-level. Easily distrubute your working environment amongst your enture team.\n\nFinally, you can *truly* mimic your production environment at the local level, without any perfromance loss.\n\n**You can add Docker into your development workflow to test your deployments locally in an isolated, lightweight VM-like environment, all without touching virtualenv.** Pretty cool.\n\n## Fig Explained\n\nFig automates the (re)creation of a Docker environment.\n\n## Quick Start\n\n### Setup Docker for Mac\n\n1. Follow the instructions [here](http://www.fig.sh/install.html) to install Docker and Fig.\n1. Sanity check\n\n    ```\n    $ docker-osx shell\n    $ fig --version\n    fig 0.5.2\n    ```\n\n1. docker-osx commands: run `docker-osx` to view the available commands\n\n### Create a Dockerfile\n\nA Dockerfile is a configuration file that automates the creation of your container from an image.\n\n```\n# start with a base image\nFROM ubuntu:13.10\nMAINTAINER Real Python \u003cinfo@realpython.com\u003e\n\n# install dependencies\nRUN apt-get -qq update\nRUN apt-get install -y python python-pip\n\n# grab contents of source directory\nADD ./src /src/\n\n# specify working directory\nWORKDIR /src\n\n# build app\nRUN pip install -r requirements.txt\nRUN python manage.py syncdb --noinput\n\n# expose port 8000 for us to use\nEXPOSE 8000\n\nCMD python manage.py runserver 0.0.0.0:8000\n```\n\n### Django Setup\n\nClone the repo to get started quickly. Alternatively, use your own Django Project. Just be sure to re-organize the project to match mine and add the *fig.yml* file. If you don't have any tests, be sure to add a few.\n\n### Signup for Docker Hub\n\nAlready have an account? Skip this section.\n\n1. Signup [here](https://hub.docker.com/account/signup/).\n1. Enter the docker-osx shell: `docker-osx shell`\n2. Login: `docker login`\n\n### Create your Image\n\n1. Build it:\n\n```sh\n$ docker build -t web .\n```\n\n2. Tag it:\n\n```sh\ndocker tag web \u003cyour_docker_login\u003e/web\n```\n\n3. Push it:\n\n```sh\n$ docker push \u003cyour_docker_login\u003e/web\n```\n\n## Deployment Workflow\n\n1. Code locally\n1. PUSH to Github\n1. Jenkins runs tests\n1. If tests fail, process ends\n1. If tests pass:\n    1. Docker Hub builds new image\n    1. Jenkis Deploys to Heroku\n\n## Code Locally\n\nIn the normal flow, you would ideally be a point where you're ready to deploy code to production. Perhaps you fixed a major bug or implemented a new feature. Create a commit and PUSH\n\n## Resources\n\nhttps://github.com/wsargent/docker-cheat-sheet","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealpython%2Fdjango-docker-tests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealpython%2Fdjango-docker-tests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealpython%2Fdjango-docker-tests/lists"}