Docker Cheat Sheet
Docker Cheat sheetBy Sameera Madushan Dissanayaka
Build docker image
docker build -t Sameera/Dissanayaka .
Run Docker image
Demon mode
docker run -dt -p 80:80 docker_image_name
Intaractive mode
docker run -id -p 80:80 docker_image_name bash
when you exit docker container distroyed
Check docker images
docker images
Check running docker containers
docker ps
Checke stopped docker container and running docker containers
docker ps -a
Stop running docker container
(1234 docker container id or docker image id)
docker stop 1234
Restart stopped container
docker restart 1234
Remove docker container
docker rm 1234
Forced remove docker container
docker rm -f 1234
Remove docker image
docker rmi 1234
Identify host and container side of docker port allocation
docker run -dt -p 8081:80
8081 container
80 hostulk
Bulk remove container
docker rm 1234 5678 1432
Bulk image remove
docker rmi 1234 5678 1432
Access the docker container
docker exec -it 1234 bash
Remove stopped docker container
docker rm $(docker ps -a -q)
Remove all the containers
docker rm -f $(docker ps -a -q)
Periodcally remove stopped containers
Create cron job to remove all stopped containers
*/30 * * * * docker rm $(docker ps -a -q) >> /var/log/docker_removed.log
Inspect the docker container
docker inspect 1234
Check IPAddress of container
docker inspect 1234 |grep IPAddress
Link docker container db container to container mywebcontainer
docker run -d -p 8081:80 --name sameera --link db -t mywebcontainer
Change docker image name container abc in to sam
docker tag abc sam
Shared container folder with host
docker run -dt -v /var/www/hostside:/var/www/containerside name_of_image
Shared Container
docker run -d --volumes-from nameofcontainer -- db docker_image_name
To Be Continued ....