Difference between revisions of "Docker"

From HyperSecurity Wiki
Jump to: navigation, search
 
Line 4: Line 4:
 
#Download base image from docker:
 
#Download base image from docker:
 
#*<pre>docker run -d --name nginx-test --net <custom-network> <nginx:latest></pre>
 
#*<pre>docker run -d --name nginx-test --net <custom-network> <nginx:latest></pre>
 +
 +
==Networking==
 +
#Create a docker network:
 +
#*<pre>docker network create --subnet=<192.168.1.0/24> <my-custom-network></pre>
  
 
==Listing==
 
==Listing==

Latest revision as of 07:13, 28 January 2025

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