怎么用docker-compose安装,创建一个docker-jenkins-compose.yml文件
时间: 2024-06-06 20:07:43 浏览: 238
1. 首先,需要安装Docker和Docker Compose。可以通过以下命令来安装:
- Docker:curl -sSL https://get.docker.com/ | sh
- Docker Compose:sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose
2. 创建一个名为docker-jenkins-compose.yml的文件,可以使用命令行或编辑器来创建。在该文件中,我们定义了两个服务:Jenkins和Nginx。
version: '3'
services:
jenkins:
image: jenkins/jenkins:lts
ports:
- "8080:8080"
- "50000:50000"
volumes:
- jenkins_home:/var/jenkins_home
networks:
- jenkins_network
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
networks:
- jenkins_network
volumes:
jenkins_home:
networks:
jenkins_network:
3. 在同一目录下,创建一个名为nginx.conf的文件,并将以下内容复制到其中:
worker_processes 1;
events { worker_connections 1024; }
http {
sendfile on;
upstream jenkins {
server jenkins:8080;
}
server {
listen 80;
location / {
proxy_pass http://jenkins;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
4. 使用以下命令来启动Docker Compose:
docker-compose up -d
5. 等待一段时间后,可以通过访问http://localhost来访问Jenkins。Nginx将代理请求到Jenkins服务。
阅读全文