Skip to main content

Command Palette

Search for a command to run...

Day 18 - Exploring Docker Compose and Docker Image Management (Dec 14, 2023)

Published
2 min read
Day 18 - Exploring Docker Compose and Docker Image Management (Dec 14, 2023)
M

Hey there! I'm currently working as an Associate DevOps Engineer, and I'm diving into popular DevOps tools like Azure Devops,Linux, Docker, Kubernetes,Terraform and Ansible. I'm also on the learning track with AWS certifications to amp up my cloud game. If you're into tech collaborations and exploring new horizons, let's connect!

Understanding Docker Compose

Docker Compose Overview

Docker Compose is a powerful tool designed to define and share multi-container applications. Utilizing a YAML file, developers can configure services, establish links between containers, and seamlessly manage the entire environment with a single command.

What is YAML?

YAML (YAML Ain't Markup Language) is a data serialization language commonly used for configuration files. Its human-readable syntax makes it an excellent choice for defining complex structures. YAML files use a .yml or .yaml extension, and they focus on data representation rather than document markup.

Task-1: Docker Compose Configuration

To set up the environment and configure services, a docker-compose.yml file is created. This YAML file defines the services and links between different containers, allowing for efficient management of the entire application stack.

Sample docker-compose.yaml file:

version: '3'
services:
  web:
    image: nginx:alpine
  database:
    image: postgres:alpine

Now, let's explore using environment variables in the docker-compose.yml file to enhance flexibility and customization.


Task-2: Managing Docker Images and Containers

Running a Pre-existing Docker Image

Pulling a pre-existing Docker image from a public repository like Docker Hub and running it locally is a common DevOps task. Ensure to run the container as a non-root user for security purposes.

# Pulling and running the Docker image as a non-root user
docker run --user <username> <image_name>

Inspecting Container Details

Use the docker inspect command to gather detailed information about the container's running processes and exposed ports.

docker inspect <container_id>

Viewing Container Logs

The docker logs command helps monitor the container's log output.

docker logs <container_id>

Stopping, Starting, and Removing Containers

Manage container lifecycle with these commands:

docker stop <container_id>
docker start <container_id>
docker rm <container_id>

Running Docker Commands Without sudo

To execute Docker commands without sudo, follow these steps:

  1. Make sure Docker is installed and your system is updated.

  2. Add your user to the docker group:

  3.    sudo usermod -aG docker $USER
    

  4. Reboot your machine.


More from this blog

DevOps Journey with M Hassan

174 posts

I am writing these blogs because I recently completed a comprehensive DevOps course where I gained in-depth knowledge of the topics mentioned. As I progressed through the course, I realized the importance of having a concise and accessible resource to revise and reinforce my understanding of each topic. Therefore, I decided to create cheat sheets in the form of blog posts. These cheat sheets will not only serve as a handy reference for myself but also benefit others who are also interested in mastering DevOps concepts. By documenting each topic and providing concise explanations, I aim to create a valuable resource that simplifies complex concepts and facilitates hands-on practice. This way, I can solidify my own understanding while helping others on their DevOps journey.