docker-image package

Simple mirror package operation, can be used as a reference

#Create dockerfile

cat > Dockerfile << EOF

from openjdk:8

MAINTAINER [email protected]

#Avoid Chinese garbled

ENV LANG C.UTF-8

#Time zone setting (the date is eight hours apart)

RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \

echo 'Asia/Shanghai' >/etc/timezone

# Add items jar package to the mirror note path

ADD admin-service-0.1.jar /usr

CMD ["java", "-jar","/usr/admin-service-0.1.jar"]

EOF

#Build a mirror (Dockerfile executes commands in the same level directory) Note that there is a dot (.) At the end 

docker build -t admin .

#Run container

docker run -p 8090:8090 --name myadmin -d admin

#Output log

docker logs myadmin

The following quick delete container and image can be put together with the above command in a shell to achieve faster image reconstruction, container restart and update.

#Delete the old container script if there is

cat > rm.sh << 'EOF'

#!/bin/sh

NAME=$1

ID=`docker ps -a | grep "$NAME" | awk '{print $1}'`

for id in $ID

do

docker stop $id

docker rm $id

echo 'rm' $id

done

EOF

#Delete the old mirror script if there is

cat > rmi.sh << 'EOF'

#!/bin/sh

NAME=$1

ID=`docker images | grep "$NAME" | awk '{print $1}'`

for id in $ID

do

docker rmi $id

echo 'rmi' $id

done

EOF

#Delete old container

sh rm.sh myadmin

#Delete old mirror

sh rmi.sh admin

#You can rebuild the mirror (repeat the steps just started) 

 

#You can also put these commands in a shell script to execute the script after uploading the jar directly when updating

Automatically delete old containers, old images, build new images, and run new containers

 

 

 

Guess you like

Origin blog.csdn.net/qq_36338555/article/details/103390162