Docker¶
Docker is a containirized tool designed to make it easier to create,deploy and run applications by using containers. Containers allow a developer to package up an application with libraries and other dependencies and deploy it as one package.Containers are OS virtualization.We don't need a OS in the container to install our application.It depends on Host OS kernel.
Install Docker Engine & Docker-Compose on Ubuntu & CentOS
Docker Setup
Create a file name docker_setup.sh and copy the below script
#!/bin/bash
apt --help >>/dev/null
if [ $? -eq 0 ]
then
echo " INSTALLING DOCKER IN UBUNTU"
echo
sudo apt update
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
sudo docker run hello-world
else
echo " INSTALLING DOCKER IN CENTOS"
echo
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io -y
sudo systemctl start docker
sudo docker run hello-world
fi
echo " Installing Docker Compose"
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
Give Execute permission for script
Now run the ScriptDocker Commands¶
Docker Images List all images that are locally stored with the Docker Engine
Build an image from the Dockerfile in the current directory and tag the image Delete an image from the local image storeContainers¶
Run a container in interactive mode:
Run a container from the Image nginx:latest, name the running container “web” and expose port 5000 externally, mapped to port 80 inside the container in detached mode. Run a detached container in a previously created container network: Follow the logs of a specific container: List only active containers List all containers Stop a container Stop a container (timeout = 1 second) Remove a stopped container Force stop and remove a container Remove all containers Remove all stopped containers Execute a new process in an existing container:Execute and access bash inside a container To inspect the containerShare¶
To Establish Connection from local to Remote. login with your Dockerhub Credentials.
Pull an image from a registry Retag a local image with a new image name and tag Push an image to a registry.Dockerfile¶
Sample Dockerfile for Deploying a Staticwebsite.
FROM centos:7
LABEL "Author"="saiteja Irrinki"
LABEL "Project"="Wave"
RUN yum install httpd wget unzip -y
RUN wget https://www.tooplate.com/zip-templates/2121_wave_cafe.zip
RUN unzip 2121_wave_cafe.zip
RUN cp -r 2121_wave_cafe/* /var/www/html/
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
EXPOSE 80
WORKDIR /var/www/html
VOLUME /var/log/httpd
Docker
You can pull my image and you can also run container from my image without creating Dockerfile.
Creating Docker Compose for local Docker File
version: "3"
services:
Wavecafe:
build:
context: /Dockerfile_path/
ports:
- "5555:80"
container_name: wavecafe
Creating a Seperate Directory to Store Container data
Now link your Directory while running the containerdocker run --name db01 -e MYSQL_ROOT_PASSWORD=secret123 -p 3300:3306 -v /root/mountbind:/var/lib/mysql -d mysql:5.7