#在Docker仓库搜索Nginx镜像;
docker search nginx
报错如下:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200715111554323.png
[root@localhost docker]# docker search nginx
Error response from daemon: Get https://index.docker.io/v1/search?q=nginx&n=25: dial tcp: lookup index.docker.io on [::1]:53: read udp [::1]:50421->[::1]:53: read: connection refused
解决方案:
#查看域名对应的ip
dig @114.114.114.114 index.docker.io
报错如下:
bash: dig: 未找到命令
经过查找资料,原来dig命令属于bind-utils工具包,安装这个包之后就可以使用dig命令了。
yum -y install bind-utils
报错如下:
Downloading packages:
bind-license-9.11.4-16.P2.el7_ FAILED
http://mirrors.cn99.com/centos/7.8.2003/updates/x86_64/Packages/bind-license-9.11.4-16.P2.el7_8.6.noarch.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cn99.com; Unknown error" ] 0.0 B/s | 0 B --:--:-- ETA
正在尝试其它镜像。
GeoIP-1.5.0-14.el7.x86_64.rpm FAILED
http://mirrors.aliyun.com/centos/7.8.2003/os/x86_64/Packages/GeoIP-1.5.0-14.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.aliyun.com; Unknown error" ] 0.0 B/s | 0 B --:--:-- ETA
正在尝试其它镜像。
解决方案
#编辑resolv.conf文件
vi /etc/resolv.conf
/#配置以下信息
nameserver 8.8.8.8
#重启network服务
service network restart
#再次执行
yum -y install bind-utils
#合适了
小插曲:
DNS(Domain Name System)是域名解析服务器的意思,它在互联网的作用是把域名转换成为网络可以识别的IP地址。当用户在浏览器中输入网址域名时,首先就会访问系统设置的DNS域名解析服务器(通常由ISP运营商如电信、网通提供)。如果该服务器内保存着该域名对应的IP信息,则直接返回该信息供用户访问网站。否则,就会向上级DNS逐层查找该域名的对应数据。
普通用户要使用Google DNS非常简单,因为Google为他们的DNS服务器选择了两个非常简单易记的IP地址:“8.8.8.8”和“8.8.4.4”。用户只要在系统的网络设置中选择这两个地址为DNS服务器即可。
Linux下设置:
echo nameserver 8.8.8.8 > /etc/resolv.conf
echo nameserver 8.8.4.4 > /etc/resolv.conf
继续执行
#在Docker仓库搜索Nginx镜像;
docker search nginx
#从Docker仓库中下载Nginx镜像;
docker pull nginx
#查看本地nginx 的镜像
docker images
#基于Nginx镜像启动Nginx应用容器;
docker run -d -p 80:80 --name my_nginx nginx
报错如下:
docker run -d -p 80:80 --name my_nginx nginx
d09ea3c1af64fd899e3bdfbc1ef908b1a3e9cb135dab9556c148947ddef4b6f4
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container ini
解决方案
vim /etc/selinux/config
修改前
修改后:
#重启虚拟机
reboot
再次执行启动nginx镜像命令
docker run -d -p 80:80 --name my_nginx nginx
报错如下:
[root@localhost ~]# docker run -d -p 80:80 --name my_nginx nginx
docker: Error response from daemon: Conflict. The container name "/my_nginx" is already in use by container "d09ea3c1af64fd899e3bdfbc1ef908b1a3e9cb135dab9556c148947ddef4b6f4". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
解决方案
# 先查看所有的容器docker ps -a
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d09ea3c1af64 nginx "/docker-entrypoint.…" 29 minutes ago Created 0.0.0.0:80->80/tcp my_nginx
#移除容器 docker rm CONTAINER ID
[root@localhost ~]# docker rm d09ea3c1af64
d09ea3c1af64
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost ~]# docker run -d -p 80:80 --name my_nginx nginx
3d0ec05ad1ad4333552be97a5f7e837e85ba2296a9d8481b3359d54afded83a9
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3d0ec05ad1ad nginx "/docker-entrypoint.…" 12 seconds ago Up 12 seconds 0.0.0.0:80->80/tcp my_nginx
[root@localhost ~]# curl http://192.168.234.3:80/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
页面访问: