What are the top 10 basic Docker commands I should know and briefly explain what they…
- User
What are the top 10 basic Docker commands I should know and briefly explain what they do. Give examples with code format output
- Assistant
docker run: This command is used to create and start a new Docker container. It takes the image name as its argument and can be used to specify various options such as port forwarding, environment variables, and volume mounts.
Example:
docker run -p 8080:80 nginxwill run an Nginx container and map the container's port 80 to the host's port 8080.docker ps: This command lists all the currently running Docker containers.
Example:
docker pswill display all running containers.docker stop: This command is used to stop a running container.
Example:
docker stop container_namewill stop a container with the specified name.docker rm: This command is used to remove a stopped container.
Example:
docker rm container_namewill remove a container with the specified name.docker pull: This command is used to download a Docker image from a registry.
Example:
docker pull nginxwill download the latest Nginx image from the Docker Hub.docker images: This command lists all the images that are currently available on the system.
Example:
docker imageswill display all the available images.docker rmi: This command is used to remove an image.
Example:
docker rmi nginxwill remove the Nginx image from the system.docker exec: This command is used to run a command in a running container.
Example:
docker exec -it container_name shwill start an interactive shell in the specified container.docker build: This command is used to build a Docker image from a Dockerfile.
Example:
docker build -t my_image .will build an image with the tag "my_image" from the Dockerfile in the current directory.docker-compose: This command is used to start a multi-container Docker application defined in a docker-compose.yml file.
Example:
docker-compose upwill start all the containers defined in the docker-compose.yml file.