All - Docker Commands

 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 Docker Tutorial for Beginners [FULL COURSE in 3 Hours] (youtube.com)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

docker ps 

docker ps -a     //  -- if you close your terminal and reopen and if you want to see which containers are available

docker stop <container_id>

docker start <container_id>

>>> To get to the docker container termial

 docker exec -it <container_id> /bin/bash
OR
 docker exec -it <container_name> /bin/bash

>>> docker creates its own isolated network

docker network ls

docker network create <network-name>  //mongo-network

now to make our mongodb container and mongo-express run this mongo-network we need to provide this network option when we run the container.


Docker Compose file.


docker-compose -f <file.yaml> up  
or 
docker-compose -f <file.yaml> up  -d

docker compose creates the network automatically even though you dont specify the network inside the docker compose file

stopping the containers using docker compose, this also removes the network.

docker-compose -f <file.yaml> down

application developed via java script has to be packaged into a docker container.


dockerfile


CMD ["node", "/home/app/server.js"]  -- this is the correct location of server.js

docker build -t my-app:1.0 .

then say 

docker images , the image should be available

docker run -p 


>>> List the names of the docker container

docker ps --format "{{.ID}}: {{.Names}}"

docker ps -a --format "{{.Names}}"

>>> Check the logs 

docker logs <cointainer_id>
or
docker logs <container_name>

>>>When you create a container, it is assigned with some random name - But if you want your containers to have a specific name

docker run -p6000:3000 -d --name redis-older redis:4.0

deleting a docker image

$ docker image ls <imagename>

docker rmi <image_id> 

first you need to delete the container only then you can delete an image if the container is available then the image cannot be deleted.

deleting a container

docker rm <container_id> or <container_name>

now you can delete the image

docker rmi <image_id> 










Certainly! Below is a comprehensive list of various Docker commands along with brief descriptions of their purposes. This list covers many common Docker operations for managing containers, images, networks, volumes, and more.

Please note that the command usage examples provided are simplified for demonstration purposes, and you should adapt them to your specific use case.

Container Management:

  1. docker run: Create and start a new container from an image. Example: docker run -d --name my-container my-image

  2. docker start: Start an existing stopped container. Example: docker start my-container

  3. docker stop: Stop a running container. Example: docker stop my-container

  4. docker restart: Restart a running container. Example: docker restart my-container

  5. docker ps: List running containers. Example: docker ps

  6. docker ps -a: List all containers (including stopped ones). Example: docker ps -a

  7. docker exec: Execute a command inside a running container. Example: docker exec -it my-container bash

  8. docker logs: Display the logs of a container. Example: docker logs my-container

  9. docker rm: Remove a stopped container. Example: docker rm my-container

Image Management:

  1. docker build: Build a Docker image from a Dockerfile. Example: docker build -t my-image .


    In the docker build command, the -t flag is used to specify a name and optional tag for the image that you're building. It allows you to assign a custom name and version tag to the image, making it easier to manage and reference.

    The -t flag is followed by the desired name and tag in the format <name>:<tag>.

    For example:

    docker build -t my-image:latest .


    In this command:

        -t specifies the tag flag.
        my-image is the custom name you're assigning to the image.
        latest is the optional tag that indicates the version of the image. It's common to use "latest" for the most recent version, but you can use any descriptive tag you prefer.

    The -t flag helps you label and organize your Docker images, making it easier to track different versions of your application or configurations. It's especially useful when working with image repositories or when sharing images with colleagues or deployment environments.




  2. docker pull: Pull an image from a registry. Example: docker pull ubuntu:latest

  3. docker push: Push an image to a registry. Example: docker push my-user/my-image

  4. docker images: List available images. Example: docker images

  5. docker rmi: Remove an image. Example: docker rmi my-image

Volume Management:

  1. docker volume create: Create a named volume. Example: docker volume create my-volume

  2. docker volume ls: List volumes. Example: docker volume ls

  3. docker volume inspect: Inspect volume details. Example: docker volume inspect my-volume

  4. docker volume rm: Remove a volume. Example: docker volume rm my-volume

Network Management:

  1. docker network create: Create a custom network. Example: docker network create my-network

  2. docker network ls: List networks. Example: docker network ls

  3. docker network inspect: Inspect network details. Example: docker network inspect my-network

  4. docker network rm: Remove a network. Example: docker network rm my-network

Docker Compose (for multi-container applications):

  1. docker-compose up: Start services defined in a Compose file. Example: docker-compose up -d

  2. docker-compose down: Stop and remove services defined in a Compose file. Example: docker-compose down

  3. docker-compose ps: List services and their status. Example: docker-compose ps

Miscellaneous:

  1. docker info: Display system-wide information about Docker. Example: docker info

  2. docker version: Display Docker version information. Example: docker version

  3. docker inspect: Inspect detailed information about a container, image, network, or volume. Example: docker inspect my-container

  4. docker prune: Remove unused resources (containers, images, networks, volumes). Example: docker system prune

These are just some of the fundamental Docker commands you might use in your everyday tasks. Docker provides a rich set of functionality for managing containers and their associated resources, enabling efficient application deployment and development workflows. Always refer to the official Docker documentation for complete and up-to-date information on command usage and options.

 

Comments

Popular posts from this blog

Docker Commands

Docker: Create a Docker file - IMAGE

Docker Volumes