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

Docker Installation and Commands

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

Docker Installation and Commands

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

DOCKER INSTALLATION AND COMMANDS

Installation of docker in AWS EC2 instant


1. Install AWS EC2 instant with Linux OS
2. Switch to root user.
3. Install docker software in Linux OS

Yum install docker -y


4. Check the version of docker before and after start docker details, like client and host/engine
details

Docker –version
Docker version

5. Start docker services with help docker command.

Systemctl start docker

Systemctl status docker


6. When you need to a ubuntu/other OS/apps image, docker will check in local and if not then
goes to searching in host/registry

Docker images

Docker search images  its shows all related latest/old version ubuntu OS details
Docker pull ubuntu/windows/Jenkins

Once command execute then automatically ubuntu image bas been created in local area.

7. Once done the image, then you can do it container with image it means we are creating a
ubuntu OS.
8. For logging into/accessing the container, one uses the exec command or Run command
9. Can stop the container/kill/rm (remove the container) the container.
DOCKER HUB

RUN/PULL command to get the image from Hub/registry.


Once image execute it will create a container in that, OS will be running.

MKDIR app it means apps directory created in that container OS and whenever
exit from container automatically apps directory will be deleted.

Whenever trying to delete the image it won’t accept why bcoz image container
already running state.
In some cases, we can delete with help command (docker rm -f image
id(xxxxxxx))

Once delete container it means all data will be deleted in that container images
OS. Again once login into the same OS it wont have the same directory in that
container OS it means fresh OS will be running. If you saw below image APP dir
not available.
For this scenario docker need to save container with name <>
This how create a custom container and save with name.

One more useful command is docker rm -f $(sudo docker ps -a -q)  this will clear all containers.
Install the Apache server on this container.
Now we are updating the software’s in container image ubuntu OS

And install Apache software in that container OS.

Need to start the Apache service

Once service up and running. need to exit from the container and save the name with proper
naming standards. Like userid/name of container.
For verification whether Apache server working or not.

Pushing a Container to Docker Hub.


Push the container Image into a Docker hub with help of PUSH command.

Docker PUSH Kudipati/Apache.

Once done the PUSH into docker Hub.


DOCKERFILE COMMANDS
Let’s create a Dockerfile
Here we need to create a dockerfile and html with help of Nano edit tool.

Now we are created a Dockerfile and html file after that we need to build docker file.

Before build, we need to know how to run the Dockerfiles in user mod.

Sudo usermod -aG docker $USER

Docker build . -t new_dockerfile


Docker build: build the image.

Once app image done, you may verify whether image create or not with help command.

Docker Image

Once image created, then you can run the image and map the port value.

Docker run -it -p 84:80 -d new_dockerfile<filename>  once ran the command it will launch the
container.

If you want, see what container having the files. For that we need to run the below command.

Docker exec -it container_id bash


In Dockerfile we define as ADD . /var/www/html/ it means add file into in that
path</var/www/html/>

Once done we can also push new_dockerfile into docker hub repository.

Docker PUSH Dockerfile.

To persist data across the lifetime of a container and to accomplish there are two ways.
1. Bind mount.
2. Docker volumes.

Bind mount: To map directory inside of local machine/container and it will be mirroring same files
which is mapped directory.

And if go back to Dockerfile folder and create a any file, and then same will be mirroring to container
APP folder.

Dockerfile folder path  created one file with 2.html

Same file will be mirroring into ubuntu container folder.

There is one disadvantage to BIND MOUNT concept

1. If the file structure won’t change, then the bind mount concept it will work.
2. If any reason, the file structure/file path has been changed/ and it won’t work in different
environment like windows/ other like favours then it won’t work the bind mount concept.
This case or to overcome, we are going to prefer the docker volumes.

What is the docker volume:

Docker volume create test  create a volume with name of TEST

Docker volume ls  it means it will show volumes in the container.


Mount command/attaching it to container.

Created one container like ubuntu and mount with docket volume <Volume name as TEST>

And again, I created one more container and mount with docker volume as TEST.

And here, wherever do perform the validation and same data will in both containers why bcoz of
both containers mount on same page.
Need to install docker compose and its not a build package in linux.
Need to get from outside.

curl -SL https://github.com/docker/compose/releases/download/v2.5.0/docker-


compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

docker-compose --version
Create a yaml file with proper standard rules

Once ran the docker-compose file, Mysql and database up and running
Here we need to create a master and worker node.

Docker swarm init –advertise-addr=<master private IP adrress>  it will


generate one command and that need to be run in worker session node.

Once ran it will be automatically created connectivity between the master and
worker.
1. if you want left/ leave then you can run the docker swarm leave in worker
node
2. Master node if you want to leave then run the command as docker
swarm leave –force
Once connection established between master and worker with help of
swarm/service.
And Apache app always running in both side like worker and master with port
83.
Master node/session:
Worker node/session:
I can scale up or down COMMAD with of docker service scale aapache.
Docker service scale apache=2 or 10

Docker service rm apache  remove the apache app in docket container.

You might also like