Docker Commands with Explanations
Command: docker exec -it container4 /bin/sh
Explanation: Starts an interactive shell session inside the running container named 'container4'.
Useful for debugging or interacting with the container.
Command: exit
Explanation: Exits the interactive shell session and returns to your host terminal.
Command: docker network remove mynetwork
Explanation: Removes the Docker network named 'mynetwork'. This will fail if any container is still
connected to the network.
Command: ping container3 (inside container4)
Explanation: Checks network connectivity from container4 to container3. This confirms if both
containers are connected to the same network.
Command: docker stop container3 container4
Explanation: Stops the containers named 'container3' and 'container4'.
Command: docker rm container3 container4
Explanation: Removes the containers named 'container3' and 'container4'. Useful for cleanup.
Command: docker network inspect mynetwork
Explanation: Shows detailed information about the 'mynetwork' network including connected
containers and IP address info.
Command: docker run -d --name container3 --network mynetwork alpine
Explanation: Runs a new container in detached mode with the name 'container3', connected to
'mynetwork', using the lightweight Alpine Linux image.
Command: docker run --rm --network host -it alpine sh
Explanation: Runs an Alpine container interactively with a shell. It uses the host's network directly
and removes the container after exit.