Docker installs Jenkins quickly

insert image description here

Installing Jenkins is a common task, and installing using Docker simplifies the process and ensures a consistent environment. Here are the detailed steps to install Jenkins in Docker:

  1. Install Docker : First, make sure you have installed Docker on the target machine. According to your operating system, you can find the perfect installation steps on the official Docker website. Here I will provide you with the installation tutorials in previous articles, which can be used as a reference.

    Contains Docker installation tutorial, no pitfalls

  2. Get the Jenkins image : Open a terminal or command line interface to get the Jenkins image in Docker. Use the following command to pull the official Jenkins image:

docker pull jenkins/jenkins:lts
  1. Create a Jenkins data volume (optional) : If you want to keep Jenkins data and configuration information in the container, you can create a Docker data volume. This way, even if the container is deleted, the data remains.
docker volume create jenkins-data
  1. Start the Jenkins container : Use the following command to start the Jenkins container. Be careful to <YOUR_LOCAL_PORT>replace with the port number you wish to use locally (for example, 8080).
docker run -d -p <YOUR_LOCAL_PORT>:8080 -v jenkins-data:/var/jenkins_home --name jenkins jenkins/jenkins:lts
  • -d: Run the container in the background.
  • -p <YOUR_LOCAL_PORT>:8080: Map port 8080 of the Jenkins container to a specified port on the host.
  • -v jenkins-data:/var/jenkins_home: Mount the created Jenkins data volume to the Jenkins data directory in the container.
  • --name jenkins: Specify a name for the container.
    insert image description here
  1. Initialize Jenkins : After the container starts, visit http://localhost:<YOUR_LOCAL_PORT> (or replace it with the port number you configured) to enter the Jenkins initialization page.

  2. Get Jenkins Unlock Key : In the initialization page, you need to get the unlock key to continue the setup.

    • Obtain the unlock key with the following command:
      docker logs jenkins
      

insert image description here

  • Find the message "Jenkins initial setup is required" in the log output and copy the unlock key.
  1. Complete Jenkins setup : In the initialization page, paste the unlock key, and follow the setup wizard to complete Jenkins initialization.
    insert image description here

  2. Install suggested plugins : After initialization, Jenkins will recommend installing some commonly used plugins. You can choose to install as suggested, or manually select the required plugins.

  3. Create an admin user : After the plugin is installed, create an admin user that you can use to log in to the Jenkins console.

  4. Completing the installation : With the installation and setup complete, you can now access the Jenkins console and start using it to build and manage projects.

Note that data in the Jenkins container will remain in the data volume even if the container is deleted. But if you want to upgrade the Jenkins version or make other configuration changes, you can re-create a new Jenkins container through the Docker command, and mount the previously created data volume to the new container to preserve the data and configuration.

That's it for the detailed steps to install Jenkins using Docker. But it’s just basic use. If you need other detailed configurations, you need to refer to the official website manual and other blogs! ! !

Guess you like

Origin blog.csdn.net/weixin_53742691/article/details/132116645