1. Docker
docker

2. Docker Images
docker images

3. Docker Image Pull
docker pull nginx
docker pull nginx:1.21 //version (tag) mentioned
Note

Without tag latest version is download. tag means version.


4. Docker Container Run
docker run nginx
docker run nginx:1.21

5. Docker Running Container Status
docker ps

*ps - Process Status


6. Docker Running & Stopped Container Status
docker ps -a

*-a - All Containers


7. Docker Image Remove
docker rmi 123456789abc

*rmi - Remove Image


8. Docker Container Size
docker ps --size

9. Docker Detached Mode
docker run -d nginx

*-d - Detached Mode


10. Port Mapping
docker run -d -p 8080:80 nginx:latest

*-p - Port
This maps port 8080 on the host to port 80 in the container running the nginx image.


11. Logs
docker logs containerid
docker logs -f containerid

*-f - Follow
The -f option (follow) keeps the log output streaming in real-time, similar to tail -f.

  docker logs containerid > filename.log

12. Docker Inspect
docker inspect 123456789abc

13. Docker Exec (Interactive Terminal)
docker exec -it 123456789abc bash

*-it -Interactive Terminal
Opens a Bash shell inside the running container.


14. Delete Container
docker rm containerid

*rm - remove

docker rm -f containerid

-f - force

docker stop containerid

15. Delete Image
docker rmi imageid

*rmi - remove image

docker rmi -f $(docker image -q)

16. Container Name Change
docker run --name my_nginx nginx:latest

Runs the nginx container with the name my_nginx.


17. Docker Build Image

 docker build -t myapp:1.0 .

Builds the Docker image from the current directory's Dockerfile and tags it as myapp with version 1.0.


18. Environment Variable Overwrite

  docker run --env ENV_VAR="production" myapp:1.0

Runs the container from the myapp:1.0 image and sets the environment variable ENV_VAR to "production" inside the container.


19. ARG Command (Build-Time Variables)

The ARG instruction defines a build-time variable in Docker that can be used in the Dockerfile and overridden during the image-building process.


20. Docker Volume

Volumes in Docker are used to persist data between container restarts and allow sharing data between the host machine and the container.

Types of Volumes:

  1. Binded Volume

    • Purpose: A bind mount directly links a directory or file from the host machine to a directory inside the container.
    • Command:
      docker run -v /path/to/localfolder:/path/to/containerfolder imagename:tag
      
    • Example:
      docker run -v /home/user/data:/app/data myapp:latest
      
      • In this case, the data folder on your host will be mapped to /app/data in the container.
  2. Unbinded Volume

    • Purpose: Docker-managed volumes are created and managed by Docker itself and do not map to a specific location on the host system.

    • Commands:

      • Create an unbound volume:
        docker volume create foldername
        
      • List Docker volumes:
        docker volume ls
        
      • Inspect a volume:
        docker inspect foldername
        
    • How to Use Unbinded Volumes:

      docker run -it -v foldername:/app/data imagename:tag
      
      • This command mounts the Docker-managed volume (foldername) to /app/data inside the container.
  3. Filtering by Volume

    • Purpose: You can filter running containers based on the volumes they are using.
    • Command:
      docker ps -a --filter volume=foldername
      
  4. Unbinding a Docker Volume

    • Purpose: Detach a volume from a container.
    • Command:
      You can stop the container and remove it, which will detach the volume.
      docker rm containerid
      

21. Docker Login


22. Docker Push