How to I make docker start as a service on OS X? - macos

I installed DockerToolbox 1.11.1 on my Mac OS 10.11 and it does start docker via Kinematic and if I click Docker CLI it wills start a terminal where docker is properly running (docker version returns info and success).
Still, If I try to do the same from normal console it does fail to detect docker and I do want to have docker available in any console window, starting it at login time, automatically or on demand. Still, once started I expect to be able to use it from any console.
I guess that this part was missing from the tutorials and I would like to find a solution for it. How can I do this?

This is what docker machine is for. Your docker instance is running in a virtual machine, and you have to set a few environment variables to connect to it(DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH and DOCKER_MACHINE_NAME) . If you run eval $(docker-machine env [machine name]) this will set those variables automatically for you assuming the VM is up. You could then put that line into your bash profile for automatic setup.
Check out the docs here https://docs.docker.com/machine/overview/
Also, there is a native version of Docker for OSX (currently in limited beta) which removes the need for docker machine, so hopefully in the near future none of this will be necessary.

I was able to come up with some code that works across all tested platforms, including OS X:
docker version > /dev/null || {
# that's in case docker machines is the the current one (OS X)
eval "$(docker-machine env default)"
}
# keep this here, it will return an error code if docker is not usable
docker version

Related

Docker for Desktop error during connect: Post A connection attempt failed because the connected party did not properly

I have freshly installed Docker for Desktop Edge in Windows 10 Home and try to build an image using the docker build command. But unfortunately, it didn't work for me, and got the below error :
CMD - docker build -t heet1996/post:0.0.1 .
error during connect: Post https://192.168.99.100:2376/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=na8ugnpn6d8gnxl3z8ppx4gap&shmsize=0&t=heet1996%2Fpost%3A0.0.1&target=&ulimits=null&version=1: dial tcp 192.168.99.100:2376: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Earlier I was using a docker toolbox so I had to remove all the environment variables related to the Docker in my User variables before installing Docker for Desktop. After a lot of search on GitHub issues, I am still not getting the solution.
This is what I found in my service.txt file (C:\ProgramData\DockerDesktop\service.txt)
[18:27:22.232][LoggingMessageHandler][Info ] [f9b6b957] <Server end> POST http://localhost/dns/refresh-hosts -> 204 NoContent (took 118ms)
I got this error when i un-installed the docker toolbox and installed the docker desktop.
System Configuration:
OS: Windows 10 Home
Version: 21H1
Steps I Followed:
Un-installed the docker desktop.
Removed the all dockers related environment variables from the user variables.
Navigation: This System-> Properties-> Advance System Settings-> Environment Variables-> User Variables.
Re-installed the docker desktop and it's started working properly.
Try to run it on Docker CLI instead of CMD
Open Powershell as Administrator and run the below commands
cd "C:\Program Files\Docker\Docker"
./DockerCli.exe -SwitchDaemon
Docker for windows must have:
[✓] Updated Windows 10 version >=2004
[✓] WSL 2 and Default Distro (i.e ubuntu)
The steps are well documented here. These are what to do after the installation:
To confirm ubuntu's installation, open C:/Windows/System32/bash.exe aka bash.
To test if docker is properly installed, run docker version on bash. This should print the docker client and server engine.
After successfully tested and confirmed the installations, try entering your command
$ docker build -t heet1996/post:0.0.1 .
here we are talking about using Docker with PowerShell and not with WSL. And also following the addition of variables in the environment variables of Windows.
Configuration when this response was made:
Windows 10 Pro 20H2 (Build 19042.867)
Docker 20.10.5
Powershell 5.1.19041.610
I also had to configure docker in a dirty way too much, after several hours of research and a comparison of installation on a clean Windows 10 I understood where my error was.
In addition to the user environment variable also make sure that you do not have DOCKER variables in the Windows system environment variables either.
Here is where my error was, I think it was due to the installation of the Docker module
I had the DOCKER_HOST variable in my system variable environment, so i deleted it.
If you want to check all your environment variables with Powershell:
[System.Environment]::GetEnvironmentVariables()
If you really want a Docker fresh installation on Windows, you need to delete the following folders:
C:\ProgramData\Docker
C:\Program Files\Docker\Docker
$HOME\AppData\Local\Docker
$HOME\AppData\Roaming\Docker
$HOME\AppData\Roaming\Docker Desktop
$HOME\.docker
my error, therefore, produced this error:
ERROR ==> error during connect: Get http://docker.artofshell:2376/v1.24/version: dial tcp: lookup docker.artofshell: no such host
After a complete uninstall of all docker (Via chocolatey, official docker ...) and by properly installing Docker from the official executable here everything is back to normal
Then if you want to use docker via Powershell you have to change the configuration of DockerCLI as you can see on many answers
Conclusion
It is possible to use docker with Powershell you must check if the
server daemon is used by Windows/amd64, you can modify the daemon with this command cd "C:\Program Files\Docker\Docker"; .\DockerCli.exe -SwitchDeamon
You can check the configuration of the daemon with the following command: docker version
You must remove all traces of old Docker installations if you had any
You must delete the environment variables from the old installation or from the docker toolbox
You must also activate the experimental features: information here

