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

Docker

This document provides instructions for dockerizing a Spring Boot application. It explains how to create a Dockerfile to build a Docker image from a Spring Boot JAR file. The key steps are: 1. Create a Dockerfile that specifies the base image, copies the JAR file, and defines the command to run it. 2. Build the Docker image from the Dockerfile. 3. Create and run a container from the image, mapping ports as needed. It also discusses using Docker Compose to automate building and running containers defined in a YAML configuration file.

Uploaded by

abhidas0810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Docker

This document provides instructions for dockerizing a Spring Boot application. It explains how to create a Dockerfile to build a Docker image from a Spring Boot JAR file. The key steps are: 1. Create a Dockerfile that specifies the base image, copies the JAR file, and defines the command to run it. 2. Build the Docker image from the Dockerfile. 3. Create and run a container from the image, mapping ports as needed. It also discusses using Docker Compose to automate building and running containers defined in a YAML configuration file.

Uploaded by

abhidas0810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Docker

-To avoid version Conflict and Environment unComfortability while modifying and
deploying (testing and running) Application in other platform we have docker
-Docker is an open platform

follow following steps for Dockerisation Project

1)Create a Project:Create a springboot Project

2)creat jar file: specify jar file name inide pom file

3)create docker File:create a docker file and specify from ,workdirct,copy,cmd

FROM openjdk:8 -) The from keyword is used to define the base image,on which we
building/working

WORKDIR /springbootdeockerdemo -)Specify the directory to store jar file

COPY target/spring-boot-docker-demos.jar . -) specify coping jar file name

CMD [ "java" "-jar" "spring-boot-docker-demos.jar"] -)write commands to execute jar


file : cmd executed during image creation time / entry pointd

run: run executed during container creation time

note: clean and install maven Project

4)crete image:by entering commands in command promt create image

5)create container:

-for one image we can create multiple containers

6)pull into the private/public repository:


-public repository:docker hub,git hub Respository
-private repository:Amazon clouds,Nexus

*)Scrach:an explicitly empty image, especially for building images "FROM scratch"
-if the project in not depend on any dependent image we have to use from scratch
-This image is most useful in the context of building base images (such as debian
and busybox) or super minimal images (that contain only a single binary and
whatever it requires, such as hello-world).
-As of Docker 1.5.0 (specifically, docker/docker#8827), FROM scratch is a no-op in
the Dockerfile, and will not create an extra layer in your image (so a previously
2-layer image will be a 1-layer image instead).
-You can use Docker’s reserved, minimal image, scratch, as a starting point for
building containers. Using the scratch “image” signals to the build process that
you want the next command in the Dockerfile to be the first filesystem layer in
your image.
-While scratch appears in Docker’s repository on the hub, you can’t pull it, run
it, or tag any image with the name scratch. Instead, you can refer to it in your
Dockerfile. For example, to create a minimal container using scratch:

FROM scratch
COPY hello /
CMD ["/hello"]
*)Docker ps -a:to know which container are there and running

*)Docker stop container Name/Id :to stop running container

*)docker build -t image_name:version docker_file_path(.-current folder) version


not mandatory (latest)

*) docker images

*)docker run --name name_of_container -d(optional for detach mode) -p


port_number(docker/host_server:tomcat_server) image_Name(version) : to create
container
note use the docker server port to in postman

*) ctrl+c coming out of the logs but still container running

*)docker start containerName/ID : start the stopped container

*)docker start containerName/ID : stop the container

*)docker rm containername/ID: remove container

*)if remove the container we cannot strat the container bcz it not exist for once
use run command to create and run the container

*)To work on container through console log enter ctrl+c then container will stop /
we can work

*)docker logs containername : to see the logs of container

*)docker logs -f containername : to see the logs of running container

*)docker image: to know images

*)docker rmi image_name: to remove image , if that image attached to running


container it will not remove ,we can forcefully remove
i.e docker rmi -f image_name then image deleted but container will be exist(start
and check container)

*)docker system prune:it will remove all images and container not in use if put yes
= remove all (images dont attached to any container and container wchich are not
running containers deleted but its image will be present)

*) docker stats containername/Id : statics of container

*)*) docker pause containername/Id :to pause the running container

*) docker unpause containername/Id : to unpause the running container

*) docker kill containername/Id : stop the running of container stop and kill are
similar but pause is different than both stop and kill

*)docker inspect imagename: to know image details

*)docker exec -it ContainerName bash/sh:to know the working directory created in
the container (it means interactive mode)
note: inside work directory jar file to be stored we can check...
to come out of it enter 'exit' command
*)docker pull mysql:to pull/docker the mysql from docker hub and to create the
mysql image

*)docker run --name mysql_container_name -e MYSQL_ROOT_PASSWORD=root -d(interactive


mode) mysql_image_name : to create the mysql container

*)docker exec -it containerNmae/Id bash: to get iteractive mode

*)mysql -u root -p : to enter into the mysql database

*)show database; : to display all database/schema

*)craete database databaseName; : to create database

*)docker compose.yml:used to provide instruction/indentation to create image and


container or only container automatically.after creating image manualy
use command to execute .yml file: docker-compose up (running in blocked mode)
docker-compose up -d (running in detached mode)
docker-compose down (to stop and remove the
container not image)
Docker-compose yml file(to create container)
version
services
-myappsevices
-image:
-container_name:
-port
-8080:8080

Docker-compose yml file(to create image and container)


version
services
-myappsevices
-build: . (. build the image using jar file which is present in current
folder)
-image
-container_name
-port
-8080:8080

Docker-compose yml file(to create image and container when we have multiple docker
file)
version
services
-myappsevices
-build: . (. build the image using jar file which is present in current
folder)
-context: .
-dockerfile:
-image:
-container_name:
-port
-8080:8080
-9090:8080(WE CAN PROVIDE ANY NUMBER OF PORTS) LEFT:Docker
Container port, Right:tomcat server port

- docker-compose logs/docker logs: to view logs


- differnce btw docker file and yml page is yml page has extension .yml
- both are same the way of providing information is different
-using docker file we have to give the commands to create container in comond promt
and container but using yml file we can create container automatically.

*)dockerFile:
*).yml file:

to do clean and instal operation automatically we have to specify in docker file

dockerFile

FROM Maven
WORKDIR /springboot-docker-app
COPY . .
RUN mvn clean install
CMD mvn spring-boot:run

when Using mysql database


1)pull the mysql from docker hub:it will create the image=====docker pull mysql
2)create the container for mysql
3)d

You might also like