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

Docker tutorial edureka

The document provides a comprehensive overview of Docker, including its key components such as Docker files, images, containers, and Docker Hub. It outlines various Docker commands for managing images and containers, as well as details on Docker Compose for multi-container applications. Additionally, it explains Dockerfile commands and the importance of version compatibility between Docker and Docker Compose.

Uploaded by

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

Docker tutorial edureka

The document provides a comprehensive overview of Docker, including its key components such as Docker files, images, containers, and Docker Hub. It outlines various Docker commands for managing images and containers, as well as details on Docker Compose for multi-container applications. Additionally, it explains Dockerfile commands and the importance of version compatibility between Docker and Docker Compose.

Uploaded by

ap.synophic
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Docker tutorial

 Docker file – all the code written by developer


 Docker image – docker file produces docker images which contains all the dependencies
required for the docker file to run. It contains all the projects code. This image can be run to
create as many as docker container as required.
 Docker container – Run time instance of docker image.
 Docker hub – A git repository of docker images. Docker images are uploaded in docker hub.
From this docker hub, various containers can be pulled.
 Docker data center (DDC) has five components – Universal control plane (used to deploy sevices
to various host), LDAP (Security), Swarm, CS engine, Registry trusted services (stores docker
images).
 Docker Compose - It makes it easier to compose and run applications made up of multiple
containers.
 Docker Commands
o Docker images – to display all the images in the local repository
o Docker –version – to view the version of docker installed
o Docker –help – returns a list of commands available in docker along with the possible
flags.
o Docker run –it <image> - to run the image by creating a container.
o Docker run <image> - executes the docker image on the local repo & creates a running
container out of it.
o
o Docker pull <image> - pulls the image from docker hub
o Docker ps –a – shows all the containers
o Docker ps – shows only active containers. ps stands for processes.
o Docker exec – access an already running container and perform operations inside the
container.
o Docker exec –it <container id> bash – accesses the running container (denoted by given
container Id). “-i” is for interactive. Container Id is to be followed by bash.
o Docker stop <container Id> - stop the container denoted by container Id. Container is
shut gracefully by waiting for other dependencies to shut.
o Docker kill <container Id> - kills the container by stopping its execution immediately. It
is similar to force kill.
o Docker commit <continer Id> <docker hub Id/image corresponding to container Id> -
creates new image of the edited container in the local system with repository name
<docker hub Id/image corresponding to container Id>. To run this command one needs
to login into docker hub.
o Docker login – to login into docker hub repo from CLI.
o Docker push <dockerID</<image name> - pushes the image under the given repository
from local to docker hub. Before pushing, an image has to be tagged.
o Docker tag <image from local repo to be tagged> <docker Id>/<image name for docker
hub> - before pushing an image from local repo to docker hub, it should be tagged to
the docker Id.
o Docker rm <container Id> - deletes the container corresponding to container Id. Before
removing, container needs to be stopped.
o Docker rmi <image Id> - deletes an image corresponding to Image Id.
o Docker compose – this command is used to power multi-container applications where
various services will be hosted on same host but inside different containers.
o Docker-compose up - to run docker container as mentioned in the “Dockerfile”.
o Docker-compose build – used to build the docker compose using docker yaml file. This
command is executed in the directory where yaml file is present for building the
compose.
o Docker-compose down – stop the containers
o Docker rm –f $(docker ps –a –q) – delete all containers
o Docker volume rm $(docker volume ls - q) – delete all the volumes
o Docker-compose up –d – restart the container
o Docker build –t <docker image name> <path to Dockerfile> - build docker custom
image by compiling a Dockerfile. Note – image name cannot be in caps.
o Docker run –p <hostport>:<containerport> --name=<name given to container> <image
on which container to be built> - create a container on image built from Dockerfile.
o Docker ps –a –q | ForEach {docker stop $_} – stop all containers.
o Docker stop <container Id> - to stop a container for the given container Id.
o Docker container – used to manage container. Has many arguments. Docker container
logs, kill, rm, run, start.
o Docker export – This command is used to export a docker image into a tar file which is
saved in the local system. This is used when the image size is huge.. So, its converted
into tar and then moved into another system and then containerized.
o Docker export –output=”<output file name> <image to be tarred> - ---- do ---
o Docker import <path to tar file> – import tar file
o Docker swarm – This command creates a network of docker engines/host to execute
containers in parallel (for scaling up & high availability). There is one docker manager
and many other docker workers. Whatever applications is run on docker manger is then
executed and run on all docker workers. Eg of docker commands – docker swarm init
advertise-addr 192.168.1.100; docker swarm join; docker swarm join-token; docker
swarm leave;
o Docker swarm init –advertise-addr <ip of manager machine> - used to initialize docker
swarm.
o Docker swarm join --token <token no> <master Ip address:port> - used to join the
workers to master docker.
o Docker swarm join-token – used to regenerate the token used for joining the master
docker.
o Docker swarm leave – to leave the docker swarm cluster. If run at worker ‘s end then it
would run at ease but to run it at manger’s end, it needs to be forced., i.e, the command
would be docker swarm leave --force.
o Docker service – used to control/manage any existing service
(containers/compose/swarm/others). Eg commands – docker service ls; docker service
ps; docker service scale; docker service stop; docker service logs; docker sevice rm. It is
used in sync with docker compose and docker swarm.
o Docker service ls – outputs different nodes (worker docker) in the docker cluster.
 Dockerfile commandas
o FROM - FROM is used to define the base docker image used to start the build process.
This will ensure user will work on base image(eg, Ubuntu, centos, etc..) machine
equivalent.
o RUN – RUN is the central executing directive for Dockerfiles. It takes a command as its
argument and runs it to form the image. This is the command that is actually used to
build the image.
o CMD – The CMD command, similar to RUN command, can be used to execute a specific
command. However, unlike RUN it is not executed during build, but when a container is
instantiated using the image being built.
o ENTRYPOINT – ENTRYPOINT argument sets the concrete default application that is used
every time a container is created using the image. That is, commands following
ENTRYPOINT will be the first one to be run after a container is built. Also, it overwrites
the CMD.
o ADD – It copies the files from the source on the host into the container’s own filesystem
at the set destination. ADD command has two arguments: a source and a destination. It
can be interchangeably used with COPY command.
o ENV – ENV command is used to set the environment variables (one or more) required in
the container. These variables consist of “key value” pairs which can be accessed within
the container by scripts and applications alike.
o WORKDIR – sets the working directory where the commands associated with CMD will
be executed. This can be set to another container as well.
o EXPOSE – EXPOSE command is used to associate a specified port to enable networking
between the running process inside the container and outside world (host).
o MAINTAINER – This is a non-executing command that declared the author, hence setting
the author field to images. It should come nonetheless after FROM.
o USER - The USER directive is used to set the UID (or username) which is to run the
container based on the image being built.
o VOLUME – this command sets the path where all files related to the container are
stored. In other words, VOLUME command is used to enable access from your container
to a directory on the host machine (i.e., mounting it).
 Kitematic is a UI tool for doc of windows.
 “daemon off” is used to bring application to the foreground.
 Docker compose file is a yml file which runs multiple Dockerfile.
 One needs to use compatible version of docker-compose with docker. Not all version of docker-
compose matches with all version of docker.

You might also like