How to download Docker CLI only for Windows 7

I'm using Windows 7 Pro and have existing shared Docker engine running on a Linux. I would like to use my workstation (with development environment) to access shared Docker engine.
Does someone know how to retrieve Docker client only for Windows 7 ? I have no admin privilege, so I can't install Docker Toolbox.
Older Clients can be found here https://download.docker.com/win/static/stable/x86_64/
And here a some newer Builds by Stefan Scherer (Docker employee) https://github.com/StefanScherer/docker-cli-builder.
Just download docker.exe and add it to your windows path variable.
Then set your DOCKER_HOST variable to define against which Docker daemon you want to speak.
The official Downloads have finally been published:
Mac CLI binaries are available at
https://download.docker.com/mac/static/stable/
Windows CLI (and daemon) binaries at https://download.docker.com/win/
Linux CLI packages are available for each distro as docker-cli (deb and rpm) packages: https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/
From: https://github.com/docker/cli/issues/2281#issuecomment-947699400
Although docker provides a REST-like API, there aren't many clients for it. A quick google turned up one on github, but ymmv. Even if you did find one, you're likely to run into the same problems involved in running docker-ce locally anyway.
There are a handful of gui clients that you could run on that engine and access with a browser, but if you are specifically after a cli you're SOL with this.
If you have an ssh client (git bash, or putty, or something), and you can arrange to run a bastion container on the engine, then you could run a container to ssh into and use that as if it's your local machine. You'd still have to scp resources onto it, but you'll eventually have to solve that problem anyway. Something like:
sudo docker container run --interactive --tty -v /var/run/docker.sock:/var/run/docker.sock image
Where 'image' is a linux image with an ssh server and appropriate keys, git, and docker installed. You could mount a local volume for persistence, or you could just keep everything in git.

the command "docker-machine ls " list nothing on my mac

I installed the latest stable docker for Mac, and started the docker directly without a virtual box. I know that it must have started a virtual box, so I use "docker-machine ls" to find the default machine, but it list nothing. How can i find the virtual machine? My OS version is 10.10.5
PS:
In fact, I didn't create any virtual machines, but do run my spring-boot app on the "alpine-oraclejdk8" image, so does that mean I exactly using the docker? And the reason I want to find the virtual machine is I used "nsenter" to enter the container to debug the log of my app but it doesn't work(the writer of "nsenter" told that I need enter the virtual machine first). So this is my confusing point that how the docker is running but I cant find the virtual machine on MAC
Docker for mac does not use docker-machine. The app that runs and give you the little whale icon in the top menu bar runs its own virtual machine. This virtual machine uses hyperkit, which is a project that uses xhyve, which is a port of bhyve to the mac os darwin kernel.
This will not create any entries to make docker-machine aware of the vm.
Rather than using nsenter to enter your container, you should use the docker exec command instead. The advantage of using docker exec is that it works without having the first ssh to where docker is running.
Because you need to create it.
Run the command
docker-machine create vm1
And you'll have your machine.
To redirect your docker client to the specific machine use this command
eval $(docker-machine env vm1)
Where 'vm1' is the same 'vm1' name that you used to create the machine. You can have a number of docker machine running at the same time using various backends like virtualbox or aws

