Docker常用命令

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

安装完之后测试docker是否安装成功:

sudo docker run hello-world

打印如下信息,则代表安装成功:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete                                                                                                                                  Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
Status: Downloaded newer image for hello-world:latest

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

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

遇到的问题:

  • 权限问题:
    在这里插入图片描述
    解决:
    将登陆用户加入到docker用户组中sudo gpasswd -a $USER docker
    更新用户组newgrp docker
安装完Docker之后,就是Docker的命令使用了

在这里插入图片描述

1.找镜像
  • 拉取镜像
    下载镜像:
    docker pull 镜像名
    ex:
    	docker pull nginx //下载nginx的镜像,默认最新版,也就是latest版本
    
    下载指定版本镜像:
    docker pull 镜像名:版本名
    ex:
    	docker pull nginx:1.20.1
    
  • 查看镜像
    - docker images
    
    在这里插入图片描述
  • 删除镜像
- docker rmi 镜像名
- docker rm 镜像名 //删除停止的镜像
- docker rm -f 镜像名 //强制删除正在运行中的镜像

在这里插入图片描述

  • 启动容器
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

- docker run 镜像名 // 运行镜像
- docker run --name=别名 镜像名 //运行镜像,并命名为别名
- docker run -d 镜像名 // 后台运行镜像
- docker run -d --restart=always 镜像名  //开机自启
- docker run -d -p 88:80 镜像名 //进行端口映射,

在这里插入图片描述

  • 查看正在运行的容器
- docker ps //查看运行中的容器
- docker ps -a //查询所有的容器,不管运行还是不运行

在这里插入图片描述

  • 停止容器
- docker stop 镜像标识 // 停止容器,这里的镜像标识可以是CONTAINER ID,也可以是NAMES

在这里插入图片描述

  • 启动停止的容器
- docker start 容器id/容器名

在这里插入图片描述

  • 更新docker的启动参数
- docker update 镜像名 启动参数

在这里插入图片描述

  • 镜像分享
1.将镜像制作为压缩包
- docker save -o zjqNginx.tar zjq:v1.0

2.推送到Docker Hub(推荐)
//需要先登录docker hub
- docker login //输入docker hub的账号密码即可
//先打出版本号
- docker tag guignginx:v1.0 17060212119/zjq_nginx:v1.0
//再推送hub
- docker push 17060212119/zjq_nginx:v1.0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值