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

发布时间:2022-07-05 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了打造属于自己的Docker镜像(1)--基础镜像制作脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

下载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 wangt.cc /ohmyzsh/ohmyzsh/master/tools/install.sh)"

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

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

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

git clone https://gitee wangt.cc /leel0330/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://gitee wangt.cc /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 wangt.cc /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然后我们的插件就生效了。比如效果如下:

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

安装Vim和插件

apt install vim

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

curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent wangt.cc /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比较多,后面会一一介绍如何打造这三种语言开发的镜像。希望各位多多捧场~

脚本宝典总结

以上是脚本宝典为你收集整理的打造属于自己的Docker镜像(1)--基础镜像制作全部内容,希望文章能够帮你解决打造属于自己的Docker镜像(1)--基础镜像制作所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。