What Is Docker?
What Is Docker?
What is Docker?
Docker is basically a software which helps up for creating rapper around the files of the code, operating
system and the libraries that we required for particular code to work.
Architecture of Docker:
Docker installation:
Installation on MAC:
https://store.docker.com/editions/community/docker-ce-desktop-mac
Installation on WINDOWS:
https://store.docker.com/editions/community/docker-ce-desktop-windows
installation on UBANTU:
docker –version
sudo docker ps
bash – run this container in the current terminal space that I am working in
exit
with this command, a new image is created which can be seen under docker images with the
same as passed in the command
Whenever you want an image push to docker hub account there is certain nomenclature that you have
to follow when you naming when naming image as follows
<user-id-of-docker-hub-account>/<new-name-of-container>
e.g. amson/apache
Map internal port of the container to the outside host operating system
Due to this we can access apache install in container using the port that mapped(82:80) to the
container.
after above command enter username and password of docker hub account.
Introduction to Dockerfile:
What is Dockerfile?
A Dockerfile is a text document that contains all the commands a user could call on the command line to
assemble an image. Using docker build users can create an automated build that executes several
command-line instructions in succession.
FROM:
FROM keyword is used to define the base image on which we will be building.
ADD:
ADD keyword is used to add files to the container being build.
Syntax: ADD <place where files are present> <location inside the container where all those files we want
to copy>
RUN:
RUN keyword is used to add layer to the base image by installing components. Each RUN statement
adds a new layer to the docker image.
CMD:
The CMD keyword is used to run commands on the start of the container. These commands run only
when there is no argument specified while running the container in the docker run command.
ENTRYPOINT:
The ENTRYPOINT keyword is used strictly to run commands the moment the container initializes. The
difference between CMD and ENTRYPOINT is, ENTRYPOINT will run irrespective of the fact whether
argument is specified or not.
ENV:
The ENV keyword is used to define environment variables in the contained runtime.
e.g. Dockerfile
ADD . /var/www/html // Add all the files from this directory to /var/www/html directory
Dockerfile will execute after this command and build the new image through Dokcerfile.
sudo usermod -aG docker $USER – run this command and then re-login into your session.
Docker Volumes are used to persist data across the lifetime of a container.
It basically posts the storage outside the container and maps it to inside the container that is storage is
there in host system rather than on the container. Rather than the files are retain on the container itself
they are retain outside the container and that location is basically mapped inside container.
1. Bind mount
Bind Mount only work with the file system is the same that you have specified. It will not work
in different environments.
It does not manage by the docker because we create the directory, we decide the which
directory our data is gone a resided and inside the directory we are making the changes and that have
been reflected in that container.
2. Docker Volumes
docker valume ls
Syntax for mounting a volume : dokcer run -it –mount source=<name-of -volume>,target=<path-
to-directory> -d <image-name>
Docker Compose:
It is a tool for defining and running multi-container applications. With docker compose you use a YAML
file to configure your application services. Then, with a single command you create and start all the
services from your configuration. Run docker compose up and compose starts and runs your entire app.
docker-compose up -d
Container Orchestration:
If there is a container which goes down or not healthy any more then Docker Swarm is automatically
repair it by stopping the container and launching the new one in place of it.
There are lot of container orchestration tools. With docker pre-packaged comes Docker Swarm.
Docker Swarm is a clustering and scheduling tool for docker containers. With Swarm, IT administrators
and developers can establish and manage a cluster of docker nodes as a single virtual system.
While launching worker, we need to some steps on instance to see this is the instance that I want the
leader/manager for my Docker Swarm cluster.
Any node which has to join this manager/leader they will have to pass below command
The command should be passed on the worker node to join the docker swarm cluster.
What is Service?
Containers on the cluster are deployed using service on the Docker Swarm. A service is a long running
docker container that can be deployed to any node worker.
Creating a service: