To manage Docker containers, follow these steps:
Step 1 : Run a container:
This command runs a Docker container named "nginx" in detached mode (-d
), using the official nginx image from Docker Hub.
Step 2 : Stop the container:
This stops the running container named "nginx".
Step 3 : Get container ID:
The -a
flag lists all containers (including stopped ones), showing their details such as CONTAINER ID, IMAGE, COMMAND, CREATED, STATUS, PORTS, and NAMES.
Step 4 : Stop a container using its ID:
Replace <CONTAINER_ID>
with the actual ID of the container you want to stop. This command halts the specified container.
Step 5 : Start a stopped container:
Or start it by name:
This restarts a previously stopped container identified by <CONTAINER_ID>
or the specified name "nginx".
Step 6 : Remove a container by name or ID:
Use this command to delete a container by providing its name or ID.
Step 7 : To forcefully remove a running container:
Add the --force
or -f
flag to delete a container that's currently running. This command overrides any dependencies or processes that prevent the container from being removed.
Congratulations! You have successfully managed Docker containers by running, stopping, starting, and removing them as needed.