docker安装与使用教程

发布时间 2023-06-15 09:34:49作者: Kevin0is0me

https://mp.weixin.qq.com/s?__biz=MjM5NTY1MjY0MQ==&mid=2650860524&idx=3&sn=02dfc31d637f70b066a6ef9842beeac5&chksm=bd017ea28a76f7b466773e68f7dab26e65ffae2918c28aa1d87c84acfc54460a7b82aa57279f&scene=27

 

 

官方的一键安装方式:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

启动Docker的命令:

sudo systemctl start docker

通过运行hello-world镜像来验证是否正确安装了Docker Engine-Community。

// 拉取镜像
sudo docker pull hello-world
// 执行hello-world
sudo docker run hello-world

如果执行之后,控制台显示如下信息,则说明Docker安装和启动成功:

[root@iZ8vb8pfb2awsz4qy7vm7qZ ~]# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.



Docker其他常见命令

安装完成Docker之后,这里汇总列一下常见的Docker操作命令:

  • 搜索仓库镜像:docker search 镜像名
  • 拉取镜像:docker pull 镜像名
  • 查看正在运行的容器:docker ps
  • 查看所有容器:docker ps -a
  • 删除容器:docker rm container_id
  • 查看镜像:docker images
  • 删除镜像:docker rmi image_id
  • 启动(停止的)容器:docker start 容器ID
  • 停止容器:docker stop  容器ID
  • 重启容器:docker restart 容器ID
  • 启动(新)容器:docker run -it ubuntu /bin/bash
  • 进入容器:docker attach 容器IDdocker exec -it 容器ID /bin/bash,推荐使用后者。

更多的命令可以通过docker help命令来查看。