- service docker start|stop|restart [Start, stop or restart docker engine]
- service docker status [check if docker is running]
- docker version: shows details of client(CLI) and server (docker engine), no of containers, images and other details
- docker --version: show only version details of docker engine
- docker info
- docker top [container] : display running processes of a container
- docker-machine ssh: go to the docker machine shell
- docker-machine restart
- docker-machine start
- docker-machine stop
- docker-machine ip default: check ip address of the docker-machine
- docker commit [container id] [new image name] [if you make any change in container, create a new image out of it]
- docker network ls :lists all network
- docker run [imagename] : run container using an image, pulls image from hub if it's not present locally
- docker run -d [imagename] : run container in detached mode
- docker run -d --name web -p 80:8080 [imagename]
- d: start container in detached mode
- Name: name of container
- P port mapping (map 80 in docker host to 8080 of container)
- docker ps : list docker containers running
- docker ps -a : list docker that have run but have now exited
- docker stop [containername] : stops the container, but the container will still be in memory
- docker stop $(docker ps -aq): stops all containers
- docker start [containername]
- docker rm [containername] : removes stopped container still in memory
- docker exec -it [containername] sh : connect to container instance
- docker build . -t [imagename] : Builds an image from dockerfile located in same folder
- docker build -f [dockerfile]: Builds an image from dockerfile located in different folder
- docker images : check if the image is created
- docker tag [imagename] [name:tag]: Tag an existing image
- docker rmi [image]:xx.xx - delete image from Docker host
- docker rmi $(docker images -q): removes all images
- docker image inspect [imagename]: Get image info
- docker login -u [username] -p [password]
- docker push [imagename]
- docker pull [imagename]: pulls an image(latest version) from docker hub and stored in Docker host
- docker pull [imagename]:xx.xx - pulls specific version(xx.xx) of image from docker hub and stored in Docker host
- docker create volume [volumename]
- docker volume ls :gives name of all volume
- docker volume inspect [volume name] :volume details like file path
- docker volume rm [volumename]
- docker run -d --name [containername] -v [volumename]:/app [imagename]
- run a container with a volume, here app is a local folder mapped to volume
- if you connect to the instance using exec command, app folder will show up on "ls" command
- Docker service create --name [service name] -p [host port]:[container port] --replicas 5 brijeshdeb/[image]
- Docker service ls
- Docker service ps [service name]
- Docker service inspect [service name]
- docker compose build : build the images
- docker compose start : start the containers
- docker compose stop : stop the containers
- docker compose up -d : Build and start
- docker compose ps
- docker compose rm : remove from memory
- docker compose down : stop and remove
- docker compose logs : get the logs
- docker compose exec [container] sh : run a command in a container
- docker compose -p test up -d : run an instance as a project
- docker compose ls
- docker compose cp [containerid]: [SRC_PATH] [DEST_PATH] Copy file from the container
- docker compose cp [SRC_PATH] [containerid]: [DEST_PATH] Copy file to the container
- docker swarm init --advertise-addr [host ip]:2377 --listen-addr [host ip]:2377
- docker swarm join-token manager [ get token to add a manager]
- docker swarm join-token worker [ get token to add a worker]
- docker stack deploy --compose-file=docker-compose.yml prod [deploy a docker compose file on swarm]
- docker swarm leave
- docker swarm leave --force [ force a manager to leave swarm]
- docker node ls [lists all docker nodes in swarm, whos manager, whos leader. Have to run from manager]
- docker node rm [NODE ID] [ removes node from the swarm]
- docker node inspect [NODE-ID] --pretty [ view details of an individual node]
- docker node promote [NODE-ID]