Skip to content

Files

Latest commit

 

History

History
43 lines (32 loc) · 2.13 KB

3_docker_commands.md

File metadata and controls

43 lines (32 loc) · 2.13 KB

This provides a comprehensive overview of various Docker commands and their use cases. Here's a summary:

  1. docker run:

    • Used to run a container from an image.
    • If the image isn't present on the host, Docker pulls it from Docker Hub (only the first time).
    • Example: docker run nginx runs an instance of the nginx application.
  2. docker ps:

    • Lists all running containers and basic information (ID, image, status, name).
    • Use docker ps -a to see all containers, including stopped or exited ones.
  3. Stopping and Removing Containers:

    • Use docker stop [container ID or name] to stop a container.
    • Use docker rm [container ID or name] to remove a stopped or exited container.
  4. Managing Images:

    • docker images lists available images on the host.
    • To remove an image, use docker rmi [image name], ensuring no dependent containers are running.
  5. docker pull:

    • Use it to download an image without running a container.
    • Example: docker pull ubuntu pulls the Ubuntu image.
  6. Behavior of Containers:

    • Containers are designed to run a specific task; they exit once the task is complete.
    • Running a container from an OS image like Ubuntu will exit immediately if no task is specified.
  7. Executing Commands in Containers:

    • docker exec [container ID or name] [command] executes a command in a running container.
    • Example: docker exec to view the contents of a file in a container.
  8. Running Containers in Foreground and Background:

    • Default: Containers run in the foreground (attached mode).
    • Use -d option to run in detached (background) mode.
    • Use docker attach [container ID or name] to reattach to a running container.
  9. Example of a Web Application Container:

    • Running a web application (e.g., xyz/simple-webapp) that listens on a specific port.
  10. Short IDs in Commands:

  • When specifying container IDs in commands, the initial characters are enough as long as they're unique.

This lecture is a great primer for those beginning with Docker, providing essential commands and insights into container behavior and management.