Setting up docker on the mac: Cannot connect via localhost

I'm just setting up docker on my Mac. The installation worked and I got some containers running (following the getting-stared guide), but now I want to connect with my browser to localhost, to show a web app.
For that I'm following this guide: https://docs.docker.com/engine/userguide/containers/usingdocker/
In the last section it is said, that you simple go with your browser to: localhost:XXXXX wheras XXXXX is the port, that you found out using the command
docker ps -l
First problem: here nothing happends. The browser is showing an empty page (ERR_CONNECTION_REFUSED)
Further more in the guide it is explained, that for Mac you can check your ip address via the command:
docker-machine ip your_vm_name
Here appears the second problem: This command results in an error-message:
Host does not exist: "your_vm_name"
So my questions are:
How to set up the virtual machine (or "your_vm_name" respectively)?
Does it have to do anything with the vhosts file on my Mac OS?
Is there mybe a conflict with MAMP (which I'm also using sometimes)?
Thanks in advance!
And thanks to GianArb for the very fast answer! That solution works as well.
Just to contribute to the community, I just found out by myself, that the solution was too simple to be true.
Instead of your-vm-name use default (obviously the default-host that is set up by docker), so I just used:
docker-machine ip default
and then I got the right IP.
Hello the process to start to use docker on mac with docker-machine is like:
Create a new docker machine on virtualbox, you can use a name like "your_vm_name" or just "default" in this way you can not use the name because "default" is a keyword that docker-machine try to use when you don't specify nothing.
The problem here is, why docker-machine ip your_vm_name doesn't provide the good ip? Can you copy the result of your command
echo $DOCKER_HOST
Usually it's 192.168.99.100
thanks a lot
Actual for Mac OS:
If there is no real need in VirtualBox machine you can just remove it.
Docker can start Linux containers under Mac OS without any VirtualBox machines.
Without any VirtualBox machines, all exported ports are available on the localhost:*.
Remove docker machine
docker-machine ls
docker-machine stop default
docker-machine rm default
Make sure that you don't have the command eval $(docker-machine env ...) in your ~/.bashrc or ~/.zshrc.
Otherwise, nothing will work. You will see the error Error: No machine name(s) specified and no "default" machine exists.
By the default configuration no need to have any env variables like $DOCKER_*
In my case, the only docker installed by downloading a .dmg image from the official site works without any problems. Any versions installed via brew didn't work out of the box.
PS: tested on Mac OS 10.13 and 10.14

docker-compose is not working on Docker Beta for OS X

I'm using docker Version 1.11.1-beta11 (build: 6974) on OS X (which is native). It has a fancy migration tool to help you to move images from docker-machine to native docker (or something like that). Everything was working perfect, I even was able to start containers through docker-compose but then I rebooted my laptop and now docker-compose is not recognizing new docker engine I guess because I'm getting:
ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.
So I believe docker-compose still thinks I'm using or depending on docker-machine to start containers.
Any idea about how to workaround this issue?
Update:
Docker env variables:
DOCKER_TLS_VERIFY=1
DOCKER_HOST=tcp://192.168.99.100:2376
DOCKER_CERT_PATH=/Users/myuser/.docker/machine/machines/default
DOCKER_MACHINE_NAME=default
I removed the docker env variables from my rc script (~/.zshrc) and upgraded docker-compose version to 1.7.1. Also made sure sure docker-machine was down

Resources