Failed to connect to bus: Host is down in ubuntu - docker

"sudo systemctl enable --now docker" while running this command I'm getting an error like "System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down"
How can I fix this and I'm new to Ubuntu commands.

Please refer to Latest Docker Documentation; Older versions of Docker don't play nicely.
The trick is to uninstall sudo apt-get remove docker docker.io containderd, etc... And add the docker GPG key and setup the repository (documented in link). Then install sudo apt-get install docker-ce docker-ce-cli containerd.io instead.
Once you've removed old docker from your Ubuntu installation, you can then go sudo service docker start to have docker daemon running without systemctl and use service instead.

I am using ubuntu:20.04 Image.
I encountered the same error while trying to use systemctl command inside the ubuntu docker container, since the system has not been booted with systemd as init system (PID 1) as the error says so in order to fix that you will need to start you container using this
docker run -ti -d ubuntu:20.04 "/sbin/init"
In fact, running the container will cause an error:
I have solvedcontroller_1 | Failed to mount tmpfs at /run: Operation not permitted
container_1 | Failed to mount tmpfs at /run/lock: Operation not permitted
container_1 | [!!!!!!] Failed to mount API filesystems.
container_1 | Freezing execution.
By default, the container is not authorized to access any device, but a container with a "privileged" tag grants its root capabilities to all devices on the host system that will give access to the container to mount API filesystems and solve the issue.
in order to fix that you will need to
docker run -ti -d --privileged ubuntu:20.04 "/sbin/init"

Related

how can i made docker work with my user (ubuntu)

this is the current situation:
hamsterofdeath#HodVm:~$ docker ps
Cannot connect to the Docker daemon at unix:///home/hamsterofdeath/.docker/desktop/docker.sock. Is the docker daemon running?
hamsterofdeath#HodVm:~$ sudo docker ps
[sudo] password for hamsterofdeath:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
hamsterofdeath#HodVm:~$ docker ps
Cannot connect to the Docker daemon at unix:///home/hamsterofdeath/.docker/desktop/docker.sock. Is the docker daemon running?
hamsterofdeath#HodVm:~$ sudo groupadd docker
groupadd: group 'docker' already exists
hamsterofdeath#HodVm:~$ sudo gpasswd -a ${USER} docker
Adding user hamsterofdeath to group docker
hamsterofdeath#HodVm:~$ docker ps
Cannot connect to the Docker daemon at unix:///home/hamsterofdeath/.docker/desktop/docker.sock. Is the docker daemon running?
hamsterofdeath#HodVm:~$
cat /etc/group gives me "docker:x:996:hamsterofdeath"
logging out and in again changes nothing. i also tried:
sudo usermod -aG docker $USER
sudo usermod -a -G docker $USER
but it has no effect. what do i need to do?
i always get:
Cannot connect to the Docker daemon at unix:///home/hamsterofdeath/.docker/desktop/docker.sock. Is the docker daemon running?
or
Error response from daemon: dial unix /home/hamsterofdeath/.docker/desktop/docker.raw.sock: connect: connection refused
with sudo, it works
there might be another(?) problem
i removed docker via
sudo apt remove docker
but the "docker" command still exists.
amsterofdeath#HodVm:~$ sudo apt remove docker
[sudo] password for hamsterofdeath:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package 'docker' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
hamsterofdeath#HodVm:~$ docker ps
Cannot connect to the Docker daemon at unix:///home/hamsterofdeath/.docker/desktop/docker.sock. Is the docker daemon running?
hamsterofdeath#HodVm:~$
Waht you could try:
Try restarting the bash process and probably the machine.
See if the docker group is associated with the .sock file
This should return nothing:
stat -c %U:%G /home/hamsterofdeath/.docker/desktop/docker.raw.sock | grep -v root:docker
if it does do:
chown root:docker /home/hamsterofdeath/.docker/desktop/docker.raw.sock
Is $USER filled with the correct data ?
Restart docker engine using sudo systemctl
Else go to Post-Install and try all the steps there especially since it seems to an VM restart it
Next Docker Desktop is rather sketchy. I personally recommend using the VS-Code Docker extension as it offers almost the same functionality as docker desktop and works fine with Ubuntu. See Docker Extension VS-Code

Problems starting docker instance

