Docker_Commands
Docker_Commands
SIMULATOR
Link: https://docs.docker.com/engine/install/ubuntu/
[Steps for Installing Dockers]
1. Set up Docker's apt repository:
# Add Docker's official GPG key:
Step 1: sudo apt-get update
Step 2: sudo apt-get install ca-certificates curl
Step 3: sudo install -m 0755 -d /etc/apt/keyrings
Step 4: sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
Step 5: sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
Step 6:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc]
https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Docker Commands:
1. Docker Version Check: docker --version or docker version
2. List Docker Images: docker images
3. List Running Containers: docker ps
4. List All containers (Running and Stopped): docker ps -a
5. Pull the Busy Box image: docker pull busybox
6. Run a Busy Box image: docker run busybox
7. Run a Busy Box image with an interactive shell: docker run -it busybox
8. Run a Busy Box container and execute a command: docker run busybox echo “Hello from
busybox”
9. Stop a running container: docker stop <container id>
10. Remove a container: docker rm <container id>
11. Remove an image: docker rmi busybox
Common Commands to run inside the busy box:
1. Run busy box with an interactive shell: docker run -it busybox sh
2. Check the version of busybox: busybox
3. View the File Systems: ls
4. Display the current directory: pwd
5. Create a new directory: mkdir /mydir
6. Change to different directory: cd /mydir
7. Create a new file: echo “Hello, Busy box” > hello.txt
8. View the content of the file: cat hello.txt
9. Delete a file: rm hello.txt
10. Check IP Address: ifconfig
11. Ping a host: ping google.com
12. List Running Process: ps
13. Kill a process: kill <pid>
14. Display date and time: date
15. Disk usage: df -h
16. Check memory usage: free
17. Exit the busy box: exit
*************************************************************************************
FEW MORE BASIC COMMANDS
Docker Installation & Version Check
docker --version # Show Docker version
docker info # Display system-wide information
Docker Images
docker pull <image_name> # Download image from Docker Hub
docker images # List all downloaded images
docker rmi <image_name> # Remove an image
docker tag <image_id> <new_tag> # Tag image with a new name
Docker Containers
docker run <image_name> # Run container from image
docker run -it <image_name> /bin/bash # Run container in interactive mode
docker run -d <image_name> # Run container in detached mode
docker run --name mycontainer <image_name> # Run container with a custom name
docker ps # List running containers
docker ps -a # List all containers
docker start <container_id> # Start a stopped container
docker stop <container_id> # Stop a running container
docker restart <container_id> # Restart a container
docker rm <container_id> # Remove a container
Docker Networks
docker network ls # List all networks
docker network inspect <network_name> # Inspect a specific network
docker network create <network_name> # Create a new Docker network
docker network rm <network_name> # Remove a Docker network
Docker Volumes
docker volume ls # List all volumes
docker volume create <volume_name> # Create a volume
docker volume inspect <volume_name> # Inspect a volume
docker volume rm <volume_name> # Remove a volume