Docker containers
Container management in Docker involves a variety of commands and options to create, manipulate, and monitor containers effectively. Here's a discussion of some common container management commands and options in Docker:
- Creating Containers:
- "docker run": This command is used to create and run a new container based on a specified image. Options include "-d" for detached mode, "-p" for port mapping, "-v" for volume mounting, "--name" for assigning a custom name to the container, and more.
- Starting and Stopping Containers:
- docker start: Starts one or more stopped containers.
- docker stop: Stops one or more running containers gracefully by sending a SIGTERM signal to the main process.
- docker restart: Restarts one or more running containers.
- docker pause: Pauses all processes within one or more running containers.
- docker unpause: Resumes execution of one or more paused containers.
- Deleting Containers:
- docker rm: Deletes one or more containers. Use the "-f" option to force deletion of running containers.
- docker container prune: Deletes all stopped containers. This is a convenient way to clean up your system from unused containers.
- Viewing Container Information:
- docker ps: Lists all running containers. Use the "-a" option to include stopped containers.
- docker inspect: Displays detailed information about one or more containers, including metadata, configuration, and networking.
- Managing Container Resources:
- docker update: Updates the resource limits (such as CPU shares or memory) of one or more containers.
- docker stats: Provides real-time usage statistics for all running containers, including CPU, memory, network, and disk I/O.
- Executing Commands in Containers:
- docker exec: Runs a command inside a running container. Use the "-it" option for interactive mode (e.g., to access a container's shell).
- Copying Files to/from Containers:
- docker cp: Copies files or directories between a container and the local filesystem. This is useful for transferring data into or out of containers.
- Container Logs:
- docker logs: Fetches the logs of a container, allowing you to view stdout/stderr output. Use the "-f" option to follow logs in real-time.
- Attaching to Containers:
- docker attach: Attaches the terminal input/output of the local machine to a running container's stdin/stdout. This allows you to interact with the container's processes.
- Container Networking:
- docker network: Manages Docker networks, allowing containers to communicate with each other and with external networks. Options include creating, inspecting, connecting, and disconnecting from networks.
These commands and options provide a comprehensive set of tools for managing Docker containers efficiently.