0 强烈推荐的docker学习网站
1. 启动docker服务
[root@laoliu src]# service docker start
Redirecting to /bin/systemctl start docker.service
[root@laoliu src]#
表示docker服务已经启动
2. 拉取镜像:
[root@laoliu ~]# docker login https://hub.someweb.com
# 默认拉取镜像的命令格式
[root@laoliu ~]# docker pull hello-world
Using default tag: latest
Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world
1b930d010525: Pull complete
Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e
Status: Downloaded newer image for docker.io/hello-world:latest
# 从 国内站c.163.com 拉取nginx镜像, 当然, 使用第一种方式也OK
[root@laoliu ~]# docker pull hub.c.163.com/library/nginx
Using default tag: latest
Trying to pull repository hub.c.163.com/library/nginx ...
latest: Pulling from hub.c.163.com/library/nginx
5de4b4d551f8: Pull complete
d4b36a5e9443: Pull complete
0af1f0713557: Pull complete
Digest: sha256:f84932f738583e0169f94af9b2d5201be2dbacc1578de73b09a6dfaaa07801d6
Status: Downloaded newer image for hub.c.163.com/library/nginx:latest
[root@laoliu ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest fce289e99eb9 4 months ago 1.84 kB
hub.c.163.com/library/nginx latest 46102226f2fd 2 years ago 109 MB
[root@laoliu ~]#
2. 使用docker运行镜像
镜像运行起来之后,就是容器,此时可以向容器内部传输文件或重写某些文件, 但是:若容器被停止, 容器内部的文件及修改文件都将全部失效, 所以此种方式可用于测试容器的某些特性, 持久性的解决方案如下:
- 1. 编写Dockerfile (推荐), 在Dockerfile内使用相关命令给出解决方式
- 2. 使用docker commit 命令持久更新镜像
# 在docker下使用ubuntu运行echo命令并输出, 这条命令也做了pull的事情,
[root@laoliu src]# docker run ubuntu echo hello world
Unable to find image 'ubuntu:latest' locally
Trying to pull repository docker.io/library/ubuntu ...
latest: Pulling from docker.io/library/ubuntu
898c46f3b1a1: Pull complete
63366dfa0a50: Pull complete
041d4cd74a92: Pull complete
6e1bee0f8701: Pull complete
Digest: sha256:017eef0b616011647b269b5c65826e2e2ebddbe5d1f8c1e56b3599fb14fabec8
Status: Downloaded newer image for docker.io/ubuntu:latest
hello world
# docker 下运行nginx
[root@laoliu src]# docker run nginx
Unable to find image 'nginx:latest' locally
Trying to pull repository docker.io/library/nginx ...
latest: Pulling from docker.io/library/nginx
27833a3ba0a5: Pull complete
ea005e36e544: Pull complete
d172c7f0578d: Pull com