Blanche
Engineer
Engineer
  • UID619
  • Fans3
  • Follows2
  • Posts59
Reads:2649Replies:0

How to deploy Docker in Debian

Created#
More Posted time:Aug 30, 2016 18:11 PM
Introduction
This article introduces how to deploy Docker in Debian. For basic knowledge about Docker, go to the Related Documents.
Install Docker
1. Add APT sources as the root user, and add public keys to authorize Docker installation sources
$ curl -s 'https://sks-keyservers.net/pks/lookup?op=get&search=0xee6d536cf7dc86e2d7d56f59a178ac6c6238f52e' | sudo apt-key
add --import

Install APT HTTPS support

sudo apt-get update && sudo apt-get install apt-transport-https
Install Image virtulization support

sudo apt-get install -y linux-image-extra-virtual
Add APT sources

echo "deb https://packages.docker.com/1.11/apt/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
Install Docker

apt-get update && apt-get install docker-engine
Check whether the installation succeeds

docker info
The following information indicates a successful installation

Containers: 1
 Running: 1
 Paused: 0
 Stopped: 0
Images: 15
Server Version: 1.11.2-cs3
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 17
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge null host
Kernel Version: 3.16.0-4-amd64
Operating System: Debian GNU/Linux 8 (jessie)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.871 GiB
Name: debian
ID: IWCZ:QXXZ:VBUN:UMF7:XRG3:CMXB:6LUO:F65C:OA6B:75QQ:7SEW:3OKT
Docker Root Dir: /var/lib/docker
Debug mode (client): false
Debug mode (server): false
Registry: https://index.docker.io/v1/


Make basic software images
JDK 8
The JDK should be installed first. Here we use JDK 8.
Download JDK
Write the Dockerfile in the same directory
FROM registry.cn-hangzhou.aliyuncs.com/yuuji/debian:latest

ADD jdk-8u101-linux-x64.tar.gz /opt

ENV JAVA_HOME /opt/jdk1.8.0_101

WORKDIR /usr/bin
RUN ln -s /opt/jdk1.8.0_101/bin/java java

The directory is structured as follows:
 

Compile and publish it
docker build -t jdk8 .
You can also create a repository on Docker Hub servers and publish it to remote servers

docker build -t registry.cn-hangzhou.aliyuncs.com/xxx/jdk8 .
docker push registry.cn-hangzhou.aliyuncs.com/xxx/jdk8


You can view the published repository on the remote server, or through a command
docker images

mave3
Based on JDK 8, we can make an image of Maven 3 following the same steps above. I will not go into the command details here.
Dockerfile
FROM registry.cn-hangzhou.aliyuncs.com/yuuji/jdk8:latest

ADD settings.xml /root/.m2/settings.xml
ADD apache-maven-3.3.9-bin.tar.gz /opt

WORKDIR /usr/bin
RUN ln -s /opt/apache-maven-3.3.9/bin/mvn mvn


Publish and see whether it succeeds.
Software errors
What can we do if errors occur during the process?
Run command docker images. If none is displayed, run command docker rmi IMAGE ID to clear the image.
If the clear operation failed, it may be because the image is being used.

Run command docker ps -a to locate the container using the image, and run command docker rm CONTAINER ID.
Compile project for deployment
Run command spring-boot to start the project, and then create the Dockerfile under the project and directory.
FROM registry.cn-hangzhou.aliyuncs.com/yuuji/maven3:latest

EXPOSE 7001

RUN mkdir -p /opt/leona
WORKDIR /opt/leona
ADD . /opt/leona

RUN mvn clean install -Dmaven.test.skip

CMD ["java","-jar","target/leona.jar"]


Port 7001, which is configured by your spring-boot web.
The structure is as follows:


The way to compile the image is the same as that for software. Here I will not publish it to the remote server.
docker build -t xxx .
The final docker image in the local repository:



Deploy Docker
After the software and application image is compiled, it’s time for deployment.
docker run -d -p 7001:7001 xxx
Run a check using curl localhost:7001

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>Leona</title>
    </head>
<body>
    hello word!
</body>
</html>

It is easy, isn’t it?
Guest