The requirement of this document is that the Docker image has already been running in Docker Desktop, but it needs to be deployed and run in other environments. Therefore, the main steps of the document are to package the image, upload the image, and start the image.
I. Package the Image
Ensure that the image can start normally in the container in Docker Desktop.
View Docker images
docker images
Save Docker images
docker save -o d:/mysql.tar jeecg-boot-mysql
docker save -o d:/redis.tar redis
docker save -o d:/system.tar jeecg-boot-system
II. Upload the Image
The Docker environment must be installed in the new environment. If it is a Windows computer, WSL2 must be enabled. Refer to the following blog for the enabling method.
Reference Blog: https://blog.csdn.net/GoodburghCottage/article/details/131413312
Refer to the blog for installing Docker on Linux
Reference Blog: https://www.jianshu.com/p/c9a05d3f6448
Upload the image file in the new environment. When executing the command, you can open the command window by typing cmd in the folder address bar and pressing Enter. The commands are as follows
docker load -i ./mysql.tar
docker load -i ./redis.tar
docker load -i ./system.tar
III. Start the Image
If the images reference each other, you need to consider the network issues in the containers. You need to create a virtual network and add all applications in the containers to this virtual network.
Create a network using the Docker command
docker network create jeecg-boot-demand_default
Connect to the network after starting
docker network connect jeecg-boot-demand_default jeecg-boot-mysql
docker network connect jeecg-boot-demand_default jeecg-boot-redis
docker network connect jeecg-boot-demand_default jeecg-boot-system
Start the image
docker create –name jeecg-boot-system
–network jeecg-boot-demand_default
–label=’com.docker.compose.project=jeecg-boot-demand’
-p 8080:8080 jeecg-boot-system
docker start jeecg-boot-system
Or
docker run
–name jeecg-boot-redis
–hostname=127.0.0.1
–env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
–env=GOSU_VERSION=1.14 –env=REDIS_VERSION=5.0.14
–env=REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-5.0.14.tar.gz
–volume=/data
–network=jeecg-boot-demand_default
–workdir=/data
-p 6379:6379
–restart=always
–label=’com.docker.compose.container-number=1′
–label com.docker.compose.project=jeecg-boot-demand
–runtime=runc -d redis:5.0
IV. Write Scripts
On a Windows computer, you can write scripts to upload and start images. Write three scripts respectively.
- Upload and start script, named docker_load.bat
@echo off
docker load -i ./mysql.tar
docker load -i ./redis.tar
docker load -i ./system.tar
REM Create network
docker network create jeecg-boot-demand_default
REM Create volumes
docker volume create jeecg-boot-mysql-volume
docker volume create jeecg-boot-redis-volume
REM Create and start MySQL container
docker run --name jeecg-boot-mysql --hostname=127.0.0.1 --env=MYSQL_PASSWORD=jyydemand123 --env=MYSQL_ROOT_PASSWORD=root --env=MYSQL_DATABASE=jyy-demand --env=MYSQL_USER=jyy-demand --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env=GOSU_VERSION=1.12 --env=MYSQL_MAJOR=8.0 --env=MYSQL_VERSION=8.0.19-1debian10 --env=TZ=Asia/Shanghai --volume=/var/lib/mysql --network=jeecg-boot-demand_default -p 3306:3306 --restart=always --label='com.docker.compose.config-hash=7330aa2ea8856385a5e1acaed3d7f033321f2c8ac9fd4cf409c556ca3b020cd5' --label='com.docker.compose.container-number=1' --label='com.docker.compose.depends_on=' --label='com.docker.compose.image=sha256:a900ffe8bac658f15c4fb0a104f1408afac77e2a75ee2e10c768baa05124354d' --label='com.docker.compose.oneoff=False' --label='com.docker.compose.project=jeecg-boot-demand' --label='com.docker.compose.service=jeecg-boot-mysql' --label='com.docker.compose.version=2.27.0' --runtime=runc -d jeecg-boot-mysql --lower_case_table_names=1
REM Create and start Redis container
docker run --name jeecg-boot-redis --hostname=127.0.0.1 --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env=GOSU_VERSION=1.14 --env=REDIS_VERSION=5.0.14 --env=REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-5.0.14.tar.gz --env=REDIS_DOWNLOAD_SHA=3ea5024766d983249e80d4aa9457c897a9f079957d0fb1f35682df233f997f32 --volume=/data --network=jeecg-boot-demand_default --workdir=/data -p 6379:6379 --restart=always --label='com.docker.compose.config-hash=740f57d5f9593e5e31e0ef86ce772289a322e39b01d74663b729d5e1e019e6c9' --label='com.docker.compose.container-number=1' --label='com.docker.compose.depends_on=' --label='com.docker.compose.image=sha256:99ee9af2b6b19af32115d853877d1ef1aac2768005dcbfeea7cbdeea30c1d79c' --label='com.docker.compose.oneoff=False' --label com.docker.compose.project=jeecg-boot-demand --runtime=runc -d redis:5.0
REM Create and start Jeecg Boot System container
docker create --name jeecg-boot-system --network jeecg-boot-demand_default ^
--label='com.docker.compose.project=jeecg-boot-demand' ^
-p 8080:8080 jeecg-boot-system
docker start jeecg-boot-system
REM Connect containers to network (if not already connected)
docker network connect jeecg-boot-demand_default jeecg-boot-mysql
docker network connect jeecg-boot-demand_default jeecg-boot-redis
docker network connect jeecg-boot-demand_default jeecg-boot-system
echo All containers have been set up and started successfully.
- Separate start script, named docker_start.bat
@echo off
docker start jeecg-boot-mysql
docker start jeecg-boot-redis
docker start jeecg-boot-system
echo All containers have been set up and started successfully.
- Separate stop script, named docker_stop.bat
@echo off
echo Stopping containers...
REM Stop the containers
docker stop jeecg-boot-system
docker stop jeecg-boot-mysql
docker stop jeecg-boot-redis
echo All containers stoped successfully.
- Uninstall container script, named docker_uninstall.bat, use this script with caution, it can be optional
@echo off
echo Stopping and removing containers...
REM Stop the containers
docker stop jeecg-boot-system
docker stop jeecg-boot-mysql
docker stop jeecg-boot-redis
REM Remove the containers
docker rm jeecg-boot-system
docker rm jeecg-boot-mysql
docker rm jeecg-boot-redis
echo Removing volumes...
REM Remove the volumes
docker volume rm jeecg-boot-mysql-volume
docker volume rm jeecg-boot-redis-volume
echo Removing network...
REM Remove the network
docker network rm jeecg-boot-demand_default
echo All containers, volumes, and network have been removed successfully.