使用Docker,拉取Nginx镜像,创建并运行Nginx容器

查看DockerHub,拉取Nginx镜像,创建并运行Nginx容器。

在DockerHub中搜索Ningx镜像,查看镜像名称

拉取Nginx镜像

bash 复制代码
[root@service ~]# systemctl start docker
[root@service ~]# mkdir -p /etc/docker
[root@service ~]# tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
}
EOF
{
  "registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
}
[root@service ~]# systemctl daemon-reload
[root@service ~]# systemctl restart docker
[root@service ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
a9edb18cadd1: Pull complete 
589b7251471a: Pull complete 
186b1aaa4aa6: Pull complete 
b4df32aa5a72: Pull complete 
a0bcbecc962e: Pull complete 
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
拉取成功!

查看本地镜像列表

bash 复制代码
[root@service ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
mysql        latest    ba6b635d3b6b   3 weeks ago   632MB
nginx        latest    605c77e624dd   2 years ago   141MB

保存Nginx镜像

bash 复制代码
[root@service ~]# docker save -o ngnix.tar nginx:latest
[root@service ~]# ll
总用量 142488
-rw-------. 1 root root      1293  9月  7 16:34 anaconda-ks.cfg
-rw-------. 1 root root 145902080  2月 13 21:01 ngnix.tar

删除Nginx镜像

bash 复制代码
[root@service ~]# docker rmi nginx:latest
Untagged: nginx:latest
Untagged: nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Deleted: sha256:605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85
Deleted: sha256:b625d8e29573fa369e799ca7c5df8b7a902126d2b7cbeb390af59e4b9e1210c5
Deleted: sha256:7850d382fb05e393e211067c5ca0aada2111fcbe550a90fed04d1c634bd31a14
Deleted: sha256:02b80ac2055edd757a996c3d554e6a8906fd3521e14d1227440afd5163a5f1c4
Deleted: sha256:b92aa5824592ecb46e6d169f8e694a99150ccef01a2aabea7b9c02356cdabe7c
Deleted: sha256:780238f18c540007376dd5e904f583896a69fe620876cabc06977a3af4ba4fb5
Deleted: sha256:2edcec3590a4ec7f40cf0743c15d78fb39d8326bc029073b41ef9727da6c851f

重新获取Nginx

bash 复制代码
[root@service ~]# docker load -i ngnix.tar
2edcec3590a4: Loading layer [==================================================>]  83.86MB/83.86MB
e379e8aedd4d: Loading layer [==================================================>]     62MB/62MB
b8d6e692a25e: Loading layer [==================================================>]  3.072kB/3.072kB
f1db227348d0: Loading layer [==================================================>]  4.096kB/4.096kB
32ce5f6a5106: Loading layer [==================================================>]  3.584kB/3.584kB
d874fd2bc83b: Loading layer [==================================================>]  7.168kB/7.168kB
Loaded image: nginx:latest
[root@service ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
mysql        latest    ba6b635d3b6b   3 weeks ago   632MB
nginx        latest    605c77e624dd   2 years ago   141MB

创建并运行容器

bash 复制代码
[root@service ~]# docker run -d --name nginx -p 80:80 nginx
daae102abc11d39c7a28dfae3c9642b9ed600d515e6582398a46758b91f9d277
[root@service ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                   CREATED         STATUS         PORTS                               NAMES
daae102abc11   nginx     "/docker-entrypoint...."   9 seconds ago   Up 8 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   nginx

停止Nginx

bash 复制代码
[root@service ~]# docker stop nginx
nginx
[root@service ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

再次启动Nginx

bash 复制代码
[root@service ~]# docker start nginx
nginx
[root@service ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                   CREATED         STATUS        PORTS                               NAMES
daae102abc11   nginx     "/docker-entrypoint...."   6 minutes ago   Up 1 second   0.0.0.0:80->80/tcp, :::80->80/tcp   nginx

查看Nginx运行日志

bash 复制代码
[root@service ~]# docker logs nginx
-f :持续查看Nginx运行

进入容器内部

bash 复制代码
[root@service ~]# docker exec -it nginx bash 
root@daae102abc11:/# 
root@daae102abc11:/# ls
bin  boot  dev	docker-entrypoint.d  docker-entrypoint.sh  etc	home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@daae102abc11:/# exit
exit
相关推荐
guoruijun_2012_4几秒前
fastadmin多个表crud连表操作步骤
android·java·开发语言
Hello-Brand11 分钟前
Java核心知识体系10-线程管理
java·高并发·多线程·并发·多线程模型·线程管理
乐悠小码17 分钟前
数据结构------队列(Java语言描述)
java·开发语言·数据结构·链表·队列
史努比.19 分钟前
Pod控制器
java·开发语言
陈小肚19 分钟前
k8s 1.28.2 集群部署 docker registry 接入 MinIO 存储
docker·容器·kubernetes
2的n次方_21 分钟前
二维费用背包问题
java·算法·动态规划
皮皮林55121 分钟前
警惕!List.of() vs Arrays.asList():这些隐藏差异可能让你的代码崩溃!
java
莳光.22 分钟前
122、java的LambdaQueryWapper的条件拼接实现数据sql中and (column1 =1 or column1 is null)
java·mybatis
程序猿麦小七27 分钟前
基于springboot的景区网页设计与实现
java·spring boot·后端·旅游·景区
weisian15133 分钟前
认证鉴权框架SpringSecurity-2--重点组件和过滤器链篇
java·安全