So im having some weird problems with docker-machine. I am trying to set up a docker-machine on my Mac OS El Capitan and also have the daemon flagged for a few insecure registries. I was able to successfully push/pull on a local Ubuntu install (without docker-machine) by setting the DOCKER_OPTS options to flag my insecure Nexus docker registries. I am trying to accomplish the same end goal on my Mac OS. So far I have installed the Docker Toolbox using a default installation and have tried the following in Terminal.
Vinays-MacBook-Pro:~ Vinay$ sudo docker-machine create --driver virtualbox --
engine-insecure-registry mynexusrepo.cloudapp.net:18443 --engine-insecure-registry mynexusrepo.cloudapp.net:18444 --engine-insecure-registry mynexusrepo.cloudapp.net:18445 dev
Creating VirtualBox VM...
Creating SSH key...
Starting VirtualBox VM...
Starting VM...
To see how to connect Docker to this machine, run: docker-machine env dev
Vinays-MacBook-Pro:~ Vinay$ eval "$(sudo docker-machine env dev)"
Vinays-MacBook-Pro:~ Vinay$ sudo docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
dev virtualbox Running tcp://192.168.99.100:2376
Vinays-MacBook-Pro:~ Vinay$ sudo docker pull mynexusrepo.cloudapp.net:18445/docker-thirdparty/mongodb:3.0.2
Password:
Post http:///var/run/docker.sock/v1.20/images/create?fromImage=mynexusrepo.cloudapp.net%3A18445%2Fdocker-thirdparty%2Fmongodb%3A3.0.2: dial unix /var/run/docker.sock: no such file or directory.
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?
Vinays-MacBook-Pro:~ Vinay$ sudo docker images
Password:
Get http:///var/run/docker.sock/v1.20/images/json: dial unix /var/run/docker.sock: no such file or directory.
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?
Vinays-MacBook-Pro:~ Vinay$ docker-machine -version
docker-machine version 0.4.1 (e2c88d6)
So I know the sudo docker pull mynexusrepo.cloudapp.net:18445/docker-thirdparty/mongodb:3.0.2 command works since it works fine on my straight Ubuntu OS with a docker install. Is there something else I am missing? I have tried closing all the terminals, deleting all of the docker-machines, restarting, etc.
Thanks!
Related
TL;DR: How do I create or link a Docker socket at /var/run/docker.sock at my host for a Docker Machine instance?
On my Mac, I installed Docker and Docker Machine using Homebrew:
brew install docker docker-machine
I also installed docker-machine-driver-vmware to create a Docker Machine instance based on my hypervisor:
brew install docker-machine-driver-vmware
docker-machine create --driver vmware default
My problem is that I have an application that relies on the Docker socket to create containers, but I cannot find the Docker socket anywhere in my system.
How do I find the Docker socket, and how can I change it or link it to /var/run/docker.sock?
My Docker service is up and running. However when attempting to use Docker by running it with sudo, e.g.:
12:40:26/~ $ sudo docker pull fluxcapacitor/pipeline
Using default tag: latest
I have got the following error:
Warning: failed to get default registry endpoint from daemon (Cannot connect to
the Docker daemon. Is the docker daemon running on this host?). Using system
default: https://index.docker.io/v1/
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Note that I had already followed the answers on Mac OS X sudo docker Cannot connect to the Docker daemon. Is the docker daemon running on this host?
as follows:
docker-machine start default
12:40:36/~ $ docker-machine start default
Starting "default"...
Machine "default" is already running.
docker ps
12:41:20/~ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
So what more needs to be done?
This is:
$ docker --version
Docker version 1.11.2, build b9f10c9
on El Capitan.
Output of docker-machine env default
$ eval "$(docker-machine env default)"
$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/macuser/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
The following command exports a few environment variables that the subsequent docker commands use:
eval "$(docker-machine env default)"
However, if you launch docker with sudo, the exported environment variables are not accessible by the docker executable. You could potentially get it to work by passing -E flag to sudo, e.g.:
sudo -E docker pull fluxcapacitor/pipeline
But much easier option is to use docker without root like:
docker pull fluxcapacitor/pipeline
You have to set environment variables with:
eval "$(docker-machine env default)"
More about it here.
I had same probelem on my MAC, when attempted
# eval "$(docker-machine env default)"
got this error
Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.100:2376": x509: certificate is valid for 192.168.99.101, not 192.168.99.100
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.
to regenerate certificates, find out the docker-machines available;
# docker-machine ls
Output of avalable docker machines (omitted others)
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default - virtualbox Running tcp://192.168.99.100:2376 Unknown Unable to query docker version: Get https://192.168.99.100:2376/v1.15/version: x509: certificate is valid for 192.168.99.101, not 192.168.99.100
Generate certificates for this default docker-machine
# docker-machine regenerate-certs default
and then setup docker-machine env to default docker-machine;
# eval "$(docker-machine env default)"
and it works normally after that.
I have also tried the same but did not work.
later I have tried these steps on AWS CLI
$ sudo nano /etc/docker/daemon.json
{
"dns": ["8.8.8.8", "8.8.4.4"]
}
$ sudo service docker restart
$ docker pull hello-world
I'm having a recurring problem with Docker Machine - every few days it decides to timeout and I am unable to recover it once this happens.
Example
docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default virtualbox Timeout
Environment Info
uname -a Darwin ColeyMBPR 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
docker version 1.11.0
docker-machine version 0.7.0
vboxmanage --version 5.0.20r106931
Attempted Solutions
I've tried the following things in no particular order:
Restarting the docker machine.
Running eval "$(docker-machine env default)"
Regenerating the certificates docker-machine regenerate-certs default
Restarting my host box.
Upgrading Docker.
Reinstalling Docker.
Upgrading VirtualBox.
Removing all VirtualBox host-only network devices.
Hack
The only thing that's working for me right now is destroying the docker machine and recreating it. This destroys all my images and containers, and it's incredibly time consuming to set it up again.
docker-machine rm -y default && docker-machine create -d virtualbox default && eval $(docker-machine env)
Is there anything I can try? Thanks!
Update: 9th May (Steps to Reproduce)
I can reliably reproduce this problem with the following steps:
Start with a freshly created Docker machine.
Use docker-compose up to build some containers.
Shutdown the computer with the containers running.
After reboot the Docker CLI doesn't work due to the Docker machine timing out.
This command worked for me with the digitalocean driver:
docker-machine ls -t 20
It seems as though the default timeout of 10 seconds was too short.
This is usually a problem related to the way you start and stop your machine.
You can solve it using
$ docker-machine stop default
$ docker-machine start default
$ docker-machine regenerate-certs default
Do not use docker-machine restart default because it will not refresh your networking configs.
Check if you are are using a proxy or VPN!
None of the above suggestions worked for me until I turned off my VPN and suddenly:
docker-machine.exe ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.102:2376 v19.03.5
I had the same issue with Docker version 1.11.2, build b9f10c9
This worked for me - my docker machine is back to the Running state
$ docker-machine restart
$ eval $(docker-machine env)
So far I have a bit of a hacky solution - this fixes the docker machine but destroys all containers and images.
Script: rebuild-machine.sh
docker-machine rm -y default
docker-machine create -d virtualbox default
docker-machine stop default
VBoxManage modifyvm "default" --natpf1 "Forwarding App 1,tcp,127.0.0.1,3000,,3000"
VBoxManage modifyvm "default" --natpf1 "Forwarding App 2,tcp,127.0.0.1,3001,,3001"
VBoxManage modifyvm "default" --natpf1 "Forwarding App 3,tcp,127.0.0.1,3004,,3004"
VBoxManage modifyvm "default" --natpf1 "Forwarding App 4,tcp,127.0.0.1,3005,,3005"
VBoxManage modifyvm "default" --natpf1 "Forwarding App 5,tcp,127.0.0.1,3006,,3006"
VBoxManage modifyvm "default" --natpf1 "Forwarding App 6,tcp,127.0.0.1,8081,,8081"
docker-machine start default
eval $(docker-machine env)
Explanation
Destroys the default docker machine, containers and images.
Creates a new docker machine on VirtualBox and stops it so we can modify VirtualBox.
Adds port forwarding for various applications on VirtualBox.
Starts the docker machine.
Ensures the Terminal is setup for the new IP address of the docker machine.
My problem was very simple. I was blocking port 2376 with my ufw firewall. Docker-machine needs this port open to connect to the remote.
I found the answer to my problem in on this page:
I have opened virtualbox and closed and start all vm manually/. State is running again
This worked for me and my containers were not destroyed:
Opened Oracle virtual box and paused the VM
Restarted the VM on docker machine
$ docker-machine restart default
docker version: 1.12.3
docker-machine version: 0.8.2, build e18a919
My problem was very trivial - I did the docker machine ls command right after restarting a docker machine, so it was not running yet, and that caused a timeout.
I'm trying to start the default machine of Docker on Mac OSX.
Everytime i'm trying to start a new default machine by command:
docker-machine create --driver virtualbox default
of using Docker Quick Start Terminal It stucks on
(default) Creating SSH key...
This is the output:
Running pre-create checks...
Creating machine...
(default) Copying /Users/avivpaz/.docker/machine/cache/boot2docker.iso to /Users/avivpaz/.docker/machine/machines/default/boot2docker.iso...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
This is my OSX and Docker versions:
Mac 10.11.3
docker-machine version 0.6.0, build e27fb87
That seems to be followed by issue 2788 and more related to VirtualBox than docker machine.
Try and reboot the Mac, or make sure there is no VBox... process.
First, just delete the boot2docker.iso from ~/cache directory and once again restart the docker terminal. If will download the fresh latest boot2docker.iso and you are good to go.
If it's not working manually download the latest boot2docker.iso and place it into the above directory of cache
/Users/{user}/.docker/machine/cache/
$ ~/.docker/machine/cache
$ ls
boot2docker.iso
And, finally run to create an virtual machine,
docker-machine create --driver virtualbox default
And, again, you are good to go. Hope this helps.
I'm new to Docker...
From my understanding, Docker is only compatible with Linux, is it possible to run docker for development purposes on a Mac?
I installed virtualbox using homebrew and have tried to create a virtualbox instance. I installed docker, but am having trouble getting my mac to communicate with the vm docker instance. My end goal is to get a locally debuggable instance of tomcat running on the docker container.
Any help or tips would be helpful.
Information:
Because Docker only runs on Linux you will need to install some kind of virtual instance on your local machine. An easy and popular way to do that is to install
Boot2docker and VirtualBox. VirtualBox is a dependency of Boot2docker. You can download, setup and install the latest versions from their websites or if you are using Homebrew, as you mentioned, you can quickly get the working binaries both in one step.
After installing boot2docker, you're ready to use Boot2docker to create a Tomcat Container. You can find a pre-configured tomcat image by searching Docker's community repository, docker hub registry.
Notes:
Each time you execute the docker run command a new container is created.
The VM running Docker requires a ssh private/public encryption key handshake to connect to. If you follow my steps below, one will be generated for you.
Steps to Setup Tomcat using the tomcat image:
Open Terminal and run this command: brew install boot2docker
Create a new Boot2Docker VM instance using the init command: boot2docker init
Run this command in Terminal to forward local ports to the vm:
for i in {10000..10999}; do VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i”; VBoxManage modifyvm "boot2docker-vm" --natpf1 "udp-port$i,udp,,$i,,$i";done
Start the boot2docker daemon: boot2docker start or boot2docker up
After starting docker, copy the exports that are displayed from the previous command to your clipboard
Edit your bash profile file ~/.bash_profile (or if you are using zsh, edit the resource configuration file ~/.zshrc) with a text editor (I prefer using Sublime text): subl .zshrc *note: this will permanently save the docker env variables.
Paste the exports into that file and save
Execute the source command on the file: source .zshrc
Pull the latest tomcat image to create a container and start tomcat: docker run -it --rm -p 10080:8080 tomcat:8.0 *note: this will forward your local 10080 port to the vm's 8080 port.
Go to http://localhost:10080, you should see the tomcat start page!
Useful Docker commands:
$ boot2docker status
$ docker version
$ docker ps #shows running containers
$ docker ps -a # shows all containers
$ docker exec -it NAME /bin/bash #to start a bash session on the container. -i = interactive, -t = tty
External Resources:
https://docs.docker.com/installation/mac/#installation
https://registry.hub.docker.com/_/tomcat/
Most people use boot2docker to run on Macs. You may also want to take a look at Kitematic, which gives you a GUI to play with.
Finally, the future is probably to use docker machine, which can provision a VM for you.
Docker requires Linux Kernel features, hence it cannot be run natively on OSX.
See instead Boot2Docker. This link gives you instructions on how to get going.