docker builds the jenkins image and runs

  1. Download the Jenkins.war file: From the Jenkins official website (https://get.jenkins.io/war-stable/) or other reliable sources to download the Jenkins.war file. Jenkins.war is the Jenkins executable file.

  2. Pull the base image: Select an appropriate base image, usually one that contains OpenJDK.

    注意j:dk版本,根据要求选择,最新的jenkins要求为jdk11版本以上

docker pull openjdk:8-jdk-alpine
  1. Prepare the Dockerfile: Create a Dockerfile to define the build steps for the Docker image.
    Here is a simple Dockerfile example, using OpenJDK 8 as an example:
# 使用 OpenJDK 8 作为基础镜像
FROM openjdk:8-jdk-alpine

# 维护者信息
LABEL maintainer="[email protected]"

# 将 Jenkins.war 复制到容器中的 /app 目录
COPY ./jenkins.war /app/jenkins.war

# 暴露 Jenkins 端口
EXPOSE 8080

# 启动 Jenkins
CMD ["java", "-jar", "/app/jenkins.war"]

Make sure to replace [email protected] in the above Dockerfile with your email address and place Jenkins.war in the same directory as the Dockerfile.

  1. Build the Docker image: Use the following command to build the image in Docker:
docker build -t your-image-name:tag .

Where,your-image-name is the name you chose for the image, and tag is the version label.

  1. Run the Docker container: Use the following command to run the built image in Docker:
docker run -p 8080:8080 -d your-image-name:tag

This will run the Jenkins container in the background and map the host's 8080 port to the container's 8080 port.

You should now be able to access Jenkins via your browser http://localhost:8080 . On first access, you will need to provide a Jenkins unlock key, which will appear in the container logs. Container logs can be viewed using the following command:

docker logs <container-id>

where <container-id> is the ID of the container you are running.

The above steps provide a basic Jenkins Docker image, which you can adjust according to your needs, such as adding plugins, configuration files, etc.

Guess you like

Origin blog.csdn.net/LSW1737554365/article/details/134602057