编程知识 cdmana.com

Young people's first docker application, greatly improving productivity!

Last one : The first young man Spring Boot application !

ha-ha , I copied the title of Lei , It doesn't matter , It is important to Docker Really young , Although it's not until now 8 year , But it's a rising star , The fire was a mess .

In recent years Docker It's too hot ,Docker do ? do Java How can you not know Docker? therefore , In this article, the stack leader takes you to do the first Docker application , You'll have a basic understanding of .

Maybe some people think Docker It has nothing to do with myself , Just write your own code ,Docker That's for O & M , After reading this , I want to change your mind .

One 、 What is? Docker?

Docker Is now the most mainstream open source container , follow Apache 2.0 agreement , Use GO Language development , Began in 2013 year , Now joined Linux The foundation .

Docker The core idea of :"Build once, Run anywhere", namely : A build , Run everywhere , This could be an operating system 、 One Web application , Or a database service .

We can Docker It means a lightweight sandbox ,Docker Containers are completely sandboxed , Each container has its own environment and components that run independently , Containers are isolated from each other and do not affect each other , You can also communicate between containers .

Docker Support all major operating systems , Such as :Linux/Mac/Windows, All mainstream cloud services also support Docker, therefore , We can apply and rely on 、 Environmental information, etc. are packaged into a Docker In the container , Can be very easy to achieve application release 、 Migration, etc .

Docker Official website :

https://www.docker.com/

Docker Managed code :

https://github.com/docker

Two 、 install Docker

Docker There is a community edition 、 Enterprise Edition . The Community Edition is open source and free , The enterprise edition is for a fee , Of course, there will be more powerful features and services , General application community version is enough .

Docker The installation is simple , Here's the stack leader Mac and Docker Community Edition as an example for installation demonstration .

open Docker Start page :

https://www.docker.com/get-started

download Mac edition Docker Install the package directly .

Use... After installation docker -v Command to view Docker edition :

$ docker -v
Docker version 19.03.13, build 4484c46d9d、

Use docker version You can also see the full version information :

docker version
Client: Docker Engine - Community
 Cloud integration  0.1.18
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 16:58:31 2020
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46d9d
  Built:            Wed Sep 16 17:07:04 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

notice Docker The version information indicates that the installation was successful .

3、 ... and 、 start-up Docker

Mac Version of Docker Just click the application icon to enter and it will start automatically , You can also set the boot to start automatically .

Mac edition Docker The official comes with its own console client , adopt Dashboard Menu entry .

The container can be used through the console 、 Image management 、 Settings, etc .

All in all Docker It's very easy to install and start , Different system environments can be easily done .

Four 、 first Docker application

be familiar with Tomcat Our friends all know ,Tomcat After installation Webapp I'll bring some of them below Web project . About Tomcat The official account of the series is public. Java Technology stack search reading .

Docker So it is with ,Docker After installation, it will also bring some mirrors , You can see it in the console , You can also use docker images Command to view all locally owned Docker Mirror image .

As shown in the figure below , Switch to Images:

Docker Bring one with you docker tutorial Mirror image , It's a learning Docker Wizard image of , Itself is a Web Image of application , How to start it ?

The image is just a read-only static file , Can not run , The container is the running instance of the mirror , So you need to add a container to run .

Client running

The easiest way is to click the run button on the right side of the image :

Fill in the necessary information for the container in the above dialog box , For example, the port of the container and the port of the local machine are both 80, Finally, click the run button .

here Docker There is a new one in the container docker-tutorial Containers , And run on 80 port .

So let's visit this Docker application , Open the browser or input through the right side of the container http://localhost/ Visit :

congratulations , It has run successfully !

Command line run

The client operation is only auxiliary , Command line is the essence , Study Docker We should also remember the common commands , Actually, we just created a new container 、 The running container is done at one time through this command :

docker run -d -p 80:80 docker/getting-started

This is equivalent to creating a new container based on the image 、 Run the container again .

Simply explain the meaning of each parameter :

It can also be reduced to :

docker run -dp 80:80 docker/getting-started

So take this image as an example , First stop the container on the client , And then start it with the command :

$ docker run -dp 80:80 docker101tutorial
9df38488adcc2a53dad65691854ffc603e1fb3e25954183b83200809805b0d93

Successful startup will output the container's ID.

adopt docker ps Command to view all running containers :

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
9df38488adcc        docker101tutorial   "/docker-entrypoint.…"   3 minutes ago       Up 3 minutes        0.0.0.0:80->80/tcp   hopeful_gauss

You can see , our docker101tutorial The container is running again , It can also be accessed normally .

in addition , adopt docker ps -a Command to view all containers .

Four 、 Conclusion

This paper introduces the stack length Docker Basic concepts of ,Docker Installation and startup of , And the first one Docker Application running .

With Docker Mirror image , We can install any Docker Running on the machine , There is no need to repeatedly configure the environment, install dependencies, etc , Is it cool ?

Docker There are also a lot of official good images in public warehouses , Such as :Nginx、MySQL、Redis etc. , Can be used directly , therefore , Don't talk about it Docker It's just for operation and maintenance , and Java Development doesn't matter much , Use it well , We develop efficiency leverage , It can also improve our technical level .

Okay , The first young man's Docker That's where the app is , The subsequent stack length will bring more Docker Practical tutorial , such as Spring Boot And IDEA Integrated use of , Official account Java The first time the technology stack pushes .

I think it's good , Looking at 、 Share and forward , It's not easy to write , I need your encouragement , Thank you, old fellow iron. !

Copyright notice : The official account is No. "Java Technology stack " original , It's not easy to be original , Reprint 、 Please indicate the source of this article , No plagiarism 、 Manuscript preparation , Please take care of yourself , Respect other people's labor achievements and intellectual property rights .

Recent hot article recommends :

1.Java 15 Official release , 14 A new feature , Refresh your mind !!

2. Finally, I got it through open source projects IntelliJ IDEA Activation code , It's delicious !

3. I use Java 8 Wrote a piece of logic , I can't understand it , You try ..

4. To hang up Tomcat ,Undertow It's very powerful !!

5.《Java Development Manual ( Song Mountain version )》 The latest release , Download it quickly !

I think it's good , Don't forget to like it + Forward !

版权声明
本文为[Java technology stack]所创,转载请带上原文链接,感谢

Scroll to Top