Docker

From HyperSecurity Wiki
Revision as of 07:13, 28 January 2025 by Srapaz (talk | contribs)
(diff) ←Older revision | view current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Installing Image

  1. Search docker image
    • docker search <image-name>
  2. Download base image from docker:
    • docker run -d --name nginx-test --net <custom-network> <nginx:latest>

Networking

  1. Create a docker network:
    • docker network create --subnet=<192.168.1.0/24> <my-custom-network>

Listing

  1. List All Docker Containers:
    • docker ps -a
  2. List all networks:
    • docker network list
  3. Inspect docker container:
    • docker inspect <container id>

Starting/Stopping

  1. Start docker container:
    • docker start <container id>
  2. Stop docker container:
    • docker stop <container id>
  3. Stop all docker containers:
    • docker stop $(docker ps -a -q)
  4. Remove all docker containers:
    • docker stop $(docker ps -a -q)
  5. Starting all docker containers with compose:
    • docker-compose up
  6. Stopping all docker containers with compose:
    • docker-compose down

Accessing Container

  1. Enter a running conntainer
    • docker exec -it <container id> /bin/bash

Deleting/Cleaning

  1. Removing a single container:
    • docker rmi -f <container id>
  2. Delete no longer needed containers:
    • docker container prune
  3. Delete no longer needed images:
    • docker image prune
  4. Delete no longer needed networks:
    • docker network prune
  5. Delete no longer needed trash:
    • docker system prune