#Day20: Docker  Cheat sheet  for DevOps Engineers.

#Day20: Docker Cheat sheet for DevOps Engineers.

ยท

2 min read

Docker is a powerful tool in DevOps workflows. Here's a set of detailed commands that cover various aspects of using Docker in a DevOps context:

1. Working with Images:

  • Pull an Image:

      docker pull image-name:tag
    
  • Build an Image from Dockerfile:

      docker build -t image-name:tag path/to/Dockerfile-directory
    
  • List Images:

      docker images
    
  • Remove an Image:

      docker rmi image-id
    

2. Running Containers:

  • Run a Container:

      docker run -it image-name:tag
    
  • Run a Detached Container:

      docker run -d image-name:tag
    
  • Run with Port Mapping:

      docker run -p host-port:container-port image-name:tag
    
  • Run with Environment Variables:

      docker run -e VARIABLE_NAME=value image-name:tag
    

3. Container Management:

  • List Running Containers:

      docker ps
    
  • List All Containers (including stopped):

      docker ps -a
    
  • Start a Stopped Container:

      docker start container-id
    
  • Stop a Running Container:

      docker stop container-id
    
  • Restart a Container:

      docker restart container-id
    
  • Remove a Container:

      docker rm container-id
    

4. Networking:

  • Create a Custom Network:

      docker network create network-name
    
  • Run a Container on a Specific Network:

      docker run --network network-name image-name:tag
    

5. Volumes:

  • Create a Volume:

      docker volume create volume-name
    
  • Run a Container with a Volume:

      docker run -v volume-name:/path/in/container image-name:tag
    

6. Docker Compose:

  • Run Services Defined in docker-compose.yml:

      docker-compose up
    
  • Stop and Remove Services:

      docker-compose down
    

7. System Cleanup:

  • Prune Unused Resources:

      docker system prune
    
  • Remove All Stopped Containers:

      docker container prune
    
  • Remove Dangling Images:

      docker image prune
    

Remember that these commands provide a solid foundation for using Docker in a DevOps environment. As your requirements evolve, you might need to explore more advanced Docker features and workflows to optimize your DevOps processes.

ย