preparation
Intranet environment deployment project, the configuration environment is cumbersome. Use the docker import / export image and container function to create and export the project environment on the networked server, and then import it directly on the intranet server.
Offline installation
1. Download docker installation package
Download docker and install the binary package on the official website and select the version suitable for you. Here you can download docker-18.06.1-ce.tgz and install it in CentOS 7.
Download address: https://download.docker.com/linux/static/stable/x86_64/
2. Copy docker-18.06.1-ce.tgz to the server
3. Prepare profile
Create and edit files
vi docker.service
File content
docker.service [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s [Install] WantedBy=multi-user.target
4. Create installation script
Create and edit scripts
vi install.sh
Script content
#!/bin/sh echo 'decompression tar package...' sudo tar -xvf $1 echo 'take docker Move directory to/usr/bin Directory...' sudo cp docker/* /usr/bin/ echo 'take docker.service Move to/etc/systemd/system/ catalogue...' sudo cp docker.service /etc/systemd/system/ echo 'Add file permissions...' sudo chmod +x /etc/systemd/system/docker.service echo 'Reload profile...' sudo systemctl daemon-reload echo 'start-up docker...' sudo systemctl start docker echo 'Set startup and self startup...' sudo systemctl enable docker.service echo 'docker Installation succeeded...' docker -v
5. Execute script installation
sh install.sh docker-18.06.1-ce.tgz
If you see the version number, the installation is successful
6. Create uninstall script
Create and edit scripts
vi uninstall.sh
Script content
#!/bin/sh echo 'delete docker.service...' sudo rm -f /etc/systemd/system/docker.service echo 'delete docker file...' sudo rm -rf /usr/bin/docker* echo 'Reload profile' sudo systemctl daemon-reload echo 'Uninstall succeeded...'
7. Execute script uninstall
sh uninstall.sh
Uninstall succeeded
Make image
1. Prepare a simple jar package for eureka service
Baidu online disk link: https://pan.baidu.com/s/11GegZ_fyyOLpsZ-5sXJr4g, extraction code: qm01
2. Upload to server
3. Make Dockerfile script
vi Dockerfile
Script content
echo 'Specify base mirror' FROM openjdk:8-jdk-alpine echo 'Define a variable,Receive input parameters' ARG JAR_FILE echo 'Copy files to container root' COPY ${JAR_FILE} app.jar echo 'The monitoring port of the burst container during operation is provided to the outside' EXPOSE 10086 echo 'Start command that runs when the container starts' ENTRYPOINT ["java","-jar","/app.jar"]
4. Build mirror
docker build --build-arg JAR_FILE=tensquare_eureka_server-1.0-SNAPSHOT.jar -t eureka:v1 .
- JAR_FILE: jar name
- eureka:v1: image name and label
- .: represents finding Dockerfile files in the current directory
If there is no basic image, the image will be pulled at the first run.
5. Check whether the image is created successfully
docker images
Making containers
docker run -i --name=eureka -p 10086:10086 eureka:v1
You can see the startup log during production. According to the log, you can confirm whether the project is started successfully. After successful startup, you can exit.
View the created container
Run container
1. Start container
2. Open ports or close firewalls
Open port
firewall-cmd --zone=public --add-port=10086/tcp --permanent firewall-cmd --reload
Turn off firewall
systemctl stop firewalld
3. Access eureka services
Mirror import and export
Export mirror
1. Export command
docker save [options] images [images...]
2. Export image to current directory
docker save -o eureka.tar eureka
3. View exported images
Import mirror
1. Upload the exported image to another server in the Intranet environment
2. Import command
docker load [options]
3. Import the image in the current directory
docker load -i eureka.tar
4. Import and view images
Making containers
1. Create container
docker run -i --name=eureka -p 10086:10086 eureka:v1
You can see the startup log during production. According to the log, you can confirm whether the project is started successfully. After successful startup, you can exit.
2. Run container
docker start eureka
Start successful
3. Access eureka services
Container import and export
Export container
1. Export command
docker export [options] container
2. Export container to current directory
docker export -o eureka_container.tar eureka
3. View exported images
Import container
1. Delete previously created containers
docker rm eureka
If the container needs to stop running, it can be deleted
2. Upload the exported container to another intranet server
3. Import command
docker import [options] file|URL|- [REPOSITORY[:TAG]]
3. Import containers in the current directory
docker import eureka_container.tar eureka:v1
4. Import and view images
Run container
1. Create container
docker run -i --name=eureka -p 10086:10086 eureka:v1
Error reported: docker: Error response from daemon: No command specified
The reason is that the image exported by docker needs to specify command when starting
Copy the command content in the extranet server to the create container command. (brackets are not required)
docker run -i --name=eureka -p 10086:10086 eureka:v1 java -jar /app.jar
2. Run container
docker start eureka
Start successful
3. Access eureka services