Docker - 学习/实践

41 篇文章 4 订阅
20 篇文章 1 订阅

1. 应用场景

利用容器化技术, 搭建开发/测试/生产环境, 以及微服务, 分布式架构.

2. 学习/操作

1.文档

Empowering App Development for Developers | Docker  //docker官网

http://www.dockerinfo.net/document  //中文文档

DaoCloud | Docker 极速下载  //国内docker资源 --- 优质网站 -- 里面有很多常见教程 -- 非常推荐

https://blog.csdn.net/Allan_shore_ma/article/details/86134053  //Docker CI: docker 中启动所有容器命令

华为开源镜像站_软件开发服务_华为云  //华为镜像

阿里镜像 -- 需要登陆, 进入控制台中, 找到容器加速器 -- 复制仓库地址

docker 从入门到自动化构建 PHP 环境

https://blog.zhenglin.work/docker/save_load_images.html  //可用

https://blog.csdn.net/LUCKWXF/article/details/97619702 //docker镜像文件导入与导出,支持批量

Install WSL | Microsoft Docs  // Windows Subsystem for Linux Installation Guide for Windows 10

Docker CI: docker 中启动所有容器命令_Allan_shore_ma的博客-CSDN博客

Docker 教程 | 菜鸟教程  // Docker 教程 -- 其中有涉及docker安装很多其他软件服务 -- 可参考,实践

docker搭建php+nginx+swoole+mysql+redis环境 // docker搭建php+nginx+swoole+mysql+redis环境 

-- 20210424 周六 公寓

前言 - Docker —— 从入门到实践  // 推荐阅读 该Docker文档 20210430 周五 公寓

Docker 命令图  -- 20210424 周六 公寓

2.整理输出

1. 安装

Window 下安装,具体过程省略

docker-ce镜像-docker-ce下载地址-docker-ce安装教程-阿里巴巴开源镜像站  // Docker CE 镜像

http://www.dockerinfo.net/docker安装-centos

MacOX 安装

补充:// 20210406 周二 科学馆

mac pro安装docker

Docker Hub  // download page

下载完毕, 直接点击, 出现如下界面, 拖拽进Applicatinos即可

安装完成, 启动台内搜索 docker,点击, 出现如下界面, 点击ok,输入密码, 然后docke开始去安装一些组件

稍等片刻, 即安装成功~~

补充 // 2020622 周二 公司

Limux安装

服务器centOS上安装Docker

GitHub - docker/for-linux: Docker for Linux

Docker Hub

Docker Hub  // 这里的阿里云服务器Linux系统为CentOS 8.x

Install Docker Engine on CentOS | Docker Documentation // 官方文档

这里使用第一种方式也是官方推荐的方式安装

过程简要截图:

1. Set up the repository

$ sudo yum install -y yum-utils


$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

2. Install Docker Engine // 这里是安装最新镜像

 $ sudo yum install docker-ce docker-ce-cli containerd.io

3. Start Docker. // 启动docker,同时查看版本

4. Verify that Docker Engine is installed correctly by running the hello-world image.

通过运行hello-world镜像去验证Docker安装是否正确

 $ sudo docker run hello-world

正常输出,说明安装正确!!

同时看到添加docker用户组

Post-installation steps for Linux | Docker Documentation // 配置docker相关工作 -- 推荐

Run the Docker daemon as a non-root user (Rootless mode) | Docker Documentation // 非root模式运行Docker  -- 推荐 - 这里尚未开始操作 - 后续实践补充

5. 配置docker开机启动

 sudo systemctl enable docker.service
 sudo systemctl enable containerd.service

关闭开机启动

 sudo systemctl disable docker.service
 sudo systemctl disable containerd.service

关于Ubuntu安装docker

参考: Install Docker Engine on Ubuntu | Docker Documentation // 这里华为云使用的ubuntu 18.04 TLS

这里使用的 Install using the repository 方式

步骤

Set up the repository

1. Update the apt package index and install packages to allow apt to use a repository over HTTPS:

更新apt包索引并安装包,以允许apt通过HTTPS使用存储库:

 sudo apt-get update


 sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

2. Add Docker’s official GPG key:

添加Docker的官方GPG密钥:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

3. Use the following command to set up the stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below. Learn about nightly and test channels.

使用以下命令设置稳定的存储库。要添加夜间存储库或测试存储库,请在下面的命令中在单词stable之后添加单词nightly或test(或两者都添加)。了解夜间频道和测试频道。

Install Docker Engine

4. Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

更新apt包索引,安装Docker Engine和containerd的最新版本,或者执行下一步安装特定版本:

 sudo apt-get update


 sudo apt-get install docker-ce docker-ce-cli containerd.io

5. Verify that Docker Engine is installed correctly by running the hello-world image.

通过运行hello-world映像,验证Docker引擎已正确安装。

sudo docker run hello-world

同时查看docker版本

docker --version

设置开机启动

systemctl enable docker.service
systemctl enable containerd.service

关闭开机启动

 systemctl disable docker.service
 systemctl disable containerd.service

Ubuntu关于卸载

Install Docker Engine on Ubuntu | Docker Documentation

