惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
小众软件
小众软件
The Register - Security
The Register - Security
量子位
博客园_首页
T
The Blog of Author Tim Ferriss
T
Threat Research - Cisco Blogs
G
Google Developers Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News and Events Feed by Topic
S
Security Affairs
O
OpenAI News
Google DeepMind News
Google DeepMind News
Webroot Blog
Webroot Blog
The Cloudflare Blog
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
Recent Commits to openclaw:main
Recent Commits to openclaw:main
V2EX - 技术
V2EX - 技术
S
Secure Thoughts
D
Docker
Cloudbric
Cloudbric
Vercel News
Vercel News
MongoDB | Blog
MongoDB | Blog
T
Troy Hunt's Blog
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
News and Events Feed by Topic
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Schneier on Security
Schneier on Security
Jina AI
Jina AI
Stack Overflow Blog
Stack Overflow Blog
T
Threatpost
D
DataBreaches.Net
Spread Privacy
Spread Privacy
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
V
Vulnerabilities – Threatpost
B
Blog RSS Feed
C
Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
F
Fortinet All Blogs
The Hacker News
The Hacker News
Know Your Adversary
Know Your Adversary

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN Mintty Tips and Configurations Generating Table of Contents for Markdown with Tagbar Convert Python Script to Exe on Windows with Pyinstaller Ubuntu on Windows Missing after Windows Update 使用代理加速 Mac 终端下载速度 My Experience with Several Zsh Plugin Managers 深圳租房小记 How to Install zplug inside Docker Container Why don't settings inside bashrc or bash_profile take effect? Setting Up Locale in Linux 谷歌 Adsense 申请及在 Hugo 中的配置 How to Write Algorithm Pseudo Code in LaTeX Nifty Nvim Techniques That Make My Life Easier -- Series 4 A Few Grammar Questions in Writing How to Read and Write Images with Unicode Paths in OpenCV Creating A Professional Table in LaTeX with booktabs How to Create Proper Folding for Vim/Nvim Configuration Linux Tips and Tricks -- s1 JPEG Image Orientation and Exif How Do I Show the Current File Path In Neovim? JPEG Image Quality in PIL Difference between view, reshape, transpose and permute in PyTorch Convert PIL or OpenCV Image to Bytes without Saving to Disk Fast Movement and Navigation Inside Vim or Neovim Unintuitive Behaviour of Case Sensitivity in Python glob Binding Keys in Zsh 几把机械键盘试用体验 Nvim Autocompletion with Deoplete Converting Markdown to Beautiful PDF with Pandoc Exclusive and Inclusive Motion in Neovim/Vim Nifty Nvim Techniques Which Make My Life Easier -- Series 3 Why Doesn't Jedi Autocompletion Work for Some Methods Vim-like Editing inside Browser Markdown 生成 HTML 时汉字之间出现多余空格问题 小米 9 安装谷歌商店(Google Play Store)与相关配置 Create Mappings That Take A Count in Neovim Spell Checking in Nvim English Words Completion inside Neovim/Vim How to Use Python Inside Vim Script with Neovim Nifty Little Nvim Techniques to Make My Life Easier -- Series 2 Setting up Ultisnips for Neovim Mac 上罗技 M590 鼠标设置 Nifty Little Nvim Techniques to Make My Life Easier -- Series 1 A Complete Guide on Writing LaTeX with Vimtex in Neovim Manipulating Images with Alpha Channels in Pillow Sublime Text Regular Expression Cheat Sheet Cropping Rotated Rectangles from Image with OpenCV Boosting Your Productivity on Terminal with Zsh and Plugins 最新版 Rime 输入法使用 (2022 更新) Display Image with Pillow inside Ubuntu on Windows Faster Directory Navigation with z.lua Cmder Advanced Configurations Nvim-qt Settings on Windows 10 Tmux Plugin Install and Management How to Debug Python Code in Terminal Markdown Writing and Previewing in Neovim -- A Complete Guide Line Number Settings for More Efficient Movement in Neovim 两个大规模中文语料库介绍以及处理 Windows 系统下几款程序员不可不用的神器 我的 2018 阅读清单 A Complete Guide to Neovim Configuration for Python Development How Is Newline Handled in Python and Various Editors? Two Issues Related to ImageFont Module in PIL 在 Listary 中调用 GoldenDict 或欧路词典查单词 Reading and Writing Text Files on Windows The Mathematics behind Font Shapes --- Bézier Curves and More 快速识别图片字体:字体识别工具介绍 Deoplete Failed to Load at Startup after Updating Python neovim Package What Is The Difference between pip, pip3 and pip3.6 Shipped with Anaconda3? Windows 10 系统下 Neovim 安装与配置
Docker 学习系列 --- 2
2020-05-02 · via jdhao's digital space

本文总结一些 Docker 使用以及 Docker 镜像构建过程中遇到的问题。

Unable to find xxx locally#

使用 docker run -it centos:7 命令,遇到提示:

Unable to find image ‘centos:7’ locally

可以等待一会,收到提示:

7: Pulling from library/centos
Digest: sha256:307835c385f656ec2e2fec602cf093224173c51119bbebd602c53c3653a3d6eb
Status: Downloaded newer image for centos:7

