Docker Commands
1) Run a container
docker run <container id>
2) List all the running containers
docker ps
3) List all the containers present
docker ps—a
4) Stop the container
docker stop <container id>
Note: You can give just the first 3 letters of the container
Ex: docker stop 98x
5) Remove the stopped container
docker rm <container id>
6) List all the available images
docker images
7) To pull a docker image
docker pull <image name>
8) To check all the steps performed when the image was pulled
docker history <image id>
9) Remove the images that are no longer used
docker rmi <image name>
10) Run the container in detached mode
docker run—d <image name>
Ex: docker run —d ubuntu
11) Pull the image
docker pull <image name>
Ex: docker pull ubuntu
12) Execute command on a running container
docker exec <container id> <command to be executed>
13) If you want a particular version of the image add the tag
docker run <image name>:<version>
14) Run the container in interactive mode
docker run -it <container name>
15) Name the container
docker run —name=<name> <image name>
Ex: docker run —name=test ubuntu
16) Port mapping host:container
docker run—p <host port>:<container port> <image-name>
Ex: docker run —p 80:5000 ubuntu
17) Volume mapping
docker run —v <path where you want to store data>:<path from where you want to store>
Ex: docker run —v /opt/home:/var/lib/test
18) If you want additional information if the container
docker inspect <container id>
19) To view the logs of a particular container
docker logs <containerid>
20) To setup environment variables
docker run—e <name>:<value> mysql
Ex: docker run —e MYSQL_ROOT_PASS=xyz mysql
21) To link the containers
docker run—d —link <container name> <container name>
Ex: docker run —d —link redis:redis flask-app
22) To bring up the entire application stack
docker-compose up
23) To remove all the dangling images
docker image prune -a
24) If you want to assign some amount of memory to your container
docker run —-memory=<specify memory> <image name>
Ex: docker run -memory=100m ubuntu
25) Set CPU limit
docker run —cpu=<specify limit> <image name>
Ex: docker run —cpu=100m ubuntu
26) Create space/volume to store all your data
docker volume create <volume name>
27) To store the data inside your volume
docker run—v <volume name>:<path to store from><path to store to>
28) To get more info on docker
docker info | more
29) To check the actual disk consumption used by docker
docker system df
29) If you want to run a container on a particular network
docker run —network=<network name> <image name>
30) To check all the networks available
docker network Is
31) Check Docker stats
docker stats
Comments
Post a Comment