WE CODE NOW
  • Home 
  • Blog 
  • Guides 
Guides
  1. Home
  2. Guides
  3. Linux Command Series
  4. Docker Basics in Linux

Docker Basics in Linux

Posted on June 1, 2024  (Last modified on June 8, 2024) • 2 min read • 263 words
Linux
 
Docker
 
Containers
 
Docker Compose
 
Linux
 
Docker
 
Containers
 
Docker Compose
 
Share via

Get started with Docker in Linux, including installing Docker, managing containers, and using Docker Compose for multi-container applications.

On this page
  • Installing Docker
    • Using the Convenience Script
    • Installing from the Repository
  • Managing Docker Containers
    • Running a Container
    • Listing Containers
    • Stopping and Removing Containers
    • Viewing Container Logs
  • Using Docker Compose
    • Installing Docker Compose
    • Creating a Docker Compose File
    • Running Docker Compose
  • Conclusion

Docker Basics in Linux  

Docker is a powerful tool for containerization. This guide covers getting started with Docker in Linux, including installing Docker, managing containers, and using Docker Compose for multi-container applications.

Installing Docker  

Using the Convenience Script  

Install Docker using the convenience script.

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Installing from the Repository  

Set up the Docker repository.

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Install Docker Engine.

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Managing Docker Containers  

Running a Container  

Use docker run to start a container.

docker run hello-world

Listing Containers  

List running containers.

docker ps

List all containers, including stopped ones.

docker ps -a

Stopping and Removing Containers  

Stop a running container.

docker stop container_id

Remove a stopped container.

docker rm container_id

Viewing Container Logs  

View logs of a container.

docker logs container_id

Using Docker Compose  

Installing Docker Compose  

Install Docker Compose.

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Creating a Docker Compose File  

Create a docker-compose.yml file.

version: '3'
services:
  web:
    image: nginx
    ports:
      - "80:80"
  db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: example

Running Docker Compose  

Start the application using Docker Compose.

docker-compose up

Stop the application.

docker-compose down

Conclusion  

Getting started with Docker in Linux involves installing Docker, managing containers, and using Docker Compose for multi-container applications. Practice these basics to effectively use Docker in your development and deployment workflows.

 Linux Networking: SSH and SCP
Kubernetes Basics in Linux 
On this page:
  • Installing Docker
    • Using the Convenience Script
    • Installing from the Repository
  • Managing Docker Containers
    • Running a Container
    • Listing Containers
    • Stopping and Removing Containers
    • Viewing Container Logs
  • Using Docker Compose
    • Installing Docker Compose
    • Creating a Docker Compose File
    • Running Docker Compose
  • Conclusion
Copyright © 2024 WE CODE NOW All rights reserved.
WE CODE NOW
Link copied to clipboard
WE CODE NOW
Code copied to clipboard