What is Docker Container ?
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.
Managing containers is a day-to-day activity of DevOps teams. Here is a list of Docker commands to manage containers.
#docker ps
To list currently running containers.
docker ps
#docker ps -a
To list all docker containers.
docker ps -a
#docker run --name
To create and run a container from an image.
docker run --name <container_name> <image_name>
#docker run -p
To run a container with port mapping.
docker run -p <host_port>:<container_port> <image_name>
#docker run -d
To run a container in the background.
docker run -d <image_name>
#Running Docker container along with name and Port
#docker start | stop
To start or stop an existing container.
docker start|stop <container_name> (or <container-id>)
#docker rm
To remove a stopped container.
docker rm <container_name>
#docker exec -it
To open a shell inside a running container.
docker exec -it <container_name> sh
#docker logs
To fetch and follow the logs of a container.
docker logs -f <container_name>
#docker inspect
To inspect a running container.
docker inspect <container_name> (or <container_id>)
#docker container stats
To view resource usage stats.
docker container stats