虚拟机 | 容器 | |
---|---|---|
启动速度 | 分钟级 | 秒级 |
运行性能 | 5%左右损失 | 接近原生 |
磁盘占用 | GB | MB |
隔离性 | 系统级 | 进程级 |
封装程度 | 完整的操作系统 | 只打包代码和依赖环境,共享宿主机内核 |
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
yum -y install gcc
yum -y install gcc-c++
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl stop docker
sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
[root@localhost lingp]# docker search hello-word
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
alexstruk/hello-wordpress 0
chenlicn163/hello-word hello-word 0 [OK]
princechopra/hello-word 0
vaibhavmehta/hello-word-node hello-word-node 0
lyvy/hello-word hello-word spring boot 0
ilfaugno/hello-word 0
sjolicoeur/hello-word 0
abhayjava/hello-word The dummy short description 0
txg5214/hello-word hello-word 0
sjolicoeur/hello-word2 0
yueshide/hello-word 0
rahulnit/hello-word hello-word 0
szaier75/hello-word hello-word 0
etokarev/hello-word-python 0
cpangam/hello-word 0
geekmc/hello-word 0
bc14f103c716/hello-word 0
rghorpade80/hello-word-docker-valaxy4 0
wattwatt/hello-word 0
luoyangc/hello-word 0
hubikz/hello-worda 0
mselender/hello-word 0
thitikornc/hello-word 0
never001/hello-word 0
manyyaks/hello-word 0
[root@localhost lingp]# docker pull chenlicn163/hello-word
Using default tag: latest
latest: Pulling from chenlicn163/hello-word
19223ab0feef: Pull complete
Digest: sha256:2b7b800ab2ef8f0c2c3331ee170af82c3613b167d20e56d1884dca4772fee6c3
Status: Downloaded newer image for chenlicn163/hello-word:latest
docker.io/chenlicn163/hello-word:latest
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
[root@localhost lingp]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pull complete
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
[root@localhost lingp]# docker run -it --name=myubuntu ubuntu:latest /bin/bash
root@1a139f4915df:/#
root@1a139f4915df:/# cat /etc/issue
Ubuntu 20.04.3 LTS \n \l
root@1a139f4915df:/#
[root@localhost lingp]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a139f4915df ubuntu:latest "/bin/bash" 6 minutes ago Up 6 minutes myubuntu
21c28993fefb ubuntu:latest "/bin/bash" 11 minutes ago Exited (0) 7 minutes ago infallible_dirac
da45904d7f38 ubuntu "/bin/bash" 24 minutes ago Exited (0) 12 minutes ago compassionate_thompson
3e6cfc10ad0d ubuntu "/bin/bash" 29 minutes ago Exited (0) 24 minutes ago adoring_lalande
[root@localhost lingp]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a139f4915df ubuntu:latest "/bin/bash" 18 minutes ago Exited (127) 5 seconds ago myubuntu
21c28993fefb ubuntu:latest "/bin/bash" 24 minutes ago Exited (0) 19 minutes ago infallible_dirac
da45904d7f38 ubuntu "/bin/bash" 36 minutes ago Exited (0) 24 minutes ago compassionate_thompson
3e6cfc10ad0d ubuntu "/bin/bash" 42 minutes ago Exited (0) 36 minutes ago adoring_lalande
[root@localhost lingp]# docker start 1a139f4915df
1a139f4915df
[root@localhost lingp]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a139f4915df ubuntu:latest "/bin/bash" 19 minutes ago Up 3 seconds myubuntu
21c28993fefb ubuntu:latest "/bin/bash" 24 minutes ago Exited (0) 20 minutes ago infallible_dirac
da45904d7f38 ubuntu "/bin/bash" 36 minutes ago Exited (0) 25 minutes ago compassionate_thompson
3e6cfc10ad0d ubuntu "/bin/bash" 42 minutes ago Exited (0) 36 minutes ago adoring_lalande
[root@localhost lingp]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a139f4915df ubuntu:latest "/bin/bash" 21 minutes ago Up 2 minutes myubuntu
21c28993fefb ubuntu:latest "/bin/bash" 27 minutes ago Exited (0) 22 minutes ago infallible_dirac
da45904d7f38 ubuntu "/bin/bash" 39 minutes ago Exited (0) 27 minutes ago compassionate_thompson
3e6cfc10ad0d ubuntu "/bin/bash" 45 minutes ago Exited (0) 39 minutes ago adoring_lalande
[root@localhost lingp]# docker rm 3e6cfc10ad0d
3e6cfc10ad0d
[root@localhost lingp]# docker rm da45904d7f38
da45904d7f38
[root@localhost lingp]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a139f4915df ubuntu:latest "/bin/bash" 22 minutes ago Up 3 minutes myubuntu
21c28993fefb ubuntu:latest "/bin/bash" 27 minutes ago Exited (0) 23 minutes ago infallible_dirac
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
[root@localhost lingp]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8f9846cbdfb2 ubuntu:latest "/bin/bash" 2 hours ago Up 15 minutes myubuntud
8a9c1c2704eb ubuntu:latest "/bin/bash" 2 hours ago Exited (129) 2 hours ago myubuntu
[root@localhost lingp]# docker commit -m="add vim and gcc" -a="graywolf" 8f9846cbdfb2 grayubuntu:1.0.0
sha256:56df3dc1d8b1f94583bc7ab59b4f0b2f402dbaa2869dd558b1630ce763eeb7a6
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
grayubuntu 1.0.0 56df3dc1d8b1 8 seconds ago 342MB
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
[root@localhost lingp]# docker login --username=littleGrayWolf registry.cn-hangzhou.aliyuncs.com
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
grayubuntu 1.0.0 56df3dc1d8b1 31 minutes ago 342MB
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
[root@localhost lingp]# docker tag 56df3dc1d8b1 registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0:1.0.0
[root@localhost lingp]# docker push registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0:1.0.0
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0]
2d9e91b2c941: Pushed
9f54eef41275: Pushed
1.0.0: digest: sha256:1dd42bfd2491b694c6d0fa5971c066d37192135d212b42faa6fb961e139e6849 size: 742
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
[root@localhost lingp]# docker pull registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0:1.0.0
1.0.0: Pulling from littlegraywolf/ubuntu1.0
7b1a6ab2e44d: Already exists
d2cb84f992fd: Pull complete
Digest: sha256:1dd42bfd2491b694c6d0fa5971c066d37192135d212b42faa6fb961e139e6849
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0:1.0.0
registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0:1.0.0
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0 1.0.0 56df3dc1d8b1 41 minutes ago 342MB
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
阿里云毕竟是第三方公司,将自己公司的东西放到阿里云还是不够安全的。因此一般来说,公司都会在内部搭建私有镜像仓库,提供给公司内部人员使用。
搭建私有镜像仓库
下载镜像 Docker Registry : docker pull registry
[root@localhost lingp]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
79e9f2f55bf5: Pull complete
0d96da54f60b: Pull complete
5b27040df4a2: Pull complete
e2ead8259a04: Pull complete
3790aef225b9: Pull complete
Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0 1.0.0 56df3dc1d8b1 56 minutes ago 342MB
registry latest b8604a3fe854 20 months ago 26.2MB
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
运行私有库镜像Registry
[root@localhost lingp]# docker run -d -p 5000:5000 --privileged=true registry
ccbe13e502cd4e9f85d08086aebbe0c5a4afff7eefc730209ac6f5004580fa60
[root@localhost lingp]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ccbe13e502cd registry "/entrypoint.sh /etc…" 7 seconds ago Up 6 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp condescending_sammet
查看私有库中的镜像
[root@localhost lingp]# curl -XGET http://192.168.206.136:5000/v2/_catalog
{"repositories":[]}
修改tag
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
grayubuntu2 2.0.0 bcc9dba161d0 52 minutes ago 185MB
registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0 1.0.0 56df3dc1d8b1 2 hours ago 342MB
registry latest b8604a3fe854 20 months ago 26.2MB
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
[root@localhost lingp]# docker tag grayubuntu2:2.0.0 192.168.206.136:5000/grayubuntu2:2.0.0
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.206.136:5000/grayubuntu2 2.0.0 bcc9dba161d0 52 minutes ago 185MB
grayubuntu2 2.0.0 bcc9dba161d0 52 minutes ago 185MB
registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0 1.0.0 56df3dc1d8b1 2 hours ago 342MB
registry latest b8604a3fe854 20 months ago 26.2MB
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
修改配置使之支持http
{
"registry-mirrors": ["https://ssfzdz4k.mirror.aliyuncs.com"],
"insecure-registries":["192.168.206.136:5000"]
}
systemctl restart docker
docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry --privileged=true registry
推送本地镜像到私有仓库
[root@localhost lingp]# docker push 192.168.206.136:5000/grayubuntu2:2.0.0
The push refers to repository [192.168.206.136:5000/grayubuntu2]
07c695add28a: Pushed
9f54eef41275: Pushed
2.0.0: digest: sha256:39ace23746821bff7798f32bbce0544789019485c231ea08aca15384cc0afe68 size: 741
[root@localhost lingp]# curl -XGET http://192.168.206.136:5000/v2/_catalog
{"repositories":["grayubuntu2"]}
拉取私有仓库镜像到本地
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0 1.0.0 56df3dc1d8b1 2 hours ago 342MB
registry latest b8604a3fe854 20 months ago 26.2MB
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB
[root@localhost lingp]# git pull 192.168.206.136:5000/grayubuntu2:2.0.0
bash: git: command not found...
[root@localhost lingp]# docker pull 192.168.206.136:5000/grayubuntu2:2.0.0
2.0.0: Pulling from grayubuntu2
7b1a6ab2e44d: Already exists
0cdd9d7ee9f3: Pull complete
Digest: sha256:39ace23746821bff7798f32bbce0544789019485c231ea08aca15384cc0afe68
Status: Downloaded newer image for 192.168.206.136:5000/grayubuntu2:2.0.0
192.168.206.136:5000/grayubuntu2:2.0.0
[root@localhost lingp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.206.136:5000/grayubuntu2 2.0.0 bcc9dba161d0 About an hour ago 185MB
registry.cn-hangzhou.aliyuncs.com/littlegraywolf/ubuntu1.0 1.0.0 56df3dc1d8b1 2 hours ago 342MB
registry latest b8604a3fe854 20 months ago 26.2MB
ubuntu latest ba6acccedd29 21 months ago 72.8MB
chenlicn163/hello-word latest 3ed90589c0b6 4 years ago 844kB