Docker not working Ubuntu 20.04 on windows - docker

I am currently trying to download Hyperledger Fabric through Ubuntu 20.04. I downloaded ubuntu through the windows store. I have also downloaded docker desktop and set up WSL 2 backend for Ubuntu. However, after installing docker.io through the ubuntu terminal using
sudo apt-get install docker.io
I was trying to enable it. As ubuntu was using Sysvinit instead of systemd i used the following to try and enable docker.
sudo service docker start
which returned
docker: unrecognized service
I am new to linux so any suggestions or anything obvious I have missed that will fix this issue would be appreciated
Thanks

The ubuntu distribution that runs in WSL differs from normal ubuntu in key ways. One of them is that it doesn't have the standard linux initialization system.
service: starts services defined in the SysV init system. If you do ls /etc/init.d/ you will see services. When I look in my WSL installation, I see cron. So this works (but probably doesn't survive a reboot):
sudo service cron start
There is no init script for docker, so that won't work.
systemctl (systemd): starts services defined in the systemd system. This is probably what you want, except, if you run:
sudo systemctl start docker
you get:
System has not been booted with systemd as init system (PID 1). Can't operate.
So, you'll need to start docker manually, not using the normal initialization systems.
This leads us to the real answer:
https://docs.docker.com/docker-for-windows/wsl/
According to the docker docs, you don't run docker as a service on linux. Install docker on windows and let it interact with the docker engine on WSL to run your containers.

For me a simple restart of Windows solved this issue:
I'm using Ubuntu in WSL2 and I'm trying to start a container inside the WSL2, and it gives me this error:
Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:8443 -> 0.0.0.0:0: listen tcp 0.0.0.0:8443: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

Related

Building a docker image on wsl

I got a new machine and am now using wsl for the first time instead of just ubuntu. I am trying to rebuild one of my projects, but I am unable to build the docker image.
When running docker-compose build I get the error:
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
I have tried running:
systemctl start docker
But then I get the error:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
Can anyone tell me what im doing wrong , please and thank you.
From WSL you actually want to use Docker from the Windows host:
Install Docker Desktop for Windows
Go to the settings > Resources > WSL Integration and flip the switch for the Distros where you want Docker enabled.
You should now be able to run docker -v in your WSL commandline and get an output of the Docker version

docker installation in ubuntu and start problem

I'm unable to start docker service in ubuntu 18.04.
How do I install docker, and how do I start the start docker service?
When running systemctl start docker I got this error:
System has not been booted with systemd as init system (PID 1). Can't operate.
This is the error related to Ubuntu Linux service error, not by Docker
You Can Use
sudo service docker start/status/stop instead of systemctl
Instead, use: sudo service docker start
Docker doesn't require any explicit commands to start its service.
Kindly use steps shared in below like for Setting up docker in Debian i.e Linux machine
https://docs.docker.com/engine/install/debian/
you can get rid of using sudo for every command by doing this Manage Docker as a non-root user

Install a package with Docker in Ubuntu

I want to install a package by docker, following instruction in: https://dynamic-fba.readthedocs.io/en/latest/installation.html#installing-from-source
I installed ubuntu and then Docker. But I don't understand what I need to do next. There it is said to type (docker run -it -v ${PWD}:/opt/examples davidtourigny/dfba python3 examples/example1.py). I excatly type it in ubuntu but I get this error:
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
Using alternative method of dockerfile, I also get error. I don't know how to make use of make build, but used build instead following tutorials on the web.
It's my first time using Docker and I don't know what to do.
Any help is very appreciated.
The Docker application has two components, a back-end server, and a front-end cli. This way you can do cool stuff like control Docker remotely or have orchestration frameworks that manage multiple Docker nodes over the network like Kubernates.
For security, the Docker back-end server is not exposed on a normal TCP port but it uses a unix domain socket (Linux magic that makes a file act as a port) at unix:///var/run/docker.sock.
When you execute docker run -it ... the cli application will attempt to connect to the backend server, but it looks like the daemon/server is probably not running.
Try to check that daemon is running. If you are using systemd you can check with
systemctl status docker and start if is stopped with systemctl start docker finally it might be good to enable it to make sure it starts automatically on reboot, you can do that with systemctl enable docker
Make sure to start docker service (you can either go for systemctl start docker or reboot your computer).
Once this is done, it is likely that your user has no permissions to communicate with Docker without sudo. Docker has privileged access to your hardware and therefore giving a user the docker group is required for security reasons.
Run:
sudo usermod -aG docker $USER
groupadd docker
docker run hello-world
This will add you to docker group, reflect the changes inmediately and run a sample image from Docker.
If all was okay, the last command should tell you "Hello from Docker".

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? Linux Bash Shell on windows 10

I am new to Docker. I'm trying to work with it on windows.
I have Windows 10 Family so I installed Linux Bash Shell.
When I run this command:
$ docker run hello-world
I get :
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
And when I run
$ systemctl status docker
I get
System has not been booted with systemd as init system (PID 1). Can't operate
For anyone using WSL2 and seeing an identical error message, look at https://github.com/MicrosoftDocs/WSL/issues/457#issuecomment-511495846
Powershell
wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
Ubuntu
$ docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
$ systemctl status docker
System has not been booted with systemd as init system (PID 1). Can't operate.
$ sudo /etc/init.d/docker start
* Starting Docker: docker [ OK ]
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
It seems like you wont be able to use docker in Windows 10 family, since docker Desktop requires specific Windows version, as said in official documentation.
System Requirements
Windows 10 64-bit: Pro, Enterprise, or Education (Build 15063 or later).
What you can try is to run linux-based virtual machine on you Windows host, and run docker inside of it. But even if you succeeded, you will lose all advantages of the docker in resources consumption.
Just run the Docker Daemon with.
sudo dockerd &
The sudo make it run as super user.
Dockerd is DOCKERDaemon
The single & at the end just make it run in the background.
The issue here is that from the error message, it states that you are using WSL (Windows Sub-system for Linux Version 1), this version did not have Docker support as it is not a full Linux kernel, but an translation layer between a Linux user-space and then translated to Windows Kernel commands.
Running the wsl --list -v command will show you the version you are using:
You can install WSL version 2, which has a Microsoft provided full Linux Kernel running using Hyper-V infrastructure (but not full Hyper-V). This way it runs on Windows Home, Education, and Professional. And here you can run a Linux Instance and the install Docker.
Windows Subsystem for Linux Installation Guide

Not use docker-machine

I used docker with docker-machine ( can access container server by 192.168.99.100 ). I would like not to use docker-machine. so I can directly access my container by localhost (127.0.0.1). I shut down docker-machine (docker-machine stop) and tried to build image and container, but It said 'no daemon'. how should I completely shut down docker-machine and use local docker?
I think what you want is unset all docker-machine environment variables to use you host Docker daemon. This can be achieved with this command.
eval $(docker-machine env -u)
There are two different installs for docker on Mac. Both use a VM running Linux under the covers.
The older method includes docker toolbox and docker machine to manage the VM in virtualbox. When you use docker machine to stop this VM, the docker commands have no host to run on and will error out as you've seen.
The newer install uses xhyve to run the VM and various other tricks to make it appear seamless. This is a completely different install that you download and run from Docker, and it requires your Mac be at least version 10.10.3 with Yosemite.
See this install page for more details: https://store.docker.com/editions/community/docker-ce-desktop-mac?tab=description

Resources