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