Docker
Docker
Docker Containers
Virtual Machine
Why Docker?
Docker Engine
Docker Architecture
Before learning the Docker architecture, rst, you should know about
the Docker Daemon.
fi
ffi
What is Docker daemon?
Docker architecture
1. Docker Client
Docker Client uses Command Line Interface (CLI) to run the following
commands -
ff
docker build
docker pull
docker run
2. Docker Host
3. Docker Registry
Docker Objects
Docker Images
Docker Containers
Containers are the structural units of Docker, which is used to hold the
entire package that is needed to run the application. The advantage of
containers is that it requires very less resources.
In other words, we can say that the image is a template, and the
container is a copy of that template.
Docker Networking
Docker Storage is used to store data on the container. Docker o ers the
following options for the Storage -
Step 3: Browse the location where you want to install the Docker
Toolbox and click on the Next.
fi
fi
Step 4: Select the components according to your requirement and
click on the Next.
You can check the Docker version using the following command.
1. docker -version
You can understand container and image with the help of the following
command.
Docker Container
ff
fi
fi
fi
fi
Docker Docker le
Docker le Instructions
The instructions are not case-sensitive but you must follow conventions
which recommend to use uppercase.
Run maven command - clean install, and a jar le gets created in the target
folder. Next we will start docker and deploy this jar using docker.
Create the docker le. Docker le is a list of commands that we want the
docker engine to execute. Go to the spring boot project folder and create a
docker le as follows-
From openjdk:8
copy ./target/employee-producer-0.0.1-SNAPSHOT.jar
employee-producer-0.0.1-SNAPSHOT.jar
CMD ["java","-jar","employee-producer-0.0.1-
SNAPSHOT.jar"]
fi
fi
fi
fi
Open the terminal and start the docker
systemctl start docker
Now open the terminal and go to the Spring Boot project folder.
Next we will build an image with the name producer.
docker image build -t employee-producer .
Next we will run the above image as a container. Also we will be publishing
the docker port 8080 to centos port 8080.
Here we have started the container with name as producer. Now using the
following command check the logs
docker container logs producer
The application has started successfully. Go to localhost:8080/employee, we
will see that our application is deployed successfully.
• Employee Producer -
• The project we will as follows-
•
• The docker le is as follows- From openjdk:8
• copy ./target/employee-producer-0.0.1-SNAPSHOT.jar
employee-producer-0.0.1-SNAPSHOT.jar
• CMD ["java","-jar","employee-producer-0.0.1-
SNAPSHOT.jar"]
•
fi
•
•
Open the terminal and start the docker systemctl start docker
•
•
•
Now open the terminal and go to the Spring Boot employee-producer project
folder.
Next we will build an image with the name producer.
docker image build -t employee-producer .
Next we will run the above image as a container named producer. Also we will
be publishing the docker port 8080 to centos port 8080.
docker container run --name producer -p 8080:8080 -d
employee-producer
So our employee container has started. We can test this by going to
localhost:8080/employee, we will see that our application is deployed
successfully.
Employee Consumer -
import java.io.IOException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import
org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
Open the terminal and go to the Spring Boot employee consumer project
folder.
Next we will build an image with the name consumer.
docker image build -t employee-consumer .
Here we can see that the container named consumer is not able to
communicate with the container named producer.
Lets start the employee consumer+ container on the newly created network.
docker container run --network consumer-producer --name
consumer -d employee-consumer