List of all docker containers which we created including stopped containers:
docker ps –all
List all the containers which are running:
docker ps
Create container (example: pull hello-world image from docker hub and create a new container from the image). It returns a container id.
docker create hello-world
Docker run command, which is doing both create and run. It pulls hello-world image from docker hub (if it hasn’t downloaded before) and creates a new container from the image and then runs an executable program inside the container which shows the hello-world output:
docker run hello-world
Run again an existing container, -a means to wait for output and stdout
docker start -a container-id
In the example below we create a docker container for the first time :
docker create busybox
Override startup command after downloading the image and before running container:
docker run busybox echo hi there
docker run busybox ls
Docker logs: not re-run or restart any container – just for getting any debug outputs
docker logs container-id
Accessing a shell or terminal inside a running container:
docker exec -it container_id sh
Running shell inside docker container with xterm:
docker exec -it container_id /bin/bash -c “export TERM=xterm; exec bash”;
Copy directory(myfolder) to docker container(/usr/app):
docker cp myfolder container_id:/usr/app
Docker logs with tail (example: 10 last sentences for the container nginx4geonode):
docker logs -f –tail 10 nginx4geonode
Tail a file inside a docker container (example: the container is geoserver4geonode):
docker exec -it geoserver4geonode tail -f /geoserver_data/data/logs/geoserver.log
Display a live stream of container(s) resource usage statistics:
docker stats geoserver4geonode
List of docker volumes:
docker volume ls
List of all docker images:
docker images
Docker start container (“-a” means wait for output or stdout):
docker start container-id -a
Docker stop container:
docker stop container-id
Docker remove container:
docker rm container-id
Docker remove container by force:
docker rm –force container-id
Docker stop all containers:
docker stop $(docker ps -a -q)
Docker remove by force all containers:
docker rm -f $(docker ps -a -q)
Docker remove by force all images:
docker rmi -f $(docker images -q)
Docker remove images dangling:
docker rmi $(docker images ls -qf dangling=true)
 
Docker build and tag docker image from Dockerfile located in current directory:
docker build -t myimage_tag .
Docker run image in port 3000 (assume the docker image is exposed in port 80):
docker run -d -p 3000:80 myimage_tag
Remove all docker volumes:
docker volume rm $(docker volume ls -qf dangling=true)
docker Prune- deletes every container
docker system prune -a
docker list volume
docker volume ls
docker volume Prune
docker volume prune