Not sure this is a docker problem specifically but this is how it goes: I tried sudo docker stop 7f8c9285465c which resulted in
Error response from daemon: cannot stop container: 7f8c9285465c: Cannot kill container...unknown error after kill: runc did not terminate sucessfully: container_linux.go:392: signaling init process caused "permission denied"
Following this stackoverflow suggestion I did sudo aa-remove-unknown. Now the docker stop succeeded but subsequent docker-compose up resulted in:
snap-confine has elevated permissions and is not confined but should be. Refusing to continue to avoid permission escalation attacks.
Next I ran the command sudo apt purge snapd snap-confine && sudo apt install -y snapd. Now running docker-compose up results in
bash: /snap/bin/docker-compose: No such file or directory.
The command sudo docker container ls results in:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
sudo service docker status returns Active: active (running).
I tried reinstalling docker. running sudo docker run hello-world retunrs the same Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (although status is active)
.
Create file /etc/systemd/network/bridge.network with contents:
[Network]
IPFoward=kernel
If no permissions to save do so in root mode (sudo su -).
Then, run:
sudo systemctl restart systemd-networkd.service # (disconnected network)
sudo apt remove docker-ce # If you hadn't done so before
sudo apt install docker-ce # Should start docker.service
sudo systemctl status docker.service # Verify docker.service is running
This information has been taken from this docker forum discussion.
I think you installed docker with snap and installation of snapd is not complete "snap-confine has elevated permissions and is not confined but should be. Refusing to continue to avoid permission escalation attacks.
" this error indicates that "apparmor" service is not enabled.
sudo systemctl enable --now apparmor
sudo systemctl status apparmor
If apparmor is not installed install it:
sudo apt-get install apparmor
this error "bash: /snap/bin/docker-compose" indicates that "/snap/bin" is not in your PATH. if you run this snap --version you might get an error saying "/snap/bin" is not in PATH.
sudo nano /etc/environment
Add "/snap/bin"
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/snap/bin
Now you need to restart your system. Everything should be fixed.

How to run a Docker host inside a Docker container?

I have a Jenkins container running inside Docker and I want to use this Jenkins container to spin up other Docker containers when running integration tests etc.
So my plan was to install Docker in the container but this doesn't seem to work so well for me. My Dockerfile looks something like this:
FROM jenkins
MAINTAINER xxxx
# Switch user to root so that we can install apps
USER root
RUN apt-get update
# Install latest version of Docker
RUN apt-get install -y apt-transport-https
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
RUN sh -c "echo deb https://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
RUN apt-get update
RUN apt-get install -y lxc-docker
# Switch user back to Jenkins
USER jenkins
The jenkins image is based on Debian Jessie. When I start bash terminal inside container based on the generated image and do for example:
docker images
I get the following error message:
FATA[0000] Get http:///var/run/docker.sock/v1.16/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?
I suspect that this could be because the docker service is not started. But my next problem arise when I try to start the service:
service docker start
This gives me the following error:
mount: permission denied
I've tracked the error in /etc/init.d/docker to this line:
mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
So my questions are:
How do I actually start a Docker host inside a container? Or is this
something that should be avoided?
Is there something special I need to do if I'm running Mac and boot2docker?
Perhaps I should instead link to the Docker on the host machine as described here?
Update: I've tried the container as user root and jenkins. sudo is not installed.
A simpler alternative is to mount the docker socket and create sibling containers. To do this, install docker on your image and run something like:
docker run -it -v /var/run/docker.sock:/var/run/docker.sock myimage
In the container you should now be able to run docker commands as if you were on the host. The advantage of this method is that you don't need --privileged and get to use the cache from the host. The disadvantage is that you can see all running containers, not just the ones the created from the container.
1.- The first container you start (the one you launch other one inside) must be run with the --privileged=true flag.
2.- I think there is not.
3.- Using the privileged flag you don't need to mount the docker socket as a volume.
Check this project to see an example of all this.

run docker Rstudio server without root?