当使用 docker run 运行镜像的时候,如果镜像不存在,那么 docker 会从 docker hub 寻找对应的镜像,下载运行。出现这个错误提示可能是因为网络原因,耐心等待就可以了,参考这里

wget 命令未找到#

docker hub 上的 CentOS 镜像和普通的 CentOS 安装包有一定区别,执行的是最小安装,有很多常用的工具并没有安装,例如 wget, which 等,需要自己去安装。

Nvidia cuda 的 CentOS 系统镜像是基于 Docker hub 上 CentOS 7 的镜像,所以这些工具也没有安装,需要自己安装。

参考#

docker run -it 选项作用#

docker run 命令很常用的两个选项是 -it-i 作用是把 host 的 input 和容器的 input 连接起来,-t 创造一个 pseudo terminal,这两个命令连起来使用,就好像直接在 container 里面创建了 bash shell,可以接收输入和输出,就像用户使用 host 机器的 shell 一样。

参考#

如何从容器中拷贝东西到 host 机器#

参考 这里,可以使用 docker cp 命令:

docker cp CONTAINER_ID:/path/inside/docker/container /path/in/host/machine

Dockerfile 里面的 RUN 命令默认运行目录在哪里?#

Dockerfile 如果没有指定 WORKDIR,那么默认执行命令的目录是在 /,并不是 /root, 如果基础镜像指定了 work dir,那么 workdir 就是基础镜像指定的目录。因此在使用 Dockerfile 构建自己的镜像时,最好使用 WORKDIR 命令指定自己的工作目录,避免受到基础镜像的影响。

参考#

Dockerfile 如何设置变量以便后续使用#

使用 Dockerfile 构建镜像时,有时候我们需要设置一些变量,以便后续引用,节省时间。可以利用 ARG 命令设置变量,指的注意的是,ARG 命令设置变量,只在 build 的时候有效,ENV 设置的变量,镜像 build 完成,进入镜像以后,仍然是有效的。

参考#

COPY failed: Forbidden path outside the build context#

当我试图从当前 Dockerfile 所在目录的上一级目录拷贝某个文件到镜像的某个目录:

COPY ../some_file /path/inside/container

然后遇到了上述错误,原因是 docker 只允许从当前 Dockerfile 的build context下某个目录 copy 文件。

参考#

Dockerfile ARG 和 ENV 指令无法扩展某些变量或者符号#

Dockerfile 的 ARG 和 ENV 指令,无法 expand $HOME, ~,如果要使用路径,最好使用绝对路径。

例如,ctags 被安装在 /root/tools/ctags,如果用 ENV 定义 PATH 环境变量:

ENV PATH=$HOME/tools/ctags/bin:$PATH

然后在 Dockerfile 中运行下面的指令:

会提示错误,如果我们把 PATH 打印出来 RUN echo $PATH, 会发现 ctags 有关的一项目录是错的,显示的是 /tools/ctags/bin,也就是使用 ENV 指令定义 PATH 的时候,$HOME 是空的,并不会被 expand 为 /root。同样如果使用 ~

ENV PATH=~/tools/ctags/bin:$PATH

也不会被正确 expand 为 /root, 如果要运行 ctags 相关的指令也是不成功的。如果要设置环境变量,可以设置为绝对路径;如果觉得啰嗦,可以利用 ARG 自定义一个 HOME 变量:

然后在设置 ENV 变量的时候引用 HOME 变量就不会出错。

如何从某一个命令之后开始强制重新 build?#

Dockerfile 如果从开始到某一步在 build 的时候没有出错,并且没有增加或者删除 build 的步骤,那么下一次 build 镜像的时候,默认使用上一步 build 的缓存,不会重新 build,这样可以加快镜像构建的速度。如果想从某一步开始重新开始 build,可以在这一步之前加入一个没用的不耗时的命令,例如

重新构建的时候,新加入的命令及以后的所有步骤就会重新 build。

参考#

source 命令未找到#

当我试着用 RUN 指令运行 source 命令:

RUN source /root/.bash_profile

遇到了错误提示:

source: command not found

原因是什么呢,原来是 docker 默认用来执行命令的 shell 是 /bin/sh,并不是 bash,在 sh 下,source 命令并不存在,如果想要执行 source 命令。有两个办法,一个办法是使用 SHELL 指令,把使用的 shell 更改为 bash:

SHELL ["/bin/bash", "-c"]

另外一种办法是使用 exec 形式的 RUN 指令,仅仅在这个指令中使用 bash shell 而不是 sh:

RUN ["/bin/bash", "-c", "source /root/.bash_profile"]

参考#

登陆 container 以后 bash 不是 login shell#

运行容器以后,发现 /root/.bash_profile 没有生效,经过排查,发现原因是 bash 不是 login shell,可以设置 CMD 指令,把 bash 变为 login shell:

不要使用 docker commit 方式创建镜像#

启动 docker 镜像以后,如果在里面又进行了修改(例如安装了额外的工具或者进行了其他的配置), 那么使用 docker commit 会保存这些更改,生成新的镜像。但是这种方式生成的镜像,除了 作者,其他用户很难清楚到底进行了什么操作,安装了哪些东西,不利于后续的维护,因此更好的方式是使用 Dockerfile 管理镜像,把要安装的软件都放到 Dockerfile 里面配置。这样的话,其他用户也可以轻松使用你的 Dockerfile 构建出同样的 Docker 镜像。

参考#