docker及服務器遇到的坑

DNS不可用

如出現這樣的錯誤:html

ERROR: error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/88/881bd08c0b08234bd19136957f15e4301097f4646c1e700f7fea26e41fc40069/data?verify=1552449302-pJVj4p2TS9sUquWEjuDZgIA0f7E%3D: dial tcp: lookup production.cloudflare.docker.com on 10.0.2.3:53: no such host

進入 /etc/resolv.conf 添加mysql

nameserver 8.8.8.8

vagrant 搭的虛擬環境或者docker裏面遇到過,每次重啓都會失效,能夠寫個shell腳本修改,每次開機啓動就行了。git

docker使用還有種方案,容器內的/etc/resolv.conf掛載到宿主機下 /etc/resolv.conf。github

修改docker查找源

docker search centos
Error response from daemon: Get https://index.docker.io/v1/search?q=centos: read tcp 52.200.132.201:443: i/o timeout

進入/etc/dockersql

查看有沒有 daemon.json。這是docker默認的配置文件。docker

若是沒有新建,若是有,則修改。shell

$ vi daemon.json
 {
   "registry-mirrors": ["https://registry.docker-cn.com"]
 }

保存退出。json

重啓docker服務centos

service docker restart

成功!

容器保持固定ip

https://yaxin-cn.github.io/Docker/docker-container-use-static-IP.html

查看docker鏈接

查看容器進程號

docker inspect -f '{{.State.Pid}}'

查看鏈接

nsenter -t 1840 -n netstat #1840爲上面操做獲取的pid

容器間通訊

參考文章 https://birdben.github.io/2017/05/02/Docker/Docker實戰(二十七)Docker容器之間的通訊/

新版docker,在容器B run中使用 --link 【容器A】,這樣在容器B中就能與容器A創建鏈接,如須要用到容器A的ip,進行鏈接服務:

# mysql是容器名
mysql:3306/users?user=root&password=123456

容器拷貝數據

  • 從容器拷貝數據到宿主機

docker cp 容器名:要拷貝的文件在容器裏面的路徑 要拷貝到宿主機的相應路徑

  • 從宿主機拷貝數據到容器

docker cp 要拷貝的文件路徑 容器名:要拷貝到容器裏面對應的路徑

php鏈接docker mysql 8.0出錯authentication method unknown

SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

MySQL 8默認使用了新的密碼驗證插件:caching_sha2_password,而以前的PHP版本中所帶的mysqlnd沒法支持這種驗證

解決方法兩種,一種是升級PHP支持mysql8的新驗證插件,另外一種mysql驗證方式降級。

mysql配置文件 my.cnf添加配置:

default_authentication_plugin=mysql_native_password
相關文章
相關標籤/搜索