热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

jenkinssh构建运行shell脚本docker:commandnotfound

ThesimplewaytorunDocker-in-DockerforCI:https:tutorials.releaseworksacademy.comlearnthe-sim

The simple way to run Docker-in-Docker for CI:https://tutorials.releaseworksacademy.com/learn/the-simple-way-to-run-docker-in-docker-for-ci

https://***.com/questions/44850565/docker-not-found-when-building-docker-image-using-docker-jenkins-container-pipel

需要将宿主机的docker环境变量映射

-v /var/run/docker.sock:/var/run/docker.sock \

参数多了使用docker-compose

curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

docker-compose -v

cd /home
vi docker-compose.yml
version: '3'
services:
  jeknins:
    container_name:  'jenkins_pen'
    image:  jenkins/jenkins:lts
    restart: always
    user:  root
    ports:
    - "11005:8080"
    - "5000:5000"
    volumes:
    - /home/jenkins/data:/var/jenkins_home
    - /usr/bin/docker:/usr/bin/docker
    - /var/run/docker.sock:/var/run/docker.sock
//若docker-compose.yml  user 权限不够会有报错
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied

https://www.cnblogs.com/Uni-Hoang/p/12901055.html

https://www.cnblogs.com/Uni-Hoang/p/12901055.html

 

若使用docker-compose.yml也要注意

jenkins sh构建运行shell脚本 docker: command not found

 

 

 sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

//执行docker-compose.yml配置文件
# 删除上次构建的容器
docker-compose down
# 重新构建镜像 --force-rm 删除构建过程中的临时容器。
docker-compose build --force-rm
# 运行容器
docker-compose up -d
# docker-compose.yml
version: "3"
services: # 服务
    node: # node 服务
        build: . # Dockerfile 的目录,用于构建镜像
        container_name: node-server-1 # 容器名称
        ports: # 暴露的端口
            - "3000:3000"
        restart: always # 自动重启
        environment: 
            - NODE_ENV=production
        networks: # 加入网络
            - "my-network"
        command: npm run start # 覆盖容器启动后默认执行的命令 dockerfile定义了workdir
    nginx:
        image: nginx:latest 指定 nginx 镜像
        ports: # 将本机的 8080 端口映射到容器的80端口
            - "8080:80"            
        container_name: nginx-node
        restart: always
        volumes: # 映射本机 F:/nginx.conf 文件到 容器的 /etc/nginx/nginx.conf:ro 文件
            - "F:/nginx.conf:/etc/nginx/nginx.conf:ro"
        networks: 
            - "my-network"
        links: # 设置 node 服务别名,其实是设置/etc/hosts的域名解析
            - "node"
        depends_on: # 指定依赖于哪个服务
            - node
networks: # 网络
    my-network: # 网络名称
        driver: bridge

 

2.docker容器的内数据备份

//docker cp
docker cp  containerId:/var/jenkins_home  /home/jenkins/data

#1.从宿主机向容器中复制文件

https://blog.csdn.net/u010046887/article/details/90408622?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase

[root@localhost data]# sudo docker cp aa.txt ssh001:/data

把当前目录下的aa.txt复制到容器名称为【ssh001】的data目录下

//官方备份volumes
https://docs.docker.com/storage/volumes/#backup-restore-or-migrate-data-volumes

docker run --rm --volumes-from jenkins_pen -v /temp/backup:/backup ubuntu tar cvf /backup/backup.tar /var/jenkins_home

 


推荐阅读
author-avatar
大爱与你_邂逅
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有