The premise of the problem is this, we have modified the code of a certain module of the platform, and want to put the modification directly into the docker image, so that our k8s
environment can directly use this image to start the container;
Run the image that needs to be modified first. Our image will depend on other configurations of the platform and cannot be run alone. We can just run the container in this way without starting the services inside;
docker run -d --name needModifyImage nbiot.com/needModifyImage:1.0.0 /bin/bash -c "tail -f /dev/null"
Copy the files or jar packages that need to be modified to the already running needModifyImage container (replace the files or jars that need to be modified directly);
docker cp needModifyImage_20210120.jar needModifyImage:/opt/nbiot/config/jar/
(Remember, after copying the jar package to the container, pay attention to modifying the operation permissions of the jar file, in case an error occurs without the read
permission when running, chmod +x needModifyImage_20210120.jar
)
Make a snapshot of the modified needModifyImage container and save it to the local directory;
docker export needModifyImage > needModifyImage_20200120.tar
Restore the snapshot (needModifyImage_20200120.tar) to a new image with the specified name; (on which server you run this command, the image will be generated on that server)
cat needModifyImage_20200120.tar |docker import - nbiot.com/needModifyImage:2.0.0
Modify the image version in the configuration helm chart for starting k8s - pod to the new nbiot.com/needModifyImage:2.0.0, and start it;
helm install -n myServiceName myServiceName/
View the started pod information;
kubectl describe pod myServiceName
Found startup error
Warning Failed 8s (x2 over 9s) kubelet, worknode2 Error: Error response from daemon: No command specified
If there is no execution command, the above error will be reported, because we are a service started by pod, and there is no way to add executable commands to the command line that is directly restarted like docker. command, added in the yaml
file;
spec:
securityContext:
runAsNonRoot: true
runAsUser: 10555
fsGroup: 10555
containers:
- name: server
image: xxxxxx-xxxxxx:xxxx
command: ["java", "-XX:MaxRAM=1825361100", "-XX:MaxRAMFraction=1", "-Djava.security.egd=file:///dev/./urandom", "-Dlog4j2.configurationFile=/staging/jars/log4j_server.xml", "-DCONFIGDIR=/appl/config", "-Dname=ServerId", "-jar", "/staging/jars/server.jar"]
imagePullPolicy: Always