According to Docker docs, Docker is a tool that provides OS-level virtualization to deliver software in packages called containers.
Docker made application containers easy to use by providing a simplified, opinionated wrapper around existing Linux distribution invoked as containers, process control, security, and resource management technologies.
Docker excels in these two key areas:
- Packaging applications
- Process isolation and management
Docker helps you package and run applications inside isolated little boxes with all platform and application dependencies provided, thus keeping the hosting computer nice and tidy.
Docker solves problems associated with :
- Missing or incorrect application dependencies such as libraries, interpreters, code/binaries, users, Os packages, etc
- Conflicts between programs running on the same host machine such as library dependencies or ports; Example: local Django trying to use port 80
- Insufficient system resources required to run an application such as CPU and memory.
Let’s see how Docker delivers on its promise to “Build, Ship, and Run” applications easily 😃.
Packaging an Application Into An Image
This OS-level virtualization provided by Docker helps us mirror the application and platform into a
docker file. The
docker file should be placed at the root of the Django project.
Docker images also allow you to define metadata and define more options to help operators run the application according to your application needs.
Setting Up A Docker-compose.yml File
For clarity, Docker Compose solves the problem of running multi-container applications at once. You thus can set the desired amount of containers counts, their builds, services, and volumes, and then with a single set of commands, you can build, run, and configure all the containers.
According to Docker-compose Docs Using Compose is basically a three-step process:
- Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
- Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
- Run docker-compose up and Compose starts and runs your entire app.
it is also located in the root directory of the Django application. The Docker environment variable file
.env is necessary when you're creating complex containers or Database service for deployments.
So let’s say you have your
.env file (that's the full name of the file, by the way) located in the same directory that houses your
docker-compose.yml file. In the
.env file, you have on these lines:
docker-compose.yml looks like this:
We’re all set now, lets build and run our container using this simple command :
That’s a simple introduction to how application containers can help your team solve many common packaging, distribution, and operational problems; while helping you ship better software 🤓.
Originally published at https://blog.nextwebb.tech.