ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

打造属于自己的Docker镜像(1)--基础镜像制作

2021-09-20 01:31:21  阅读:283  来源: 互联网

标签:插件 set -- vim git 镜像 Docker syntax zsh


下载Ubuntu基础镜像

docker pull ubuntu

默认下载的是latest版本的镜像(目前latest是20.04),如果要下载18.04或者16.04,请加上版本号信息,比如:

docker pull ubuntu:16.04

安装完镜像后我们需要创建容器并进入其中,安装必要的软件:

docker run -itd --name ubt-code-based ubuntu
docker exec -it ubt-code-based bash

安装软件前建议先执行一下apt update

我们这里以ubt-code-based这个容器名来进行说明。

安装zsh和oh-my-zsh

默认的ubuntu里有bash,能够满足非常基础的需求,但是如果想更高效的工作,建议使用zsh,同时安装上oh-my-zsh,能提升你的工作效率。

apt install zsh curl git
cd ~
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

安装完oh-my-zsh后,建议安装如下插件:

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions

如果由于网络原因访问不了这两个库,建议访问gitee的,这里也贴下命令:

git clone https://gitee.com/leel0330/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://gitee.com/leel0330/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions

这里说明下这几个库的作用:

插件名 作用
zsh-syntax-highlighting 高亮命令,错误的、找不到的命令会用红色标记,正确的一般是绿色
zsh-autosuggestions 缓存了敲过的命令,再次使用该命令时避免了重复复制,直接使用即可

zsh的配置文件是.zshrc。上面安装的插件需要配置下才能生效:

plugins=(git zsh-syntax-highlighting zsh-autosuggestions)

另外,我们需要追加配置以下内容:

# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
   OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
   zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}

pastefinish() {
   zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish

这里的配置是避免复制命令在控制台是一个个字符显示出来。

好了配置完后source .zshrc然后我们的插件就生效了。比如效果如下:

image

安装Vim和插件

apt install vim

vim的插件安装推荐使用插件管理器vim-plug。具体这里不详细介绍了,想了解更多请自Google之。

curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

在目录~创建.vimrc并添加如下内容:

" Plugins will be downloaded under the specified directory.
call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')
" Declare the list of plugins.
Plug 'crusoexia/vim-monokai'
" List ends here. Plugins become visible to Vim after this call.
call plug#end()

需要安装什么插件配置在两个call命令之间即可。可以看出这里我添加了一款monokai主题的插件。让我们加一些基础的配置吧:

" vim basic config
" 设置编码格式
set encoding=utf-8
" 显示行号
set number
" 关闭兼容模式
set nocompatible
" 设置右下角光标的行列信息
set ruler
" 当一行很长时取消换行
set nowrap
" 在状态栏显示输入的命令和模式
set showcmd
set showmode
" 突出显示当前行列
set cursorline
" 开启语法高亮
syntax enable
syntax on
" 设置Tab宽度
set tabstop=4
set shiftwidth=4
set softtabstop=4
" 设置输入Tab键为空格
set expandtab
" 关闭设置输入Tab键为空格
"set noexpandtab
" 显示括号匹配
set showmatch
" 显示tab键
"set list
"set listchars=tab:>-,trail:-
" 设置自动缩进
set autoindent
" 设置搜索相关配置
set hlsearch
set incsearch
set ignorecase
" 设置颜色
set t_Co=256
" 设置主题
colorscheme monokai

上面的配置同样是在.vimrc文件。完整的配置文件可以参考如下:

" Plugins will be downloaded under the specified directory.
call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')

" Declare the list of plugins.
Plug 'crusoexia/vim-monokai'

" List ends here. Plugins become visible to Vim after this call.
call plug#end()

" vim basic config
set encoding=utf-8
set number
set nocompatible
set ruler
set nowrap
set showcmd
set showmode
set cursorline
syntax enable
syntax on
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
"set noexpandtab
set showmatch
"set list
"set listchars=tab:>-,trail:-
set autoindent
set hlsearch
set incsearch
set ignorecase
set t_Co=256
colorscheme monokai

好了,我们的Ubuntu镜像就制作到这了,为了方便在此镜像基础上进行扩展,可以保存到我们的远程Docker Hub上(前提是你要有一个Docker账号并且已经登录上去):

docker commit ubt-code-based ubt-code-based
docker tag ubt-code-based leel0330/ubt-code-based
docker push leel0330/ubt-code-based

至此,我们的镜像就推送到了Docker Hub上,以后想使用的话直接Pull下来即可,不需要一直从ubuntu基础镜像开始构建起了,节省了大量时间。

这篇作为打造属于自己的Docker镜像系列的起始篇,因为本人使用Go、C++和Python比较多,后面会一一介绍如何打造这三种语言开发的镜像。希望各位多多捧场~

标签:插件,set,--,vim,git,镜像,Docker,syntax,zsh
来源: https://www.cnblogs.com/FSCoder/p/15313372.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有