docker-compose使用

📅 2026/7/21 23:32:44
docker-compose使用
介绍docker-compose的作用不用挨个手动跑多个容器写个配置文件就能一条命令统一启动、管理一整套关联服务。安装# 上传二进制程序到/usr/local/bin下面[rootlocalhost /opt/jenkins]# ls /usr/local/bin/docker-compose[rootlocalhost /opt/jenkins]## 给二进制文件执行权限[rootlocalhost /opt/jenkins]# chmod x /usr/local/bin/docker-compose[rootlocalhost /opt/jenkins]# ls /usr/local/bin/docker-compose[rootlocalhost /opt/jenkins]#docker-compose创建gitlab容器1.0 创建文件夹和文件# 创建文件夹mkdir/opt/gitlabcd/opt/gitlab# 创建文件touchdocker-compose.yml2.0 编写docker-compose.yml文件#vim docker-compose.yml # 注意我们的ip地址需要进行修改为我们自己本地上面的ip地址version:3.7services: gitlab: image:gitlab/gitlab-ce:14.1.0-ce.0container_name: gitlab restart: always ports: -8085:80-8443:443environment: GITLAB_OMNIBUS_CONFIG:|external_urlhttp://192.168.255.165gitlab_rails[time_zone]Asia/Shanghaipuma[worker_processes]2sidekiq[max_concurrency]8postgresql[shared_buffers]128MBpostgresql[max_worker_processes]4prometheus_monitoring[enable]falsevolumes: -/opt/gitlab/etc:/etc/gitlab-/opt/gitlab/log:/var/log/gitlab-/opt/gitlab/data:/var/opt/gitlab3.0 通过docker-compose up -d 启动容器#启动docker-composeup-d#进入容器dockerexec-itgitlabbash#重新初始化并重启gitlab-ctl reconfigure gitlab-ctl restart# 注意 通过docker-compose起启动镜像的时候速度肯能会比较慢我们可以先手动拉取镜像dockerpull gitlab/gitlab-ce:14.1.0-ce.0