Install Jenkins automatic deployment project using Docker

See the previous article for the installation of Docker

Environment to prepare

Install mysql using Docker

Mysql5.7 is used here

Docker pull mysql: 5.7Copy the code

Start mysql and mount the directory

docker run -p 10081:3306 --name mysql \ -v /usr/local/docker/mysql/conf:/etc/mysql \ -v /usr/local/docker/mysql/logs:/var/log/mysql \ -v /usr/local/docker/mysql/data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD = password \ - d mysql: 5.7Copy the code

Then enter the container to enable remote access

docker exec -it mysql bash
Copy the code
mysql -uroot -ppassword
Copy the code
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql> flush privileges;
Copy the code

Write Dockerfile

# Docker image for springboot file run # VERSION 0.0.1 Qhliao # Base image using Java FROM Java :8 # author MAINTAINER Qhliao <[email protected]> # VOLUME specifies the temporary file directory as/TMP. Create a temporary file in /var/lib/docker EXPOSE 80 RUN bash -c 'touch /app.jar' ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]Copy the code

Writing shell scripts

CD 'dirname $0' # enter the root directory proj_home=$PWD # container port name = 10084 # docker exposed port # for docker container id and mirror id r_c = ` docker ps - a | grep "$appname" | awk '{print $1}' ` c = ` docker Ps - a | grep "$appname" | awk '{print $1}' ` r_img = ` docker images | grep "$appname" | awk '{print $3}' ` # if the container is running, If ["$r_c"x!= ""x]; Then docker stop "$r_c" if ["$c"x!= "x "]; Docker rm "$c" if ["$r_img"x!= ""x]; Then docker rmi "$r_img" fi # generate image docker build -t $img_output 8086 for port engineering docker run - d - name $appname - p $port: 8011 - link mysql: mysql - v/home/app/logs: / home/devlop/log - v /home/app/logs/backup:/home/devlop/log/backup $img_outputCopy the code

Docker installation Jenkins

docker pull jenkinsci/blueocean:latest
Copy the code
docker run --name jenkins -p 10083:8080 -p 50000:50000 -v /etc/timezone:/etc/timezone -v /etc/localtime:/etc/localtime -v /var/docker_data/jenkins/jenkins_home:/var/jenkins_home -v /var/docker_data/jenkins/settings:/var/settings -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -d jenkinsci/blueocean
Copy the code

Then open Jenkins in open IP :10083

Install plug-ins such as Maven, Git, and NPM

Finally configure the project. I won’t bother writing it here… Deploy at the end