Docker Introduction#
What Is The Docker?#
- Docker is
a container management service
. The keywords of Docker are develop, ship and run anywhere. The whole idea of Docker is for developers to easily develop applications, ship them intocontainers
which can then be deployed anywhere. - The initial release of Docker was in March 2013 and since then, it has become the buzzword for modern world development, especially in the face of Agile-based projects.
- More Information
Docker Components#
- Docker contains some main components as below
Docker for Windows
− It allows one to runDocker containers
on the Windows OS. We also have docker for Linux and MacOS.Docker Engine
− It is used for buildingDocker images
and creatingDocker containers
. It is the heart of Docker.Docker Hub
− This is the registry which is used to host variousDocker images
.Docker Compose
− This is used to define applications usingmultiple Docker containers
.
What Is The Docker Engine?#
The Docker engine
is an open-source software designed to build and run applications in isolated environments known as containers.- It uses OS-level virtualization to run the applications. This is similar to virtual machines but the Docker engine offers a more resource-friendly and portable environment to our processes.
- Developed by Docker.Inc under the Apache License, the Docker engine hosts images, networks, and containers through a server-side daemon process. Since its initial release in 2013, Docker has grown massively in demand and reputation.
What Is The Docker Container?#
A container
is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.A Docker container image
is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.Container images (docker images)
becomecontainers
at runtime and in the case of Docker images become containers when they run onDocker Engine
.- More information
What Is The Docker Images?#
- A
Docker image
is a file used to execute code in aDocker container
.Docker images
act as a set of instructions to build aDocker container
, like a template.Docker images
also act as the starting point when using Docker. An image is comparable to a snapshot in virtual machine (VM) environments - Docker Engine is used to create, run and deploy applications in containers. A
Docker image
contains application code, libraries, tools, dependencies and other files needed to make an application run. When a user runs an image, it can become one or many instances of a container. - More indormation
- Example of a docker image to run a spring boot project
#get docker image with openjdk 8 installed from docker hub
FROM openjdk:8-jdk-alpine
#expose port 8080 to real machine
EXPOSE 8080
#some information for docker image
LABEL owner="duc"
LABEL maintainer="minhducnguyen189@gmail.com"
LABEL description="test image my project"
#copy the jar file in target folder into docker image
COPY target/my-project-1.0.0-SNAPSHOT.jar my-project-1.0.0-SNAPSHOT.jar
#run command java to run jar package when docker image is run
ENTRYPOINT ["java","-jar","/my-project-1.0.0-SNAPSHOT.jar"]
- run command
docker build . --tag myproject
to build a docker image with namemyproject
- run command
docker run -it -p8080:8080 myproject
to run a docker container with 8080 is mapped out side to real machine.
What Is The Docker Hub?#
Docker Hub
is a service provided by Docker for finding and sharing container images with your team. It is the world’s largest repository of container images with an array of content sources including container community developers, open source projects and independent software vendors (ISV) building and distributing their code in containers.- Users get access to free public repositories for storing and sharing images or can choose a subscription plan for private repositories.
- More information
What Is The Docker-Compose?#
Docker Compose
is a tool for defining and running multi-container Docker applications. With Docker Compose, you use a YAML file to configure your application’s services. Then, with a single commanddocker-compose up
, you create and start all the services from your configuration.- Using Compose is basically a three-step process:
- Define your app’s environment with a
Dockerfile
so it can be reproduced anywhere. - Define the services that make up your app in
docker-compose.yml
so they can be run together in an isolated environment. - Run
docker-compose
up and the Docker compose command starts and runs your entire app. You can alternatively rundocker-compose up
using the docker-compose binary.
- Define your app’s environment with a
- An docker-compose.yml is like the example below. In this example we can see that we have 2 services, one is the mysql_db_container which is using image
mysql:latest
from the docker hub. The second one is theadminer_container
which is using the imageadminer:latest
from the docker hub also.
docker-compose.yml | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Install Docker And Docker-Compose#
- Go to link below to download and install Docker as default:
- For Window
-
For Install Docker Compose
- For Linux
- For Window, It included in the Docker Desktop so we don't need to install anymore.