docker使用时遇到的错误及解决
学习docker时遇到的一些问题,在此记录一下1.sudo docker-machine create -d generic --generic-ip-address 192.168.88.128 --generic-ssh-key $HOME/.ssh/id_rsa --generic-ssh-user cj286 --generic-ssh-port 22 host2错误信息:su...
学习docker时遇到的一些问题,在此记录一下
1.sudo docker-machine create -d generic --generic-ip-address 192.168.88.128 --generic-ssh-key $HOME/.ssh/id_rsa --generic-ssh-user cj286 --generic-ssh-port 22 host2
错误信息:
sudo: unable to resolve host host1
Running pre-create checks...
Creating machine...
(host2) Importing SSH key...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Error creating machine: Error detecting OS: Too many retries waiting for SSH to be available. Last error: Maximum number of retries (60) exceeded
解决:
sudo ssh-copy-id -i ~/.ssh/id_rsa.pub cj286@192.168.88.128
2.sudo -S docker-machine create -d generic --generic-ip-address 192.168.88.130 --generic-ssh-key $HOME/.ssh/id_rsa --generic-ssh-user cj3 --generic-ssh-port 22 host3
错误信息:
sudo: unable to resolve host host1
Running pre-create checks...
Creating machine...
(host3) Importing SSH key...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Error creating machine: Error running provisioning: ssh command error:
command : sudo hostname host3 && echo "host3" | sudo tee /etc/hostname
err : exit status 1
output : sudo: no tty present and no askpass program specified
解决:
在远程主机上
# visudo
dockeradmin ALL=(ALL) NOPASSWD: ALL
3.[root@host22 cj286]# docker-machine create -d generic --generic-ip-address 192.168.88.129 --generic-ssh-key $HOME/.ssh/id_rsa --generic-ssh-user cj286 --generic-ssh-port 22 host286
错误信息:
Running pre-create checks...
Creating machine...
(host286) Importing SSH key...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Installing Docker...
Error getting SSH command to check if the daemon is up: ssh command error:
command : sudo docker version
err : exit status 1
output : sudo: docker: command not found
Error getting SSH command to check if the daemon is up: ssh command error:
command : sudo docker version
err : exit status 1
output : sudo: docker: command not found
解决:
执行docker-machine create命令的时候不要在root用户下执行,切换到普通用户下执行即可
4.执行任何命令时都报以下错误
错误信息:
__docker_machine_ps1: command not found
解决:
Machine资源库提供了几个bash脚本,可添加以下功能:
命令完成
一个在shell提示符下显示活动计算机的函数
一个函数包装器,它添加一个docker-machine use子命令来切换活动机器
确认版本并将以下的脚本保存到/etc/bash_completion.d or /usr/local/etc/bash_completion.d:
base=https://raw.githubusercontent.com/docker/machine/v0.14.0
for i in docker-machine-prompt.bash docker-machine-wrapper.bash docker-machine.bash
do
sudo wget "$base/contrib/completion/bash/${i}" -P /etc/bash_completion.d
done
然后,您需要在bash终端中运行source /etc/bash_completion.d/docker-machine-prompt.bash,告诉您的设置,它可以找到您之前下载的文件docker-machine-prompt.bash。
要启用docker-machineshell提示,请添加 $(__docker_machine_ps1)到您的PS1设置中~/.bashrc。
PS1='[\u@\h \W$(__docker_machine_ps1)]\$ '
5.docker-machine ssh host2 docker ps -a
错误信息:
open /home/cj286/.docker/machine/machines/host2/config.json: permission denied
解决:
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "/home/$USER/.docker" -R
$USER 是当前登录用户的用户名
6.docker-machine ssh 80 sudo docker ps -a
错误信息:
permissions 0670 for '/home/cj286/.docker/machine/machines/host3/id_rsa' are too open
解决:
chmod 770 /home/cj286/.docker/machine/machines/host3/id_rsa
7.docker 容器中连接主机中的mysql(127.0.0.1)时报错 getsockopt: connection refused
错误信息:
getsockopt: connection refused
解决:
使用--net参数指定为host,docker run --net=host,但是这样的话将会把主机所有的端口暴露给container,有一定的安全隐患。
如:docker run -it --net=host -p 8080:8080 shunxing
更多推荐
所有评论(0)