What is docker
- Docker is a computer program which is used to provide a running environment to run all kinds of application which are in docker hub, or created in docker.
It creates an image of your application and stores all requirements of files into the container. Whenever we want to run docker application in any system, we have to run a single file without providing any other requirements.
- Docker is easy to use in Ubuntu. It also supports Window and Mac operating system.
For windows, it runs in Windows10/enterprise only. To use in Windows7/8/8.1 or Windows10 home should use docker toolbox.
- There are two kind of docker software for programmers.
- Docker CE :- Free community edition :- This is an open source software.
- Docker EE :- Docker Enterprise Edition :- This is a paid software design for enterprise development and IT teams who build, ship, and run business-critical applications in production.
- Operating system (ubuntu)
Steps to install docker
. Steps to download docker in ubuntu.
1. Open terminal and follow these command to install docker.
- Just type docker and check if docker is in your system or not.
2. To check the version of operating system. To install Docker CE, we need the 64-bit version of one of these Ubuntu versions:
1. Cosmic 18.10
2. Bionic 18.04 (LTS)
3. Xenial 16.04 (LTS)
$ lsb_release -a
3. Update the apt package index.
$ sudo apt-get update
4. If requires, then install.
$ sudo apt-get install
5. If docker is not in your system then install it.
$ sudo apt-get install docker.io
6. Now check the staus of docker.
$ sudo systemctl status docker
Steps to add user in docker
1. Why sudo :-
We have to use ‘sudo’ command to run docker commands because docker container run user ‘root’. We have to join the docker group, when your system join the docker group after that one can run docker command without sudo.
2. ‘USER’ is your system name, commands to add user as listed below.
$user will pick system user
1. $ sudo groupadd docker
2. $ sudo gpasswd -a $USER
3. $ newgrp docker
3. Second way to add user in docker group.
1. $ sudo groupadd docker
2. $ sudo usermod -aG docker $USER
4. After adding a ‘USER’ into the docker group, we have to shut down or restart so that we can run docker commands without ‘sudo’.
5. Command to uninstall docker.
$ sudo apt-get remove docker docker-engine docker.io containerd runc
1.To check Docker version
$ docker –version
2. To check Docker and containers info
$ docker info
3. Find out which users are in the docker group and who is allowed to start docker containers.
1. $ getent group sudo
2. $ getent group docker
4. ‘pull’ command fetch the ‘name_of_images’ image from the ‘Docker registry’ and saves it to our system.
$ docker pull busybox (busybox is name of image)
5. You can use the ‘docker images’ command to see a list of all images on your system.
$ docker images
6. To find the location of the images in the system we need to follow some commands:-
$ docker info
path of docker:- “Docker Root Dir: /var/lib/docker”
Commands to check the images:-
$ cd /var/lib/docker
pardise@pardise-MS-7817:/var/lib/docker$ cd image
bash: cd: image: Permission denied
Permission denied for all users
$ sudo su
$ root@pardise-MS-7817:/var/lib/docker# ls
Now docker info command will provide all details about images and containers
$root@pardise-MS-7817:/var/lib/docker/image/overlay2# docker info
7. Now run a Docker container based on this image. When you call run, the Docker client finds the image (busybox in this case), loads up the container and then runs a command in that container.
$ docker run busybox
8. Now Docker client ran the ‘echo’ command in our busybox container and then exited it.
$docker run busybox echo “hello from busybox”
9. Command to shows you all containers that are currently running.
$ docker ps
10. List of all containers that one can run. Do notice that the STATUS column shows that these containers exited a few minutes ago.
$ docker ps -a
CONTAINER ID – Unique ID given to all the containers.
IMAGE – Base image from which the container has been started.
COMMAND – Command which was used when the container was started
CREATED – Time at which the container was created.
STATUS – The current status of the container (Up or Exited).
PORTS – Port numbers if any, forwarded to the docker host for communicating with the external world.
NAMES – It is a container name, you can specify your own name.
11. To start Container
$ docker start (container id)
12. To login in Container
$ docker attach (container id)
13. To stop container
$ docker stop (container id)
Difference between images and containers
Docker Image is a set of files which has no state, whereas Docker Container is the abstract of Docker Image. In other words, Docker Container is the run time instance of images.
Remove images and containers
1. Docker containers are not automatically removed, firstly stop them, then can use docker rm command. Just copy the container IDs.
$ docker rm 419600f601f9 (container_id)
2. Command to deletes all containers that have a status of exited.
-q flag, only returns the numeric IDs and -f filters output based on conditions provided.
$ docker rm $(docker ps -a -q -f status=exited)
3. Command to delete all container.
$ docker container prune
4. Command to delete all images.
To remove all images which are not referenced by any existing container, not just dangling ones, use the -a flag:
$ docker images prune -a
dangling image is an image that is not tagged and is not used by any container. To remove dangling images type:-
$ docker images prune
$ docker rmi image_id image_id……
5. Removing all Unused Objects. It will remove all stopped containers,all dangling images,and all unused network.
To remove all images which are not referenced by any existing container, use the -a flag:
$ docker system prune -a
You can follow us and our codes at our github repository:
https://github.com/amit-kumar001/You can follow us and our codes at our github repository: