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}}"
>>> Check the logs
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
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:
docker run: Create and start a new container from an image. Example:docker run -d --name my-container my-imagedocker start: Start an existing stopped container. Example:docker start my-containerdocker stop: Stop a running container. Example:docker stop my-containerdocker restart: Restart a running container. Example:docker restart my-containerdocker ps: List running containers. Example:docker psdocker ps -a: List all containers (including stopped ones). Example:docker ps -adocker exec: Execute a command inside a running container. Example:docker exec -it my-container bashdocker logs: Display the logs of a container. Example:docker logs my-containerdocker rm: Remove a stopped container. Example:docker rm my-container
Image Management:
docker build: Build a Docker image from a Dockerfile. Example:docker build -t my-image .In the
docker buildcommand, the-tflag 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
-tflag 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.docker pull: Pull an image from a registry. Example:docker pull ubuntu:latestdocker push: Push an image to a registry. Example:docker push my-user/my-imagedocker images: List available images. Example:docker imagesdocker rmi: Remove an image. Example:docker rmi my-image
Volume Management:
docker volume create: Create a named volume. Example:docker volume create my-volumedocker volume ls: List volumes. Example:docker volume lsdocker volume inspect: Inspect volume details. Example:docker volume inspect my-volumedocker volume rm: Remove a volume. Example:docker volume rm my-volume
Network Management:
docker network create: Create a custom network. Example:docker network create my-networkdocker network ls: List networks. Example:docker network lsdocker network inspect: Inspect network details. Example:docker network inspect my-networkdocker network rm: Remove a network. Example:docker network rm my-network
Docker Compose (for multi-container applications):
docker-compose up: Start services defined in a Compose file. Example:docker-compose up -ddocker-compose down: Stop and remove services defined in a Compose file. Example:docker-compose downdocker-compose ps: List services and their status. Example:docker-compose ps
Miscellaneous:
docker info: Display system-wide information about Docker. Example:docker infodocker version: Display Docker version information. Example:docker versiondocker inspect: Inspect detailed information about a container, image, network, or volume. Example:docker inspect my-containerdocker 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
Post a Comment