Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Steps and methods of using Docker to build Java Environment

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

What does Docker do?

Docker is an advanced container engine based on Linux Container (LXC-linux container), developed based on the go language, the source code is hosted on Github, and is open source according to the Apache2.0 protocol. Docker's goal is to implement a lightweight operating system virtualization solution.

The first thing to learn about Docker is to understand several concepts:

Mirror-the Docker image is similar to the common system ISO image and contains information about the application

Container-Container is equivalent to a virtual machine that can be run, the application runs in the container, and the Docker runs on "Docker"

Warehouse-Warehouse is the place where images are stored, with version control similar to git, which is also divided into two forms: public warehouse (Public) and private warehouse (Private).

Docker supports most Linux distributions. By using Docker containers, you can run your own applications on different operating systems and different machines, regardless of hardware, running environment and other configurations. Application migration becomes very simple.

Comparison between Docker and traditional Virtualization Technology

Compared with the traditional virtual machine technology, Docker takes up less resources and starts faster, which greatly facilitates the deployment and operation of the project.

Docker implements virtualization at the operating system level and reuses the operating system of the local host. The traditional way is to virtualize multiple operating systems on the basis of hardware, and then deploy related applications on the system.

This picture vividly illustrates the difference between traditional virtualization technologies such as Docker and VM:

Vs

Prepare for

First of all, you need to prepare an operating system for CentOS, and the virtual machine can also be used. The specific configuration requirements are as follows:

1. Must be a 64-bit operating system

two。 Kernel above 3.8 is recommended.

Install Docker

You only need to install the Docker software with the following command

Yum-y install docker-io

You can use the following command to see if Docker is installed successfully:

Docker version

If the output looks at the version number of Docker, the installation is successful, and you can start the Docker service with the following command:

Service docker start

If the service command fails to start, use the following

Systemctl start docker.service

Practice

Just like installing software, we first need to have a CD burning the software, and if you are using a virtual optical drive, you need to prepare the mirrored files through which to install the software. In the world of Docker, there are also mirrored files that have installed the operating system we need, which we generally call the Docker image.

Download the image

Docker search

Use docker pull imagename (mirror name) to download the image

After the download is complete, use the following command to view all local images:

Docker images

When the download is complete, you should see:

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEdocker.io/centos centos7 f753707788c5 12 days ago 127.1 MB

If you see the above output, you can use the image "docker.cn/docker/centos", or call it Repository, which has a Tag named "centos7" and an image ID called "25c5298b1a36" (this is randomly generated, so everyone sees it differently)

Start the container

The container runs on the basis of an image, and once the container is started, we can log in to the container and install the software or applications we need.

Use to enter docker that is already running

Docker attach dabfb413d8cf [Container ID]

Use the following command to start the container:

Docker run-I-t-v / root/software/:/mnt/software/-- privileged=true 2a392a47afc5

Docker run

The relevant parameters include:

-I: indicates that the container is running in interactive mode

-t: indicates that the container will enter its command line after startup

-v: indicates which local directory needs to be mounted to the container. Format-v:

Suppose all our installers are placed in the / root/software/ directory of the host, and now we need to mount them to the container's / mnt/software/ directory.

When all this is done, you can install software for this container.

Docker transfer file command

Docker cp more.log e7de404c00bd:/tmp/ 1f8787b81bcd

Install the Java development environment

We need to install jdk1.7, tomcat7 and nginx. Just download the installation package from the official website.

1. Install jdk

First, extract the JDK package:

Tar-zxf jdk-7u71-linux-x64.tar.gz-C

If it's a rpm package,

Rpm-ivh jdk-7u71-linux-x64.tar.gz

Then rename the folder

Mv jdk1.7.0_71/ jdk/

Finally, configure the environment variables

Vi / .bashrc

Add the following configuration at the end of the file:

Export JAVA_HOME=/opt/jdkexport PATH=$PATH:$JAVA_HOME

Open / etc/profile with a text editor

Add the following at the end of the profile file:

Export JAVA_HOME=/usr/share/jdk1.6.0_14 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

Finally, use the source command to make the environment variable take effect:

Source ~ / .bashrcsource / etc/profile

1. Install Tomcat

Similarly, extract the Tomcat package:

Tar-zxf apache-tomcat-7.0.55.tar.gz

Then rename the Tomcat directory:

Mv apache-tomcat-7.0.55/ tomcat/

Write a running script, and when you start the container, run the script to start Tomcat, as follows:

Vi / root/run.sh

Then, edit the script as follows:

#! / bin/bashsource ~ / .bashrcsh / opt/tomcat/bin/catalina.sh run

Note: you must first load the environment here, and then run Tomcat using Tomcat's running script

Finally, add execution permissions to run the script:

Chmod uplix / root/run.sh

1. Install nginx

First go to the official website to download the source code package. Note that if gz

Http://nginx.org/en/download.html download address

After downloading, extract the installation package:

Tar-zxvf nginx-1.11.5.tar.gz

Then configure the installation variable, open the decompressed directory-execute the command

Cd nginx-1.11.5

Configure the installation environment

. / configure-- prefix=/usr/local/servers/nginx "/ usr/local/servers/nginx" is the installation path

It is possible to appear. / configure: error: C compiler cc is not found

At this point, you need to run the command to update gcc.

Yum install gcc gcc-c++ ncurses-devel perlyum-y install pcre-develyum-y install zlib-develyum-y install autoconf libtool make

Execute in the decompression directory:

Make

Switch to the root user to execute the installation command

Make install

Create a soft chain

Ln-s / usr/local/servers/nginx/sbin/nginx / usr/local/bin/nginx

Start the nginx service

Nginx

Then use ps-ef | grep nginx to check whether the startup is successful.

Submit Docker image

First exit the docker image you just configured

Exit

Then you can see the docker image that you just exited using the following command

Docker ps-a

Then use the following command to create a new "mirror" based on a "container ID":

Docker commit 57c312bbaad1 javaweb:0.1

The container ID is "57c312bbaad1" and the mirror name created is "javaweb"

Note: the ID of "57c312bbaad1" is viewed using the docker ps command

After submitting a new image, you can store this image in the tar package.

Docker-o ~ / javaweb.tar javaweb

Docker save-o saved directory image name

Start the container

First use docker images to see all the current images.

Start the newly created image

Docker run-d-p 80:80-name javaweb javaweb:0.1 / root/run.sh

-d: indicates that the / root/run.sh script is executed in "daemon mode", when the Tomcat console does not appear on the output terminal.

-p: indicates the port mapping between the host and the container. At this time, port 80 inside the container is mapped to port 80 of the host, so port 80 is exposed to the outside world, and the port 80 inside the container can be accessed through the Docker bridge.

-- name: represents the container name and can be named with a meaningful name

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report