关于升级docker【Upgrade Docker Engine】

To upgrade Docker Engine, first run sudo apt-get update, then follow the installation instructions, choosing the new version you want to install.

2. 国内配置镜像

Docker Hub 公有镜像在国内拉取加速配置-阿里云开发者社区 

Docker国内仓库以及镜像加速配置_mumucgq的博客-CSDN博客

阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台  // 镜像加速器

windows:

针对安装了Docker for Windows的用户,您可以参考以下配置步骤:

在系统右下角托盘图标内右键菜单选择 Settings,打开配置窗口后左侧导航菜单选择 Docker Daemon。编辑窗口内的JSON串,填写下方加速器地址:

{
  "registry-mirrors": ["https://4hxxxmx.mirror.aliyuncs.com"]
}

编辑完成后点击 Apply 保存按钮,等待Docker重启并应用配置的镜像加速器。

本地配置如下:

点击Apply & Restart 即可

实践 // 可以看到很快就拉取完毕~~~

image如下:

正常~~~

3.关于Windows 10下, 虚拟引擎[WSL/Hypre-V]

插入: //20200927 周日 科学馆

公司电脑

由上看来, 系统升级之后, 已经支持 docker使用WSL 2支持虚拟化

详细文档见:  Redirecting…

公司电脑目前使用的是Hyper-V虚拟引擎, 同时WSL2也是支持的, 这里没有切换, 是因为Hyper-V虚拟引擎下, 有之前开发搭建的项目镜像, 容器环境, 一旦切换虚拟引擎, 就需要重新部署项目开发环境, 暂时不想折腾.

家里电脑  // 20201215 周二

解决办法:

一: Install WSL | Microsoft Docs

二: 使用Hyper-V虚拟引擎, 但是记住:WSL 2 provides better performance than the legacy Hyper-V backend。// 即 WSL 2 的性能更好

 
如果Windows系统WSL 2由于各种原因不支持,可以先切换使用 Hyper-v的虚拟化, 但是如果两个都不支持,就没法使用docker了。

windows 10 家庭版等版本是不支持Hyper-v的。

方式解决结果:

1.下载【https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi】,双击安装。

2.重启docker for windows

正常启动~~~

方式二解决结果:

1.修改虚拟化引擎, 即将勾选去掉, 点击Apply & Restart

亦正常解决~~~

Note:

1.还是推荐使用方式一, 性能更好。比如:启动速度更快~~~

2.docker切换虚拟引擎 [Hyper-V / WSL2], 本地镜像,容器不会共享, 即可能会导致之前开发搭建的项目镜像, 容器环境消失, 需要重新部署项目开发环境, 暂时不想折腾.

但是仍然可以切换回来, 继续使用原来虚拟引擎下的本地镜像与容器实例, 开发或者测试, 生产环境[应该很少人会选择做].


 

后续补充

...

3. 问题/补充

1. window10 如何 docker 中启动所有容器命令

打开git bash

输入命令: docker start $(docker ps -a | awk '{ print $1}' | tail -n +2)

补充:

docker中    关闭所有的容器命令
# docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2)

docker中 删除所有的容器命令
# docker rm $(docker ps -a | awk '{ print $1}' | tail -n +2)

docker中    删除所有的镜像
# docker rmi $(docker images | awk '{print $3}' |tail -n +2)

2. 批量导出镜像文件

批量导入到一个压缩包

#!/bin/bash
IMAGES_LIST=($(docker  images   | sed  '1d' | awk  '{print $1":"$2}'))
docker save ${IMAGES_LIST[*]}  -o  all-images.tar.gz

Windows下: 在git bash中执行

可知: okay~

单独导出镜像:

批量导入:

TBD

单独导入:

docker load --input ./nginx.tar

3. 登陆到docker hub // 20210406 周二 科学馆

这里开始注册docker hub,登陆,可以将相应的image镜像文件push/pull到不同主机,从而方便地使用, 但是免费版空间有限~~

同一个账号:

windows:

mac:

4. 参考

Empowering App Development for Developers | Docker  //docker官网

http://www.dockerinfo.net/document  //中文文档

DaoCloud | Docker 极速下载  // 国内docker资源

https://blog.csdn.net/Allan_shore_ma/article/details/86134053  //Docker CI: docker 中启动所有容器命令

华为开源镜像站_软件开发服务_华为云  //华为镜像

阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 //阿里镜像

http://www.baidu.com/link?url=dhyfiHbzQ_pDtmM9K3KDv1DOZkiy70PRQmDc0mCI_WfB3kGDzmgYKvQI6jZ0YdU_&wd=&eqid=8576137d0006f302000000065e5f7a89  //docker 从入门到自动化构建 PHP 环境

https://blog.zhenglin.work/docker/save_load_images.html  //可用

https://blog.csdn.net/LUCKWXF/article/details/97619702 //docker镜像文件导入与导出,支持批量

Install WSL | Microsoft Docs  // Windows Subsystem for Linux Installation Guide for Windows 10

docker搭建php+nginx+swoole+mysql+redis环境 // docker搭建php+nginx+swoole+mysql+redis环境  -- 20210424 周六 公寓

后续补充

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值