What is Docker
o Docker is an open platform for developing, shipping, and running
applications
o Docker enables you to separate your applications from your infrastructure
so you can deliver software quickly
o Docker manage your applications
o Reduce the delay between writing code and running it in production
Docker Architecture
How Docker Container run
Install Docker
Step1: Install packages RHEL/Fedora/Centos
# yum install docker -y
OR
Step1: Install packages on Ubuntu/Debain
# apt-get install [Link] -y
Step2: To Start your docker service
# systemctl start docker
Step3: To Enable your docker service
# systemctl enable docker
Step4: To Check service status
# systemctl status docker
How to Run Docker Container
Step1: PULL Docker Image from Docker HUB
# docker pull busybox
Step2: Check your Docker Image
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest c51f86c28340 4 weeks ago 1.109 MB
Step3: Execute your CMD/Task/Code/App/Process with DockerImage
# docker run busybox echo "Hello World"
Step2: Check Running Docker Containers (-a for all)
# docker ps
How to Jump in a Docker Container
Step1: PULL Docker Image from Docker HUB
# docker run --name lc1 -itd busybox sleep 1d
Step2: Check Running Docker Containers (-a for all)
# docker ps
CONTAINERID IMAGE COMMAND CREATED STATUS PORTS NAMES
558d15ef2761 busybox "sleep 1d" 3 seconds ago Up 2 seconds lc1
Step3: Use exec with containerID or ContainerName including supported Shell
docker exec -it lc1 sh
How to remove Docker Container
Step1: Check Running Containers (-a for all)
# docker ps
CONTAINERID IMAGE COMMAND CREATED STATUS PORTS NAMES
558d15ef2761 busybox "sleep 1d" 3 seconds ago Up 2 seconds lc1
REMOVE Container with containerID or ContainerName (-f for forcefully)
# docker rm lc1
STOP Container - Use rm with containerID or ContainerName
# docker stop lc1
START Container - Use rm with containerID or ContainerName
# docker start lc1
RESTART Container - Use rm with containerID or ContainerName
# docker restart lc1
How to Run Nginx Container
Step1: PULL Docker Image from Docker HUB
# docker pull nginx:latest
Step2: Check your Docker Image
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ad80nkldf0 4 weeks ago 142 MB
Step3: Use –p to port-forward trafick from your local machine to Container
# docker run -itd --name c1 -p 8080:80 nginx
Step4: Check WebPage on browser
[Link]
How to Create Docker Image
BUILD RUN
Dockerfile
•FROM – Select the base image to build the new image.
•RUN - Triggers command while we build the docker image.
•CMD - Triggers command while we launch the created docker image.
•ENTRYPOINT - Is also closely related to CMD and can modify the way a container starts an image.
•COPY - only supports the basic copying of local files into the container,
•ADD - It has some features like auto tar extraction and remote URL support
•EXPOSE – Define which Container ports to expose
•USER – Define the default User all commands will be run
•WORKDIR – Define the default working directory
•ENV – Set/modify the environment variables
•VOLUME – Creates a mount point within the Container linking it back to file systems accessible by the Docker Host
Lets Create Docker Image
Step1: Create your JAVA application docker Image with entrypoint using Dockerfile
Ref link [Link]
openshift/tree/master/kubernetes/hello-java-app-run/helo-app-docker-image
# cat Dockerfile
FROM anapsix/alpine-java:8_jdk_nashorn
MAINTAINER AMIT GANVIR
RUN mkdir /myapp
COPY [Link] /
COPY [Link] /myapp/[Link]
RUN chmod +x /[Link]
ENTRYPOINT ["/[Link]"]
Step2: Check content of [Link]
#!/bin/sh
set -x
java -jar /myapp/[Link]
OR
Create your JAVA application docker Image with CMD using Dockerfile
# cat Dockerfile
FROM anapsix/alpine-java:8_jdk_nashorn
MAINTAINER AMIT GANVIR
RUN mkdir /myapp
COPY [Link] /myapp/[Link]
CMD ["/java”, “-jar”, “/myapp/[Link]"]
Ref link [Link]
openshift/tree/master/kubernetes/hello-java-app-run/helo-app-docker-image
Step3: Build Docker image
# docker build . –t “amitganvir6/java-app1:v1”
Step4: Test your application by running container
# docker run -itd --name c3 -p 8081:8080 amitganvir6/java-app1:v1
Check the pod
# docker ps
Check the pod logs
# docker logs -f c3
Check Your App WebPage on browser
[Link]
Lets make Docker Image tag
Step1: docker tag <Image Name/ID> <New IAMGE TAG repo/app:tag>
# docker tag amitganvir6/java-app1:v1 amitganvir6/java-app1:v2
Docker Registries
o A Docker registry stores Docker images
o Docker Hub is a public registry that anyone can use
([Link]
o You can even run your own private registry
o When you use the docker pull or docker run commands, the required
images are pulled from your configured registry. When you use the docker
push command, your image is pushed to your configured registry
From Local
Internet
Docker Image Docker Registry
[Link]
Docker Image
Docker Image
How to push Docker Image in Docker Registry
Step1: Create an account on Dockerhub registry - [Link]
Step2: Create your access token - [Link]
Step3: Login with credentials on your local machine. Don’t use your login password
instead use token
# docker login -u amitganvir6
OR
# docker login -u amitganvir6 –h [Link]
Step4: Now push your image to Dockerhub Registry
# docker push amitganvir6/java-app1:v1
Step5: Now check your Image in dockerhub registry- [Link]
Lets Run a Mlflow Container and
integrated with DB
docker pull [Link]/mlflow/mlflow:v2.1.1
docker pull bitnami/mariadb:latest
export DB_PASSWORD=1234
docker run -p 3306:3306 --name mariadb -e MARIADB_ROOT_PASSWORD=$DB_PASSWORD -itd
bitnami/mariadb:latest
docker run -p 5100:5100 -v /var/mm/:/var/mm --name mlflow -itd [Link]/mlflow/mlflow:v2.1.1
DB_IP=$(docker inspect -f '{{[Link]}}{{.IPAddress}}{{end}}' mariadb)
docker run -p 5100:5100 -v /var/mm/:/var/mm --name mlflow -itd [Link]/mlflow/mlflow:v2.1.1 sh -c
"pip install pymysql;mlflow server --host [Link] -p 5100 --backend-store-uri
mysql+pymysql://root:${DB_PASSWORD}@${DB_IP}:3306/test --default-artifact-root
[Link]
[Link]
Docker command list
docker run – Runs a command in a new container
docker start – Starts one or more stopped containers
docker stop – Stops one or more running containers
docker build – Builds an image form a Docker file
docker login - To login on Container registry
docker pull – Pulls an image or a repository from a registry
docker push – Pushes an image or a repository to a registry
docker exec – Runs a command in a run-time container (-it)
docker ps - To list containers (-a)
docker images - To list all the local images
docker rm - to remove the container
docker rmi - To remove images
docker search - To search images on the registry
docker kill – To kill pods
docker export – Exports a container’s filesystem as a tar archive
docker search – Searches the Docker Hub for images
docker attach – Attaches to a running container
docker commit – Creates a new image from a container’s changes
Data Availabe in Github Repository
[Link]
Present By Amit Ganvir
amitganvir6@[Link]