{"id":15705319,"url":"https://github.com/brahmlower/code-tacoma-docker-presentation","last_synced_at":"2025-10-12T12:44:32.080Z","repository":{"id":86081482,"uuid":"144122033","full_name":"brahmlower/code-tacoma-docker-presentation","owner":"brahmlower","description":"Docker introduction \u0026 basics for CodeTacoma meetup","archived":false,"fork":false,"pushed_at":"2018-08-09T08:19:38.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-22T03:38:20.379Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/brahmlower.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-09T08:17:20.000Z","updated_at":"2018-08-10T17:00:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"95dbe0ad-14ae-4a42-aadc-c41b8a769c72","html_url":"https://github.com/brahmlower/code-tacoma-docker-presentation","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"4320668eb2a95c8076dfb6a5f8df075184d7632a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brahmlower/code-tacoma-docker-presentation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brahmlower%2Fcode-tacoma-docker-presentation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brahmlower%2Fcode-tacoma-docker-presentation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brahmlower%2Fcode-tacoma-docker-presentation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brahmlower%2Fcode-tacoma-docker-presentation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brahmlower","download_url":"https://codeload.github.com/brahmlower/code-tacoma-docker-presentation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brahmlower%2Fcode-tacoma-docker-presentation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011299,"owners_count":26084928,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-03T20:15:24.973Z","updated_at":"2025-10-12T12:44:32.038Z","avatar_url":"https://github.com/brahmlower.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Introduction to Docker\n\nThis repository demonstrates some of the basics of docker and docker-compose through the use of a simple flask API backed with a database.\n\n- [Building via Docker](https://github.com/bplower/code-tacoma-docker-presentation#building-via-docker)\n- [Running via Docker](https://github.com/bplower/code-tacoma-docker-presentation#running-via-docker)\n- [Building via Docker Compose](https://github.com/bplower/code-tacoma-docker-presentation#building-via-docker-compose)\n- [Running via Docker Compose](https://github.com/bplower/code-tacoma-docker-presentation#running-via-docker-compose)\n- [Databae initialization](https://github.com/bplower/code-tacoma-docker-presentation#database-initialization)\n- [Local development](https://github.com/bplower/code-tacoma-docker-presentation#local-development)\n- [Tooling glossary](https://github.com/bplower/code-tacoma-docker-presentation#tooling-glossary)\n\n## Building via Docker\n\nFrom the `buildings-api` directory, you can build the image by running:\n\n```\ndocker build .\n```\n\nYou can verify the image has been built by listing the images:\n\n```\nbrahm@localhost ~/buildings-api $ docker image ls\nREPOSITORY                                                      TAG                 IMAGE ID            CREATED             SIZE\n\u003cnone\u003e                                                          \u003cnone\u003e              f0e9c51a0387        41 seconds ago      164MB\n```\n\nOur image has been built, but it doesn't have a name, so we can only reference it via the image hash. Referencing \"f0e9c51a0387\" isn't very clear, so we're going to rebuild the image with a proper name:\n\n```\ndocker build . -t buildings-api\n```\n\nThe end of the output will look something like the following:\n\n```\n ---\u003e Using cache\n ---\u003e f0e9c51a0387\nSuccessfully built f0e9c51a0387\nSuccessfully tagged buildings-api:latest\n```\n\nThe name of the image just a fancy tag. The tag \"latest\" was applied since we didn't specify any sort of version. We can specify a proper version number like so:\n\n```\ndocker build . -t buildings-api:0.1.0\n```\n\nIf we list our images, we'll see that the hash referenced by `buildings-api:latest` and `buildings-api:0.1.0` is the same, indicating that they are the exact same image, just with different tags.\n\n```\nbrahm@localhost ~/buildings-api $ docker image ls\nREPOSITORY                                                      TAG                 IMAGE ID            CREATED             SIZE\nbuildings-api                                                   0.1.0               f0e9c51a0387        9 minutes ago       164MB\nbuildings-api                                                   latest              f0e9c51a0387        9 minutes ago       164MB\n```\n\n## Running via Docker\n\nNow that we have our docker image, let run it! The process of running the image effectively creates an instance of the image, which is called a container.\n\n```\nbrahm@localhost ~/buildings-api $ docker run buildings-api\nNo such file or directory: 'settings.yml'\n```\n\nBoooooo! This isn't what we want! Our application is expecting a configuration file at the path \"/app/settings.yml\" within the container, but that file wasn't included when the image was built. This was intentional because including such a file would be roughly equivalent to hardcoding settings in code itself. Now we need to run our docker container and give it access to a local configuration file to use:\n\n```\nbrahm@localhost ~/buildings-api $ docker run -v $(pwd)/settings.example.yml:/app/settings.yml:ro buildings-api\nFailed to connect to database.\n```\n\nThe server failed to start completely, but not because of configuration file problems- we simply can't connect to the database to initialize our connection pool. Lets talk about what we just did for a moment before moving forward. We've included a simple form of the volume (`-v`) option while calling docker run. Here we've taken the path of the `settings.example.yml` file and mounted it to the `/app/settings.yml` path inside the container- exactly where our server expects it to be. Lastly, we included the `:ro` label, which indicates that the volume should be mounted within the container as read-only. This is a good security practice since you don't want anything (or anyone) in the container to be able to change this file. I would recommend reading the [official documentation](https://docs.docker.com/storage/volumes/) on the volume option since it provides much more functionality than is used here.\n\n## Building via Docker Compose\n\nDocker compose can make the process of building an image easier. If you look at the `docker-compose.yml` file, you'll see that we've defined a service called \"buildings-api\". That service has information about where the dockerfile is located, what volumes to mount, and what ports to forward. All of this information would have otherwise been provided on the commandline, but instead we can simply build our image by running:\n\n```\ndocker-compose build api\n```\n\n## Running via Docker Compose\n\nRun the service and its dependent services via the \"up\" command:\n\n```\ndocker-compose up\n```\n\nIt's worth noting here that docker-compose is mounting the settings file here in the root directory of the project rather than the example settings file. There's a small difference between the two: the database hostname is set to \"db\" here. When docker-compose runs the two containers together, it ensures they can communicate with each other based on their service names. Since the database service name is \"db\", it can be resolved on the network as \"db\".\n\n\u003caside class=\"notice\"\u003e\nThe api container may fail here the first time you run this. The database takes a moment to initialize for the first time, and the api service will likely attempt to connect before the database is actually listening for connections. There are ways around this, but that's outside the scope of this tutorial. In our case, cancel the process (ctrl+c) and run it again and the database should start up in time.\n\u003c/aside\u003e\n\nNow that the service is running, lets verify we can actually communicate with it. In another terminal we should see the following:\n\n```\nbrahm@localhost ~/ $ curl http://localhost:9090/\n{'message':'Hello world!'}%\n```\n\nThis is also a good example of how ports can be forwarded through to containers. In the settings.yml file, you'll see that we've told the service to listen on port 8080, but when we try to talk to it, we end up talking to it on port 9090. That's because docker is forwarding port 9090 on your host to port 8080 on the container.\n\n## Database initialization\n\nAt this point if we try to query the list of buildings, we'll recieve a 500 error since we haven't initialized our database yet. While you have `docker-compose up` running, in another terminal, run the following make targets:\n\n```\nmake db-init\nmake db-load\n```\n\nThis will create the \"buildings\" table in the database and add some very basic data to it.\n\nNow we'll recieve some proper data when we query the api:\n\n```\nbrahm@localhost ~/ $ curl http://localhost:9090/buildings/6\n{'id': 6, 'name': 'One World Trade Center', 'height': 541, 'city': 'New York City', 'country': 'United States'}%\n```\n\n## Local development\n\nWhenever testing `buildings-api` locally, install it within a python virtual environment to avoid polluting your local system.\n\n```\nvirtualenv -p python3 venv\nsource venv/bin/activate\n```\n\nNow you can install the server within your virtual environment, and verify it runs as expected. Installing the package make the `buildings-api` executable available in your path.\n\n```\npip install buildings-api/\nbuildings-api buildings-api/settings.example.yml\n```\n\nThe application expects the path to a settings file as its first argument. An example settings file is provided in the buildings-api directory. For additional information about the buildings-api application and its settings, see the readme in the buildings-api directory.\n\n## Tooling glossary\n\nThis is just a list of links to additional information about tools or features used in this project. This list may be incomplete and will expand as I have more time.\n\n- Docker\n- [Docker volumes](https://docs.docker.com/storage/volumes/)\n- Docker compose\n- Python's virtualenv\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrahmlower%2Fcode-tacoma-docker-presentation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrahmlower%2Fcode-tacoma-docker-presentation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrahmlower%2Fcode-tacoma-docker-presentation/lists"}