Docker and Docker Compose

What is Docker ?
Docker is an open source platform for building, deploying, and managing containerized applications. This ecosystem around creating and running containers.
For example the ecosystem contains
1. Docker Client
2. Docker Server
3. Docker Machine
4. Docker Images
5. Docker Hub
6. Docker Compose
Containers simplify delivery of distributed applications, and have become increasingly popular as organizations shift to cloud-native development and hybrid multi-cloud environments.
Simply says , Docker makes it really easy to install and run software without worrying about setup or dependencies.

Docker at Windows/Mac

Simple Example for Docker client — server methodology


What is Container?
- Actual problem in normal system

2. Solution in normal system

3. How the Container Works



Commands that we are using
To list running containers =docker ps
To list all containers = docker ps -a
To see images = docker images
To create image = docker create <image-name>
To start container = docker start <container-id>
To start container & show output = docker start -a <container-id>
To run docker=docker create <image-name> + docker start <container-id>
To removing all stopped containers = docker system prune
To retrieving log outputs = docker logs <container id>
To get container id by using image name = docker run -it -d <image name>
To stop container = docker stop <container id>
To kill container = docker kill <container id>
To interact with container to cmd prompt = docker exec -it<container id> sh
To set tag = docker build -t <tagname/some:latest> . (@ current folder)
Creating Own Images
- create file — Dockerfile
- Config file

3. Build File — On the docker file directory

4. Run Container — docker run <container id>

Running Docker file for Spring-boot Application
- Create and build spring boot application
- Create Docker file
- Create Account in hub.docker.com
- Create repository at the hub.docker.com
Note : Options for connecting these containers
1. Use docker CLI’s Networking Features
2. Use Docker Compose
Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications at the same time.
With Compose,
1. Use a YAML file to configure your application’s services.
2. Then, with a single command, you create and start all the services from your configuration.
Compose works in all environments:
1.Production
2. Staging
3. Development
4. Testing as well as CI workflows.
Using Compose is basically a three-step process:
1. Define your app’s environment with a Dockerfile
so it can be reproduced anywhere.
2. Define the services that make up your app in docker-compose.yml
so they can be run together in an isolated environment.
3. Run docker compose up
and the Docker compose command starts and runs your entire app. You can alternatively run docker-compose up
using the docker-compose binary.
Simple Example
On this page you build a simple Python web application running on Docker Compose. The application uses the Flask framework and maintains a hit counter in Redis. While the sample uses Python, the concepts demonstrated here should be understandable even if you’re not familiar with it.
Prerequisites
Install docker engine and docker compose
Step 1: Setup — Create directory with any name

Step 2: Create a Project file — Here I used app.py

Step 3: Create text file -requirements.txt

Step 4: Create a Dockerfile

Step 5: Define services in a Compose file

Step 6: Build and run your app with Compose


Step 6: Finally check with browser — http://localhost:5000/

Note : Refresh the browser — you will see the count increment
Step 7: Edit the Compose file to add a bind mount

Step 8: Re-build and run the app with Compose

Step 8: Update the application

Note: Refresh the browser, It updates the changes

Step 8: Stop all services

I think this article was helpful to understand the docker and its features with small practical example. Stay in touch to learn more about latest technology.
Cheers..!