安裝和啓動docker

一、安裝和啓動dockerjava

yum update -ylinux

yum install -y yum-utilsgit

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repogithub

yum -y install docker-cedocker

systemctl start dockershell

二、設置鏡像apache

vi /etc/docker/daemon.jsonjson

{
"registry-mirrors": ["https://aj2rgad5.mirror.aliyuncs.com"]
}centos

三、開放管理端口映射bash

vi /lib/systemd/system/docker.service

將第11行的ExecStart=/usr/bin/dockerd,替換爲:

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock -H tcp://0.0.0.0:7654

2375是管理端口,7654是備用端口

在~/.bashrc中寫入docker管理端口

export DOCKER_HOST=tcp://0.0.0.0:2375

source ~/.bashrc

四、重啓docker

systemctl daemon-reload && service docker restart

五、測試docker是否正常安裝和運行

docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.


一、安裝maven

wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz

tar -zxvf apache-maven-3.5.0-bin.tar.gz

vi ~/.bashrc

export MAVEN_HOME=/usr/local/apache-maven-3.5.0
export PATH=$PATH:$MAVEN_HOME/bin

source ~/.bashrc

mvn -version

cd /usr/local/apache-maven-3.5.0/conf

vi settings.xml

<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

二、安裝git

yum install -y git

git --version

三、將代碼推送到github中

一、新建一個任務

二、構建一個自由風格的軟件項目

三、配置Github,包括github地址,用戶名和密碼,分支

四、配置構建環境

增長構建步驟 -> invoker top-level-Maven targets

Maven version: maven3.5.0
Goals: clean package
POM: pom.xml

五、增長構建步驟 -> execute shell

#!/bin/bash
REGISTRY_URL=192.168.189.54:2375
WORK_DIR=/root/work_build
PROJECT_NAME=eureka-server
PROJECT_VERSION=0.0.1-SNAPSHOT
if [ ! -e ${WORK_DIR}/${PROJECT_NAME} ] && [ ! -d ${WORK_DIR}/${PROJECT_NAME} ]; then
mkdir -p ${WORK_DIR}/${PROJECT_NAME}
echo "Create Dir: ${WORK_DIR}/${PROJECT_NAME}"
fi
if [ -e ${WORK_DIR}/${PROJECT_NAME}/Dockerfile ]; then
rm -rf ${WORK_DIR}/${PROJECT_NAME}/Dockerfile
echo "Remove File: ${WORK_DIR}/${PROJECT_NAME}/Dockerfile"
fi
cp /root/.jenkins/workspace/eureka-server/Dockerfile ${WORK_DIR}/${PROJECT_NAME}/
cp /root/.jenkins/workspace/eureka-server/target/*.jar ${WORK_DIR}/${PROJECT_NAME}/
cd ${WORK_DIR}/${PROJECT_NAME}/
docker build -t ${REGISTRY_URL}/eshop-detail/${PROJECT_NAME}:${PROJECT_VERSION} .
docker push ${REGISTRY_URL}/eshop-detail/${PROJECT_NAME}:${PROJECT_VERSION}
if docker ps -a | grep ${PROJECT_NAME}; then
docker rm -f ${PROJECT_NAME}
echo "Remove Docker Container: ${PROJECT_NAME}"
fi
docker run -d -p 8761:8761 --name ${PROJECT_NAME} ${REGISTRY_URL}/eshop-detail/${PROJECT_NAME}:${PROJECT_VERSION}

六、執行一些修改

(1)修改1:在系統配置中設置maven,而後在配置中選擇本身配置的maven版本,解決cannot run mvn program的錯誤

(2)修改2:編寫DockerFile

FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD eureka-server-0.0.1-SNAPSHOT.jar app.jar
#RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
EXPOSE 8761

七、執行構建

八、訪問http://192.168.31.253:8761/,能夠看到eureka-server的頁面

相關文章
相關標籤/搜索