What is docker? — IBM definition
Docker is an open source containerization platform. It enables developers to package applications into containers—standardized executable components combining application source code with the operating system (OS) libraries and dependencies required to run that code in any environment
Containerization — IBM definition
Containerization is the packaging of software code with just the operating system (OS) libraries and dependencies required to run the code to create a single lightweight executable—called a container—that runs consistently on any infrastructure
Why should we care about docker?
- Reproducibility
- Local experiments
- Integration tests (CI/CD) - General software engineering best practices
- Running pipelines on the cloud using this docker image of the data pipeline
- Serverless (AWS Lambda, Google Functions)
- Apache Spark, Apache Kafka, Apache Airflow
Running PostgreSQL in docker
The following command is used to run PostgreSQL with docker:
|
|
Also, using pgcli to connect to postgres:
|
|
We can use pgAdmin or pgcli to interact with our postgres database.
Since we are using Docker, we don’t have to install pgAdmin in our host system, and we can simply use Docker to pull an image of pgAdmin.
To run pgAdmin in Docker we can run the following command:
|
|
Linking Two Different Containers
Now, since postgres and pgAdmin are running in different containers we need to be able to link them together
We can do this by putting the two docker containers under one network using the following command:
docker network create pg-network
Now using the following arguments when using docker run -it
command:
|
|
Docker Compose
A way to put together multiple services in one config file
Instead of running multiple docker commands with docker configurations in them. We can create one yml file with the config information. For this we will use docker compose.
This is how a docker-compose file would look like in our case:
|
|
We don’t need to define a network for this as the images here automatically become part of the same network
Run:
|
|
Run in detached mode:
|
|
Shutting it down:
|
|