Docker安装及基本使用

一、安装Docker(ubuntu)

卸载旧版本(可选)

sudo apt-get remove docker docker-engine docker.io containerd runc

添加Docker的官方GPG密钥

curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

设置仓库

sudo add-apt-repository \

"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \

$(lsb_release -cs) \

stable"

安装Docker

列出Docker可用版本

apt-cache madison docker-ce

安装Docker最新版

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

测试Docker

sudo docker run hello-world

image-20230225182817517

二、基本使用

1、列出镜像

sudo docker images

  • REPOSITORY:表示镜像的仓库源
  • TAG:镜像的标签
  • IMAGE ID:镜像ID
  • CREATED:镜像创建时间
  • SIZE:镜像大小

2、获取镜像

sudo docker pull ubuntu:13.10

3、查找镜像

sudo docker search httpd

4、拉取镜像

sudo docker pull httpdUsing default tag:lastest

5、运行镜像

sudo docker run httpd

指定参数运行

sudo docker run -it ubuntu /bin/bash

  • -i: 交互式操作。
  • -t: 终端。
  • ubuntu: ubuntu 镜像。
  • /bin/bash:放在镜像名后的是命令,这里我们希望有个交互式 Shell,因此用的是 /bin/bash。

退出终端

exit()

6、删除镜像

sudo docker rmi hello-world

7、查看所有容器

sudo docker ps -a

8、启动已停止的容器

sudo docker start 容器ID

  • start 启动
  • stop 停止
  • restart 重启

9、进入容器

使用-d 参数后,容器进入后台运行

sudo docker exec 容器ID

attach也能进入,但是退出后会停止容器。

10、删除容器

sudo docker rm -f 容器ID

posted @ 2023-02-25 19:42  kinber  阅读(24)  评论(0编辑  收藏  举报