编辑 vi /etc/netplan/50-cloud-init.yaml
配置文件,修改内容如下
network:
version: 2
ethernets:
ens33:
dhcp4: no
dhcp6: no
addresses: [192.168.137.254/24]
gateway4: 192.168.137.1
nameservers:
addresses: [114.114.114.114, 8.8.8.8]
使用 netplan apply
命令让配置生效
# 取消 DNS 行注释,并增加 DNS 配置如:114.114.114.114,8.8.8.8修改后重启下计算机
vi /etc/systemd/resolved.conf
修改 cloud.cfg 防止重启后主机名还原
vi /etc/cloud/cloud.cfg
# 该配置默认为 false,修改为 true 即可
preserve_hostname: true
修改主机名
# 修改主机名
hostnamectl set-hostname gitlab
# 配置 hosts
vim /etc/hosts
192.168.137.254 gitlab
apt-get remove docker docker-engine docker.io containerd runc
# 更新数据源
apt-get update
# 安装所需依赖
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# 安装 GPG 证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 新增数据源
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# 更新并安装 Docker CE
apt-get update && apt-get install -y docker-ce
docker version
# 输出如下
Client:
Version: 18.09.6
API version: 1.39
Go version: go1.10.8
Git commit: 481bc77
Built: Sat May 4 02:35:57 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.6
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 481bc77
Built: Sat May 4 01:59:36 2019
OS/Arch: linux/amd64
Experimental: false
点击链接获取
https://registry.docker-cn.com
以配置阿里云加速器为例,首先 登录阿里云(没有账号请先注册),搜索 容器镜像服务
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oleVVfQ4-1585139763280)(https://note.youdao.com/yws/api/personal/file/4C4EDBE702074F94BAFDB9BA29482995?method=download&shareKey=81f8499b02d92c576bbb9df92775f01d)]
找到你的专属加速器
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9i3qDKSs-1585139763282)(https://note.youdao.com/yws/api/personal/file/AF69FB53093D45A499932FE8E485DFCB?method=download&shareKey=52a774a82a3e0c3876b798c5355a8958)]
通过修改 daemon 配置文件 /etc/docker/daemon.json
来使用加速器
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://xxxxxxxx.mirror.aliyuncs.com"]
}
# 重启 Docker
systemctl daemon-reload
systemctl restart docker
docker info
``
# 输出如下
Containers: 38
Running: 18
Paused: 0
Stopped: 20
Images: 10
Server Version: 18.09.6
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.15.0-51-generic
Operating System: Ubuntu 18.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.924GiB
Name: kubernetes-master
ID: PJ4H:7AF2:P5UT:6FMR:W4DI:SSWR:IQQR:J6QO:ARES:BOAC:ZVMO:SV2Y
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
## 这里是你配置的镜像加速器
Registry Mirrors:
https://xxxxxxxx.mirror.aliyuncs.com/
Live Restore Enabled: false
Product License: Community Engine
``
WARNING: No swap limit support
Compose 支持 Linux、macOS、Windows 10 三大平台。在 Linux 上的也安装十分简单,从 官方 GitHub Release 处直接下载编译好的二进制文件即可。
curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version
# 输出如下
docker-compose version 1.24.0, build 0aa59064
docker-py version: 3.7.2
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.1.0j 20 Nov 2018
docker search gitlab
gitlab/gitlab-ce GitLab Community Edition docker image based … 2816 [OK]
sameersbn/gitlab Dockerized gitlab web server 1149 [OK]
gitlab/gitlab-runner GitLab CI Multi Runner used to fetch and run… 593 [OK]
twang2218/gitlab-ce-zh 汉化的 GitLab 社区版 Docker Image 211
选择安装汉化版的twang2218/gitlab-ce-zh
docker pull twang2218/gitlab-ce-zh
mkdir -p /usr/local/docker/gitlab
cd /usr/local/docker/gitlab
touch docker-compose.yml
vi docker-compose.yml
version: '2'
services:
gitlab:
image: 'twang2218/gitlab-ce-zh'
container_name: "gitlab"
restart: unless-stopped
privileged: true
hostname: 'gitlab'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://192.168.137.101'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.aliyun.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "xxxxx"
gitlab_rails['smtp_domain'] = "aliyun.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'
gitlab_rails['gitlab_shell_ssh_port'] = 220
ports:
- '8080:80'
- '443:443'
- '220:22'
volumes:
- ./config:/etc/gitlab
- ./data:/var/opt/gitlab
- ./logs:/var/log/gitlab
docker-compose up -d
docker-compose stop
停止容器
docker-compose start
启动容器
docker-compose logs
查看容器日志
docker-compose logs -f
查看容器实时日志
docker-compose down
停止后删除容器
http://192.168.137.101:8080