Docker入门1
文章目录
关键词
镜像(Image)
Docker 镜像(Image),就相当于是一个 root 文件系统。
容器(Container)
镜像(Image)和容器(Container)的关系,就像是面向对象程序设计中的类和实例一样,镜像是静态的定义,容器是镜像运行时的实体。容器可以被创建、启动、停止、删除、暂停等
仓库(Repository)
仓库可看成一个代码控制中心,用来保存镜像。
安装
环境 : deepin 操作系统
安装相应的依赖
# 更新镜像源
$ sudo apt-get update
# 安装相关依赖
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
添加密钥
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
验证
sudo apt-key fingerprint 0EBFCD88
修改稳定版仓库
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
阿里镜像源
sudo add-apt-repository、
"deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu\
$(lsb_release -cs) stable"
安装 Docker Engine-Community
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
# 查看不同的版本信息
$ apt-cache madison docker-ce
# 安装 前后 version 相互对应
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
# 如下
$ sudo apt-get install docker-ce=5:18.09.0\~3-0\~debian-stretch docker-ce-cli=5:18.09.0\~3-0\~debian-stretch containerd.io
- 启动服务:
systemctl start docker
- 开机自启:
systemctl enable docker
- 测试:
docker run hello-world
先拉取 后运行
命令
安装ubuntu
-
拉取 ubuntu 镜像 :
docker pull ubuntu | docker pull ubuntu:latest
-
运行容器:
docker run ubuntu -it /bin/bash
-
查看镜像:
docker images
-
查看运行的容器:
docker ps [-a]
-
停止运行容器:
docker stop <id|name>
-
查看容器:
docker container ls -a
-
启动容器:
docker run <id|name>
-
删除容器(先停止):
docker rm <id|name>
docker 命令权限问题
# 创建docker用户组
sudo groupadd docker
# 将用户添加到 docker 组中
sudo gpasswd -a $USER docker
# 切换当前会话到新 group 或者重启 X 会话
newgrp docker
参考内容
https://www.runoob.com/docker/docker-tutorial.html ↩︎