0% found this document useful (0 votes)
2 views

DockerCommands

This document provides a comprehensive guide on installing Docker on an Ubuntu instance and explains key concepts such as Docker images, containers, clients, daemons, and registries. It also lists important Docker commands for managing images, containers, networking, and volumes. The document serves as a practical reference for users to effectively utilize Docker's functionalities.

Uploaded by

upadhye.manasi
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

DockerCommands

This document provides a comprehensive guide on installing Docker on an Ubuntu instance and explains key concepts such as Docker images, containers, clients, daemons, and registries. It also lists important Docker commands for managing images, containers, networking, and volumes. The document serves as a practical reference for users to effectively utilize Docker's functionalities.

Uploaded by

upadhye.manasi
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

Installing docker on Linux(Ubuntu)

==========================================
1 Create an aws ubuntu instance
2 Connect to it using git bash
3 Open http://get.docker.com
4 Copy and paste the first two commands

curl -fsSL https://get.docker.com -o get-docker.sh

sh get-docker.sh

To check if docker is installed or not


docker --version

Images and Containers


=========================
A docker image is a combination of bin and libs that are necessary for a
s/w application to run.Most of these images are avialble in the cloud site
of docker

A running instance of an image is called as a container.Any number of containers


can be created from one docker image.

Docker host is the machine where docker is installed.It can be windows,Linux or Mac

Docker Client
----------------
This is an application which is responsible for accepting the docker commands
and pass them to the docker deamon.On the windows machine power shell will act as
docker client on Linux and Mac the terminal will work like docker client

Docker Deamon
-----------------
This is a back ground process which accepts the commands from docker and
send them either to the docker images or docker containers or docker registry

Docker Registry
------------------
This is a location where docker images can be stored.This is of two types
1 Public Registry
2 Private Registry

Public Registry is maintianed by docker corporation and it is the cloud site of


docker where all the docker images are avilable.It can be accessed through
hub.docker.com

Private Registry is created within the servers of our originization and it can
be accessed on by our orginization team members

Important docker commands


===============================

Working on docker images


==========================
1 To see the list of images present on our docker host
docker images
(or)
docker image ls

2 To search for a docker image on hub.docker.com


docker search image_name

3 To download an docker image


docker pull image_name

4 To delete an image which is not associated with any container


docker rmi image_name

5 To delete an image which has a running container associated with it


docker rmi -f image_name

6 To create an image from a container


docker commit contianer_name/container_id new_image_name

7 To create an image from a docker file


docker build -t new_image_name .

8 To delete all the images present on the docker host


docker system prune -a

9 To upload a docker image into docker hub


docker push docker_id/image_name

Working on docker containers


---------------------------------
10 To start a stopped docker container
docker start container_name/container_id

11 To stop a running container


docker stop container_name/container_id

12 To restart a container
docker restart container_name/container_id
To restart after 10 seconds
docker restart -t 10 container_name/container_id

13 To delete a stopped container


docker rm container_name/container_id

14 To delete a running container


docker rm -f container_name/container_id

15 To stop all running container


docker stop $(docker ps -aq)

16 To delete all stopped containers


docker rm $(docker ps -aq)

17 To delete all containers running and stopped


docker rm -f $(docker ps -aq)

18 To get detailed info about a container


docker inspect container_name/container_id
19 To get the logs generated by a container
docker logs container_name/container_id

20 To see the ports used by a container


docker port container_name/container_id

21 To go into a container which is moved into background


docker attach container_name/container_id

22 To run any command or process in a container other than the default


process of that container
docker exec -it container_name/container_id command/process

23 To see the list of running contianers


docker container ls

24 To see the list of all the containers running as well as stopped


docker ps -a

25 To create a container from a docker image


docker run image_name
Run commnad options
--------------------
--name Used to give an name to the container
-d Used to run the container in the background in detached mode
-it Used to open interactive terminal in the container
-v Used to mount an external device or directory as a volume
--volumes-from Used to create reusable volumes
-e Used for passing environment variables
-p Used for port mapping,it will link the dockerhost port(external
port with the container port(internal port)
Eg: -p 8080:80 here 8080 is the dockerhost port and 80
is the container port
-P Used for automatic port mapping it will map the container port
with a port greater than 30000 on the host machine
--link Used to create a multi container architecture.This is used in
breaking a monolithic application and making it work as a
microservices
-rm This will delete the container on exit
--network This is used to specify on which network these containers
should run
--memory Used for fixed amount of memory allocation to the containers
--cpus Used for specifying how many cpus should be used by the container

Working on docker networking


------------------------------------
26 To see the list of networks
docker network ls

27 To get detailed info about a network


docker network inspect network_id/network_name

28 To create a network
docker network create --driver network_type network_name

29 To attach a running container to a network


docker network connect network_id/network_name container_name/container_id
30 To remove a container from a network
docker network disconnect network_id/network_name container_name/container_id

31 To delete a network
docker network rm network_id/network_name

Working on docker volumes


--------------------------------
32 To see the list of all the docker volumes
docker volume ls

33 To create a new docker volume


docker volume create volume_name

34 To get detailed info about a volume


docker volume inspect volume_name/volume_id

35 To delete a volume
docker volume rm volume_name/volume_id

You might also like