I just started playing with docker. The first thing I did was to install it, and then install Rstudio-server. (I'm running ubuntu 14.04)
sudo apt-get install docker.io
sudo docker run -d -p 8787:8787 -e USER='some_user_name' -e PASSWORD='super_secret_password' rocker/hadleyverse
Is it possible to run a docker rstudio server without sudo? If so, how?
Thanks!
From this answer:
The docker manual has this to say about it:
Giving non-root access
The docker daemon always runs as the root user, and since Docker version 0.5.2, the docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root, and so, by default, you can access it with sudo.
Starting in version 0.5.3, if you (or your Docker installer) create a Unix group called docker and add users to it, then the docker daemon will make the ownership of the Unix socket read/writable by the docker group when the daemon starts. The docker daemon must always run as the root user, but if you run the docker client as a user in the docker group then you don't need to add sudo to all the client commands. As of 0.9.0, you can specify that a group other than docker should own the Unix socket with the -G option.
Warning: The docker group (or the group specified with -G) is root-equivalent; see Docker Daemon Attack Surface details.
Example:
Add the docker group if it doesn't already exist.
sudo groupadd docker
Add the connected user "${USER}" to the docker group. Change the user name to match your preferred user.
sudo gpasswd -a ${USER} docker
Restart the Docker daemon:
sudo service docker restart
If you are on Ubuntu 14.04 and up use docker.io instead:
sudo service docker.io restart
You need to log out and log back in again if you added the current logged in user.

docker error: /var/run/docker.sock: no such file or directory

I am new to docker. I have a shell script that loads data into impala and I want a docker file that runs builds an image and run the container.
I am on mac, installed boot2docker and have the DOCKER_HOST env set up.
bash-3.2$ docker info
Containers: 0
Images: 0
Storage Driver: aufs
Root Dir: /mnt/sda1/var/lib/docker/aufs
Dirs: 0
Execution Driver: native-0.2
Kernel Version: 3.15.3-tinycore64
Debug mode (server): true
Debug mode (client): false
Fds: 10
Goroutines: 10
EventsListeners: 0
Init Path: /usr/local/bin/docker
Sockets: [unix:///var/run/docker.sock tcp://0.0.0.0:2375]
I am trying to just installed a pre-built image using:
sudo docker pull busybox
I get this error:
sudo docker pull busybox
2014/08/18 17:56:19 Post http:///var/run/docker.sock/images/create?fromImage=busybox&tag=: dial unix /var/run/docker.sock: no such file or directory
Is something wrong with my docker setup?
When I do a docker pull busybox, It pulls the image and download is complete.
bash-3.2$ docker pull busybox
Pulling repository busybox
a9eb17255234: Download complete
fd5373b3d938: Download complete
d200959a3e91: Download complete
37fca75d01ff: Download complete
511136ea3c5a: Download complete
42eed7f1bf2a: Download complete
c120b7cab0b0: Download complete
f06b02872d52: Download complete
120e218dd395: Download complete
1f5049b3536e: Download complete
bash-3.2$ docker run busybox /bin/echo Hello Doctor
Hello Doctor
Am I missing something?
You don't need to run any docker commands as sudo when you're using boot2docker as every command passed into the boot2docker VM runs as root by default.
You're seeing the error when you're running as sudo because sudo doesn't have the DOCKER_HOST env set, only your user does.
You can confirm this by doing a:
$ env
Then a
$ sudo env
And looking for DOCKER_HOST in each output.
As for having a docker file that runs your script, something like this might work for you:
Dockerfile
FROM busybox
# Copy your script into the docker image
ADD /path/to/your/script.sh /usr/local/bin/script.sh
# Run your script
CMD /usr/local/bin/script.sh
Then you can run:
docker build -t your-image-name:your-tag .
This will build your docker image, which you can see by doing a:
docker images
Then, to run your container, you can do a:
docker run your-image-name:your-tag
This run command will start a container from the image you created with your Dockerfile and your build command and then it will finish once your script.sh has finished executing.
You can quickly setup your environment using shellinit
At your command prompt execute:
$(boot2docker shellinit)
That will populate and export the environment variables and initialize other features.
docker pull will fail if docker service is not running. Make sure it is running by
:~$ ps aux | grep docker
root 18745 1.7 0.9 284104 13976 ? Ssl 21:19 0:01 /usr/bin/docker -d
If it is not running, you can start it by
sudo service docker start
For Ubuntu 15 and above use
sudo systemctl start docker
On my MAC when I start boot2docker-vm on the terminal using
boot2docker start
I see the following
To connect the Docker client to the Docker daemon, please set:
export DOCKER_CERT_PATH=<my things>
export DOCKER_TLS_VERIFY=1
export DOCKER_HOST=tcp://<ip>:2376
After setting these environment variables I was able to run the build without the problem.
Update [2016-04-28] If you are using a the recent versions of docker you can do
eval $(docker-machine env) will set the environment
(docker-machine env will print the export statements)
I also got this error. Though, I did not use boot2docker but just installed "plain" docker on Ubuntu (see https://docs.docker.com/installation/ubuntulinux/).
I got the error ("dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?") because the docker daemon was not running, yet.
On Ubuntu, you need to start the service:
sudo service docker start
See also http://blog.arungupta.me/resolve-dial-unix-docker-sock-error-techtip64
For boot2docker on Windows, after seeing:
FATA[0000] Get http:///var/run/docker.sock/v1.18/version:
dial unix /var/run/docker.sock: no such file or directory.
Are you trying to connect to a TLS-enabled daemon without TLS?
All I did was:
boot2docker start
boot2docker shellinit
That generated:
export DOCKER_CERT_PATH=C:\Users\vonc\.boot2docker\certs\boot2docker-vm
export DOCKER_TLS_VERIFY=1
export DOCKER_HOST=tcp://192.168.59.103:2376
Finally:
boot2docker ssh
And docker works again
In Linux, first of all execute sudo service docker start in terminal.
If you're using CentOS 7, and you've installed Docker via yum, don't forget to run:
$ sudo systemctl start docker
$ sudo systemctl enable docker
This will start the server, as well as re-start it automatically on boot.
To setup your environment and to keep it for the future sessions you can do:
echo 'export DOCKER_HOST="tcp://$(boot2docker ip 2>/dev/null):2375";' >> ~/.bashrc
Then:
source ~/.bashrc
And your environment will be setup in every session
The first /var/run/docker.sock refers to the same path in your boot2docker virtual machine. Correcly write for windows /var/run/docker.sock
You, maybe the not the OP, but someone may have a directory called /var/run/docker.sock/ already due to how many times you hack and slash to get things right with docker (especially noobs). Delete that directory and try again.
This helped me on my way to getting it to work on Centos 7.
I have installed the docker using offline method and post server restart docker is not running.
So, I executed the below command it worked for me!
/usr/bin/dockerd > /dev/null
run the following commands, OS = CentOS / RHLE / Amazon Linux, etc.
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker
chmod 777 /var/run/docker.sock

Resources