Creating and Running container from a Image
Command : docker run
docker run hello-world
Override default command
Command : docker run command
docker run busybox echo hi there
docker run busybox ls
Listing Running Containers
Command : docker ps
docker run busybox ping google.com
docker ps
docker ps --all //List all containers ever created
Docker Lifecycle
Command docker run
docker create <image name>
docker start <container id>
docker start -a <container id> -a to display the console log
Docker Restaring
Command : docker ps –all
docker start -a <container id from ps command>
Removing Stopped Containers
Command : docker system prune
Retrieving Log outputs
Command : docker logs // if you have not started using docker start -a
Stopping Containers
Command : docker stop – SIGTERM (die gracefully) – Listen to Stop command in code – 10 Seconds to Shutdown – After 10 seconds its KILL
docker kill <container id> - SIGKILL - Die immediately
Multi Command Containers – Execute a second command inside a runinng container
Command : docker run redis
docker exec -it <container id> <command> // -it enter using keyborad and send it to container
dcoker exec -it <id> redis-cli
Using docker -it flag
Command : docker exec -i redis-cli
docker exec -t <container id> redis-cli
Getting Command Prompt in Running Container
Command : docker exec -it sh – CTRL C or CTRL D to exit or type exit
Starting a Shell using docker run
Command : docker run -it busybox sh – Start and run sh and attached to STDIN and STDOUT
Building docker images
Command : docker build . (where Docker file is present) – Returns the image id of docker then use docker run
Tagging Docker image
Command : docker build -t /:latest .
Mannual Image Creation
Command : docker run -it apline sh
apk add --update redis
New Terminal
docker ps
docker committ -c 'CMD ["redis-server"]' <container id>
docker run <container id>
Port Forwarding
Command : docker run -p 8080:8080 /
Docker Building using Custom File Name
Command : docker build -f Dockerfile.dev .