docker ps
To check running Docker process
docker ps -a
To check status of all available images
docker run docker_image_Name
To simple run an image
docker stop container_name/container_id
To stop a container. Use "start" to start a container.
docker rmi docker_image
To delete a docker image. use "docker rmi -f docker_image" to forcefully remove an image.
docker rmi -f $(docker images -q)
To delete all available images on the host.
docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
docker exec docker_name shell_command1;shell_command2;shell_command3;......
To run any command on docker container from docker host.
for example :
root@devopspoc:/docker# docker exec 5fc767ce7da6 cat /etc/hosts; hostname; date ;lscpu | grep core
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 5fc767ce7da6
devopspoc
Tue Mar 12 04:57:25 UTC 2019
Thread(s) per core: 1
docker log docker_container_id
To check logs of running application on the container. We can use docker log --tail , log -f etc.
docker cp container_id:/path/to/file.ext
docker cp /path/of/the/file/on/localHost container_id:/path/on/the /container
docker build -t my_imageName .
Build the image from the Dockerfile ( available in current working directory ) with your custom image name.
docker pull image_name:version_number
Pull a docker image from docker-hub, example : docker pull alpine:3.4
docker run -itd --name custom_Container_name image_name
Run docker with custom container name.
docker exec -it container_id /bin/sh
connect to container terminal.
docker run -d -p xxxx:xxxx --name=Container_Name -v /path/to/application.war:/config/dropins/application.war image_name Run a container on specified port and deploy application. This step is used mostly for WebSphere Liberty profile. Example :
docker run -d -p 80:9080 --name=app -v $PWD/Sample.war:/config/dropins/Sample.war webSphereLiberty_image
Docker Compose File -- Mongo DB
version: '2'
services:
mongodb:
image: mongo:latest
container_name: "Santosh-Mongo-DB"
environment:
- MONGO_DATA_DIR=/data/db
- MONGO_LOG_DIR=/dev/null
- MONGODB_USER="user"
- MONGODB_PASS="pass"
volumes:
- ./mongo/db:/mongo/db
ports:
- 27017:27017
command: mongod --smallfiles --logpath=/dev/null # --quiet