标签:docker

以下是与标签 “docker” 相关联的文章

docker 加速器配置方法

  • ubuntu
apt install docker docker-compose
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://srdqkbud.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
  • docker toolbox (win7)
docker-machine ssh default 
sudo sed -i "s|EXTRA_ARGS='|EXTRA_ARGS='--registry-mirror=https://srdqkbud.mirror.aliyuncs.com |g" /var/lib/boot2docker/profile 
exit 
docker-machine restart default
  • docker for windows (win10)
--registry-mirror=https://srdqkbud.mirror.aliyuncs.com

{
  "registry-mirrors": [
    "https://srdqkbud.mirror.aliyuncs.com"
  ],
  "insecure-registries": [],
  "debug": false
}

win10 安装或升级 docker 失败问题

  • 必须关闭 win10 的实时防毒功能!
  • 如果已经失败,无法安装,无法启动,可以运行的 PowerShell 脚本 remove-docker.ps1 删除。

    $ErrorActionPreference = "SilentlyContinue"
    
    kill -force -processname 'Docker for Windows', com.docker.db, com.docker.slirp, com.docker.proxy, com.docker.9pdb, moby-diag-dl, dockerd
    kill -force -processname com.docker.service
    
    try {
    pushd "C:\Program Files\Docker\Docker\Resources"
    ./MobyLinux.ps1 -Destroy
    popd
    } Catch {}
    
    $service = Get-WmiObject -Class Win32_Service -Filter "Name='com.docker.service'"
    if ($service) { $service.StopService() }
    if ($service) { $service.Delete() }
    Start-Sleep -s 5
    Remove-Item -Recurse -Force "~/AppData/Local/Docker"
    Remove-Item -Recurse -Force "~/AppData/Roaming/Docker"
    if (Test-Path "C:\ProgramData\Docker") { takeown.exe /F "C:\ProgramData\Docker" /R /A /D Y }
    if (Test-Path "C:\ProgramData\Docker") { icacls "C:\ProgramData\Docker" /T /C /grant Administrators:F }
    Remove-Item -Recurse -Force "C:\ProgramData\Docker"
    Remove-Item -Recurse -Force "C:\Program Files\Docker"
    Remove-Item -Recurse -Force "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Docker"
    Remove-Item -Force "C:\Users\Public\Desktop\Docker for Windows.lnk"
    Remove-Item -Recurse -Force "~.docker"
    Remove-Item -Recurse -Force "~\DockerSwarm"
    Get-ChildItem HKLM:\software\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.PSPath} | Where-Object { $_.DisplayName -eq "Docker" } | Remove-Item -Recurse -Force
    Get-ChildItem HKLM:\software\classes\installer\products | ForEach-Object {Get-ItemProperty $_.pspath} | Where-Object { $_.ProductName -eq "Docker" } | Remove-Item -Recurse -Force
    Get-Item 'HKLM:\software\Docker Inc.' | Remove-Item -Recurse -Force
    
    Get-ItemProperty HKCU:\software\microsoft\windows\currentversion\Run -name "Docker for Windows" | Remove-Item -Recurse -Force
    Get-ItemProperty HKCU:\software\microsoft\windows\currentversion\UFH\SHC | ForEach-Object {Get-ItemProperty $_.PSPath} | Where-Object { $_.ToString().Contains("Docker for Windows.exe") } | Remove-Item -Recurse -Force
    
    Get-Item Env:\COMPOSE_CONVERT_WINDOWS_PATHS | Remove-Item
    Get-Item Env:\DOCKER_* | Remove-Item # DOCKER_CERT_PATH, DOCKER_HOST, DOCKER_MACHINE_NAME, DOCKER_TLS_VERIFY
    

32 位 win7 下用 docker 搭建 gitlab 服务器

安装 vmware

  • 32 位 windows 没有 docker 安装版本,只能先安装 vmware,然后在 vmware 里安装 ubuntu 和 docker。
  • 安装 vmware 10.0.4 32 位版本
  • 新建虚拟机,安装 ubuntu-server-16.04,注意不要选择立即安装,否则会进入自动安装模式,最后卡死在 vmware-tools 安装界面。
  • 设置 vmware 网络为桥接模式,

安装 ubuntu 虚拟机

  • 修改 ubuntu 源为 http://mirrors.163.com/
  • 修改 root 密码

    su
    passwd
    
  • 设置 vmware 网络为桥接模式
  • 设置静态 IP
    • ifconfig 查看网卡名称
    • 新建网卡配置 /etc/network/interfaces.d/ens33

      auto ens33
      iface ens33 inet static
      address 192.168.1.108
      netmask 255.255.255.0
      gateway 192.168.1.1
      dns-nameservers 192.168.1.1
      
    • 重启网卡 /etc/init.d/network restar
  • 安装 open-sshd ,修改 /etc/ssh/sshd_config

    Port 2222
    PermitRootLogin yes
    
  • 安装 docker,新建 /etc/docker/daemon.json

    {
      "registry-mirrors": [
        "https://changeme.mirror.aliyuncs.com"
      ],
      "insecure-registries": [],
      "debug": false
    }   
    
    service docker restart
  • 安装并配置 samba,参考链接

