How to run docker-compose under WSL 2 - docker

According to Docker documentation, using Docker under WSL v2 should be fairly simple:
Install WSL 2 (make sure all the preconditions are met);
Install Docker Desktop 2.2.0 or newer;
In Docker Settings > General enable 'Expose daemon on tcp://localhost:2375 without TLS' and 'Enable the experimental WSL 2 based engine';
Make sure no Docker-related packages are installed in your Linux file system.
Once all this is done, I should be able to run docker or docker-compose commands from my Linux Terminal. But I'm not. I keep getting Command 'docker' not found, but can be installed with sudo apt install docker.io'.
What am I doing wrong?

Did you check if the integration is enabled in Resources > WSL Integration as below?

Have you made sure that wsl2 is enabled for your distro? Run this in Powershell
wsl -l -v
If your distro is not on WSL 2 then enable it like this.
wsl --set-version <Distro> 2

Install docker and docker-compose.
Type in the terminal:
sudo service docker start
sudo service --status-all | grep '+'

Related

Unable to create Docker machine on Ubuntu (VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path)

I am trying to install Docker and get it up and running on my machine. But let me tell you what OS I am using and how I am using it. I have a Windows 10 laptop. Then I installed Oracle VirtualBox on it. Then I installed Ubuntu on top of it. I am trying to install Docker and get it up and running on Ubuntu. I installed Docker.
sudo snap install docker
sudo apt install docker-compose
Then I tried to boost up the Docker Compose of my project running the following command.
docker-compose up --build -d
Then I got the following error.
ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.
Then I tried to create the Docker machine because there is no default machine. I run the following command.
docker-machine create -d virtualbox default
Then I got the following error.
Error with pre-create check: "VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path"
Then I tried installing the VirtualBox running the following commands.
sudo apt-get install virtualbox
sudo apt-get install virtualbox-ext-pack
It was successfully installed. I tried running the following command again.
docker-machine create -d virtualbox default
I am still getting the same error. What is missing in my configuration and how can I fix it?

docker-machine: command not found

I recently upgraded Docker Desktop for Mac to version 2.2.0.0, and now when try to run a docker-machine command I am getting an error:
$ docker-machine --version
docker-machine: command not found
Docker Machine used to be installed with Docker, but it appears in the latest docs that this is no longer the case. What is the replacement or do I need to install Docker Machine from somewhere else?
Docker machine has been removed from later versions of Docker Desktop. Your going to need the docker-toolbox package.
Read here for install and co existence of the packages.
https://docs.docker.com/docker-for-mac/docker-toolbox/#docker-toolbox-and-docker-desktop-coexistence
For Windows, if you have chocolatey installed, you follow the steps:
open a command shell with "Run as Administrator" selected (I tested this on my work laptop).
run "choco install docker-machine"
Docker machine is now merged into the docker command, So instead of using
docker-machine init
Use
docker swarm init
And instead of
docker-machine join
Use
docker swarm join
for more command just use this:
docker swarm --help
If you already have docker-desktop & want the docker-machine command, then brew install docker-machine does the trick.
My versions of the binaries in usr/local/bin/docker and usr/local/bin/docker-compose did not change, & the version of the docker client & server, but I got the docker-machine binary extra.
run unset ${!DOCKER_*} if you want to use docker-desktop.
The docker docs are a bit confusing because they seem to address the case where you have docker-machine first, not the case where you have desktop first.
You basically need to install Docker Machine first on your local machine. Reference :- https://github.com/docker/machine/releases
$ curl -L https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine &&
chmod +x /tmp/docker-machine &&
sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
Try and run this command on bash:
curl -L https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && chmod +x /tmp/docker-machine && sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
Click here to know more about docker-machine installation
It worked for me.
Did you try brew to install it as they removed docker-machine from v2.2.0?
brew install docker-machine
Try this (both inside, and outside of container):
ss -nputl

Docker issues on Mac

I installed docker using HomeBrew on Mac.
➜ mattermost-server git:(master) docker --version
Docker version 18.09.1, build 4c52b90
➜ mattermost-server git:(master) which docker
/usr/local/bin/docker
When I run docker,
This is the error I get.
➜ mattermost-server git:(master) docker ps
Cannot connect to the Docker daemon at **unix:///var/run/docker.sock.
Is the docker daemon running?**
Update: This can be solved by removing existing docker and running
brew install cask docker
Refer here Cannot connect to the Docker daemon on macOS
I had the same problem after install docker on my mac (brew cask install docker).
docker --version works, but docker ps or any other docker command results in the error:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
To solve the problem you have to :
Install Virtual Box
run : docker-machine create default to create a virtual machine (mandatory
on mac os)
run: docker-machine env default to set the environment
run: eval $(docker-machine env default)
try docker ps or docker version to check that everything is ready.
You are possibly running docker without sudo user, aren't you?
By default you should run docker with sudo user, if you don't want to do that, folow Manage Docker as a non-root user
We need to run brew cask install docker. This should fix the problem.

