docker虚拟化容器技术
1、安装
#安装方式一
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
#安装方法二
sudo apt remove docker docker-engine docker.io containerd runc
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release
sudo apt install docker-ce docker-ce-cli containerd.io
sudo snap install docker # version 20.10.8, or
sudo apt install docker.io # version 20.10.7-0ubuntu1~20.04.2
2、查看docker服务
$ docker --version
$ docker version
$ sudo systemctl status docker
$ sudo service docker status restart stop enable disable
3、卸载
sudo apt remove docker docker-engine docker.io containerd runc
sudo apt autoremove docker-ce-*
sudo rm -rf /etc/systemd/system/docker.service.d
sudo rm -rf /var/lib/docker
或者
sudo systemctl disable docker
/lib/systemd/systemd-sysv-install disable docker
sudo find / -name docker.service | xargs sudo rm -rf
sudo find / -name docker.service
sudo rm /etc/init.d/docker
sudo systemctl daemon-reload
sudo service docker status
或者
webrx@us:/etc/init.d$ sudo systemctl daemon-reload
webrx@us:/etc/init.d$ sudo rm /etc/init.d/docker
webrx@us:/etc/init.d$ sudo systemctl daemon-reload
webrx@us:/etc/init.d$ sudo systemctl status docker
Unit docker.service could not be found.
webrx@us:/etc/init.d$ sudo service docker status
Unit docker.service could not be found.
webrx@us:/etc/init.d$
4、帮助命令
$ docker version
$ docker --version
$ info
$ docker 命令 --help
$ docker pull --help
$ docker 回车查看所有命令信息
5、镜像命令
#1 查看本地镜像,没有镜像
webrx@us:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
#2 从官方hub.docker.com接取一个hello-world镜像案例
webrx@us:~$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
#3 再查看镜像
docker images
docker images -q
docker images -aq
webrx@us:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 4 weeks ago 13.3kB
#4 运行hello-world镜像
webrx@us:~$ docker run hello-world
#运行结果
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/
#5 搜索镜像
docker search mysql
docker search webrx
docker search --limit 35 --no-trunc centos
docker pull mysql 拉取
NAME: 镜像仓库源的名称
DESCRIPTION: 镜像的描述
OFFICAL: 是否docker官方发布
stars: 类似Github里面的star,表示点赞、喜欢的意思
AUTOMATED: 自动构建
#6 删除镜像
docker rmi -f 镜像ID