docker 配置

  • 新建目录 /home/share/gitlab/volume/ config log data
  • 新建文件 /home/share/gitlab/docker-compose.yml

    version: '2'
    services:
        gitlab:
          # image: 'twang2218/gitlab-ce-zh:10.0'
          image: 'gitlab/gitlab-ce:latest'
          restart: unless-stopped
          hostname: 'gitlab'
          environment:
            TZ: 'Asia/Shanghai'
            GITLAB_OMNIBUS_CONFIG: |
              external_url 'http://192.168.1.108'
              gitlab_rails['time_zone'] = 'Asia/Shanghai'
              gitlab_rails['smtp_enable'] = true
              gitlab_rails['smtp_address'] = "smtp.163.com"
              gitlab_rails['smtp_port'] = 25
              gitlab_rails['smtp_user_name'] = "MyEmail@163.com"
              gitlab_rails['smtp_password'] = "MyPassword"
              gitlab_rails['smtp_domain'] = "163.com"
              gitlab_rails['smtp_authentication'] = "login"
              gitlab_rails['smtp_enable_starttls_auto'] = true
              gitlab_rails['gitlab_email_from'] = 'MyEmail@163.com'
              user["git_user_email"] = "MyEmail@163.com"
          ports:
            - '80:80'
            - '443:443'
            - '22:22'
          volumes:
            - /home/share/gitlab/volume/config:/etc/gitlab
            - /home/share/gitlab/volume/log:/var/log/gitlab
            - /home/share/gitlab/volume/data:/var/opt/gitlab
          privileged: true
    

    注意上面的 smtp 密码为 163 授权码,不是登陆密码

  • docker 命令

    docker-compose up -d #创建
    docker-compose down #删除
    docker-compose pull #升级
    
    docker-compose start
    docker-compose stop
    

软件备份

gitlab 备份

  • 新建文件 /home/share/gitlab/backup.sh

    #!/bin/sh
    docker exec -it gitlab_gitlab_1 gitlab-rake gitlab:backup:create
    mv /home/share/gitlab/volume/data/backups/* /home/share/gitlab/backup
    chmod -R 777 /home/share/gitlab/backup/*
    
  • crontab -e

    0 3 * * * /home/share/gitlab/backup.sh
    

将备份复制到 windows

  • 在 windows 下新建网络映射目录 V: -> /home/share/
  • 新建批处理文件 gitlab-backup.bat注意网络路径不能写成盘符

    move \\192.168.1.108\share\gitlab\backup\* E:\gitlab-repo-bak\
    
  • 新建 windows 定时任务,4 点钟执行 gitlab-backup.bat

gitlab 数据恢复

  • 把还原数据复制到 /home/share/gitlab/volume/data/backups/
# 停止相关数据连接服务
docker exec -it gitlab_gitlab_1 gitlab-ctl stop unicorn
docker exec -it gitlab_gitlab_1 gitlab-ctl stop sidekiq

# 从 1393513186 编号备份中恢复
docker exec -it gitlab_gitlab_1 gitlab-rake gitlab:backup:restore BACKUP=1393513186

# 启动 Gitlab
docker exec -it gitlab_gitlab_1 gitlab-ctl start

docker compose 实例

配置文件

  • ./docker-compose.yml

    version: '3.1'
    
    services:
    
      mysql:
        #image: mysql:5.7.20
        build: ./builds/mysql-5.7.20
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: myPassword
        ports:
          - 3306:3306
        volumes:
          - //c/Users/fj/spidercloud/mysqlcfg:/etc/mysql/conf.d/source
          - //c/Users/fj/spidercloud/mysql:/var/lib/mysql
    
      redis:
        image: redis:4.0.6
        restart: always
        ports:
          - 6379:6379
        volumes:
          - //c/Users/fj/spidercloud/redis:/data
    
      mongo:
        image: mongo:3.6.0
        restart: always
        ports:
          - 27017:27017
        volumes:
          - //c/Users/fj/spidercloud/mongo/configdb:/data/configdb
          - mongodata:/data/db
    
    volumes:
      mongodata:
        external: true
    
  • ./builds/mysql-5.7.20/Dockerfile

    # Base image
    FROM mysql:5.7.20
    
    # Copy starting scripts file
    COPY start.sh /root/start.sh
    
    # Run necessary services
    CMD ["/bin/bash", "/root/start.sh"]
    
  • ./builds/mysql-5.7.20/start.sh

    #!/bin/sh
    
    cp /etc/mysql/conf.d/source/* /etc/mysql/conf.d/
    
    /entrypoint.sh mysqld
    

配置说明

  • volume 映射路径

    win7 dockertools 创建的虚拟机,默认共享了 C:/Users 目录。所有映射目录都必须在此目录下。

  • - //c/Users/fj/spidercloud/mysqlcfg:/etc/mysql/conf.d/source

    直接启动 mysql 官方镜像,不会映射配置目录,需要手工添加。该目录下配置会覆盖默认配置

  • build: ./builds/mysql-5.7.20

    如果直接将配置文件映射到 mysql 配置目录下,因为文件权限是所有人都可访问, mysql 认为不安全,会忽略此配置文件。所以在官方 mysql 镜像基础上定制,先复制配置到 source 目录下,启动时,再将配置文件复制到 mysql 配置目录下。

  • - mongodata:/data/db

    mongodb 的数据目录需要权限设置,而 windows 目录不支持此操作,所以直接映射 volume 的方法在 windows 下无法启动。需要先创建一个 volume。

    docker volume create mongodata

    然后将此 volume 映射到 mongo 容器中。该 volume 是在 linux 虚拟机中创建的,所以有权限设置。