• UID619
  • Fans3
  • Follows2
  • Posts59

How to deploy Docker in Debian

More Posted time:Aug 30, 2016 18:11 PM
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 '' | 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 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
 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
Docker Root Dir: /var/lib/docker
Debug mode (client): false
Debug mode (server): false

Make basic software images
The JDK should be installed first. Here we use JDK 8.
Download JDK
Write the Dockerfile in the same directory

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 .
docker push

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

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.

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.


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">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    hello word!

It is easy, isn’t it?