Table of contents
What is Docker?
Docker is an open platform for developing, shipping and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.
You can download and install Docker on multiple platforms. Refer to the following link to download the docker
Install Docker In Ubuntu
To download docker in ubuntu we need to run the below commands
sudo apt update -y
- To update, the package sources list to get the latest list of available packages in the repositories
sudo apt install docker.io -y
-To install the docker in ubuntu OS
docker --version
-To check the docker version or docker install or not
systemctl status docker
-To check docker status /running or stopped
systemctl start docker
-To start the docker service
systemctl stop docker
-To start the docker service
Docker Commands
1. docker pull [image-name]
- To pull the docker image from the registry (DockerHub)
2. docker image ls
- To list the images available in the docker host
3. docker search [image-name]
- To search for images in the docker hub from the docker host
4. docker ps
-This command is used to list the running containers
5. docker ps -a
-This command is used to list all running & stopped containers
docker run
- This command is used to create a container from an image
6. docker run -d [image-name or ID] bash
Create a container using an image.
-d
is the detached mode.
image-name or ID:
container base image. If available in the docker host docker will pull from the host otherwise it will pull from the registry(DockerHub)
7. docker run -d --name=[container-name] [image-name or ID]
Create a container using an image with the given container name
8. docker run -d --name [container-name] -p [host-port]:[container-port] [image-name]
-Create a container using an image with a port number to expose the port for accessing the container using port
8080
-Here 8080 is the host port
80
-Here 80 is the container port
9. docker run -it --name [container-name] -p [host-port]:[container-port] [image-name]
-Create a container in interactive mode
-it
-flag to make the container in interactive mode (login into a container)
10. docker run -it --name [container-name] -p [host-port]:[container-port] [image-name] bash
-Create a container with a bash shell
bash
-Here bash command will execute while deploying the container
11. docker start [container-name or containerID]
-To start the stopped container
12. docker stop [container-name or containerID]
-To start the running container
13. docker exec -it [container-name or containerID] bash
-To log in to the running container (To log-in container should be in running state)
14. exit or Ctrl +p and Ctrl +q
To log out from the logged-in container
15. docker inspect [container-name or containerID]
docker inspect is a command that returns detailed, low-level information on Docker objects. Those objects can be docker images, containers, networks, volumes, plugins, etc. By default, docker inspect returns information in JSON format.
16. docker port [container-name or containerID]
Use the `docker port` command to list the port mappings for a container.
17. docker stats [option] [container-name or containerID]
The docker stats command returns a live data stream for running containers. To limit data to one or more specific containers, specify a list of container names or ids separated by a space. You can specify a stopped container but stopped containers do not return any data.
Options:
--all , -a
Show all containers (default shows just running)--format
Pretty print images using a Go template--no-stream
Disable streaming stats and only pull the first result--no-trunc
Do not truncate output
18. docker top [container-name or containerID]
-Use the `docker top` command to view the processes running inside a container.
19. docker save [option] [image-name]
-Use the 'docker save' command to save an image to a tar archive.
option: --output , -o
: Write to a file, instead of STDOUT
20. docker load [option]
-Use the `docker load` command to load an image from a tar archive.
options:
--input , -i
: Read from the tar archive file, instead of STDIN--quiet , -q
: Suppress the load output
21. docker rm [container-name-1] [container-name-2] or [containerID]
-Use to remove one or more container
22. docker rmi [image-name-1] [image-name-2] or [imageID]
-Use to remove one or more images from the docker host
Thank you for reading the article.
Thanks for your valuable time.
Happy Learning !... Keep Learning ! 😊