download and run ubuntu-desktop with gnome support via docker

I am completely new to docker. I have a Redhat 7 desktop with docker installed.
I now want to run a full fledged ubuntu-desktop 18.04 (including its gnome GUI) via docker. How can this be done? I have been googling for instructions/tutorials on where I can download an ubuntu 18.04 docker image (with GUI support) and run it, but surprisingly I cannot find anything. Can someone help me? Thanks.
I have a different situation, where I run docker on a Windows10 platform. I also tried to install Gnome for some Ubuntu image and start a gnome-session from the terminal. I did not manage to do so.
My current solution is to use Mate instead of Gnome. Maybe my steps are helpful for others that just started with docker:
Install Docker Desktop on Windows 10 and start the Docker application
Install vcxsrv and start it with Xlaunch (also see https://dev.to/darksmile92/run-gui-app-in-linux-docker-container-on-windows-host-4kde)
Get the IP of your computer with ipconfig, e.g 192.111.999.9
Open a console with admin rights and start a docker container. Pass some DISPLAY-Information including your IP:
docker run -it -e DISPLAY=192.111.999.9:0.0 --privileged --name=ubuntu ubuntu
You should then see a linux prompt
Update the package-manager and upgrade existing packages:
apt-get update
apt-get upgrade -y
apt-get update
start dbus service to avoid dbus warnings (also see https://georgik.rocks/how-to-start-d-bus-in-docker-container/):
dbus-uuidgen > /var/lib/dbus/machine-id
mkdir -p /var/run/dbus
dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address
install mate (and some themes to avoid theme warning)
apt-get install mate-desktop-environment -y
apt-get ubuntu-mate-themes -y
start a Desktop session with
mate-session
Good luck!
(If you want some more programs, instead of "mate-desktop-environment", you can also use the larger package "ubuntu-mate-desktop". Will take > 10 min to be installed.)
This is an atypical use case for Docker. Docker is normally used to run applications via the command line, or on a server without GUI support. Most operating systems in docker images ship without GUI support.
However, you can enable GUI support with X11. Only with containers that support it though, and not with Ubuntu as far as I can tell. More details on this blog post: https://blog.jessfraz.com/post/docker-containers-on-the-desktop/
For now, just run docker run -it --rm ubuntu:latest bash and you'll launch an Ubuntu 18.04 shell (at the time of this post).

Docker - Error response from daemon: client is newer than server

After creating a new machine with Docker Machine, I'm getting the following error:
$ docker ps
Error response from daemon: client is newer than server(client API version 1.21, server API version: 1.19)
How can I fix this?
docker-machine upgrade <your-machine>
will do the trick. This can happen - as it did for me - even if you're not using RCs and your machine was newly created. It would be due to an ISO cache issue. The error is commented in this thread.
If the docker client is 1.9.x and the server is running docker 1.8.x,
the error message is observed.
If someone happens to get this error, but is not using docker-machine, there is another way to resolve the issue by specifying an older API version in an environment variable on the client side:
export DOCKER_API_VERSION=<version>
for example:
export DOCKER_API_VERSION=1.19
and retrying the docker command.
Reference.
On ubuntu distrib it happens after an apt update, if docker run as a service.
The client is updated but the old version of the server is still running.
In this case just do a:
sudo service docker restart
If you upgrade your docker client you will not be able to use old docker-machine VMs. Actually you can force an upgrade with docker-machine upgrade vm-name, but if you are working with other distros (except boot2docker) as docker host like coreos, atomic, rancheros it may fail.
I am using Carina to manage more than one docker client version.
just install with $ curl -sL https://download.getcarina.com/dvm/latest/install.sh | sh
(linux and mac installation) and run dvm ls to list installed versions, dvm install 1.9.0 to install versions and dvm use 1.8.1 to change your client version.
Very easy and powerfull. =)
Atention, for your safety always take a look inside scripts downloaded from internet before running them.
Hope it helps
Apparently this error is due to docker-machine "falling asleep". Here is the magic command solving it for me:
$ docker-machine restart default
Or replace default by the name of your machine.
The result is:
$ docker-machine restart default
Restarting "default"...
Restarted machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
As suggested, you may need to:
$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://....."
export DOCKER_CERT_PATH=".../.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)
And so you finally run that command:
$ eval $(docker-machine env default)
From now it should work.
I had the same issue with 1.10.0-rc4, and it turned out that boot2docker wasn't updated properly when installing a newer Docker Toolbox. I had to remove boot2docker manually:
sudo rm -rf /usr/local/share/boot2docker
You can also delete the rest of the toolbox:
sudo rm -rf /usr/local/bin/docker*
sudo rm -rf /Applications/Docker
And finally install Docker Toolbox of the desired version.
Please see official uninstall script for on GitHub for OS X here.

Resources