logout/login from inside Vagrantfile - docker

I'm currently trying to finish a Vagrantfile to be used as a docker host by other Vagrantfiles running the docker provider (https://www.vagrantup.com/docs/docker/).
I am using centos/atomic-host as a base box. The problem is that when I run vagrant up I get:
A Docker command executed by Vagrant didn't complete successfully!
The command run along with the output from the command is shown
below.
Command: "docker" "ps" "-a" "-q" "--no-trunc"
Stderr: Cannot connect to the Docker daemon. Is the docker daemon running on this host?
And this is due to the vagrant user not being part of the docker group. I solve this by adding this to my Vagrantfile:
# Add user vagrant to docker group
$docker_group = <<-DOCKER_GROUP
groupadd docker
usermod -a -G docker vagrant
systemctl restart docker
DOCKER_GROUP
config.vm.provision "docker_group", type: "shell", privileged: true, inline: $docker_group
I still get the exception above the first time I run vagrant up but it works from the second time onwards. The reason I suspect is that after adding the vagrant user to the docker group I need to logout/login for the changes to take effect.
For the record, I tried adding newgrp docker at the end of the my $docker_group script but it doesn't solve the problem. I suspect the docker provider starts a separate session.
Anybody found a solution for this?

I am not aware of Vagrantfile, but what I understand from your question is that you need some way to refresh a user's group without having to re-login.
If that's the case, the following points may help you:
Why not just su to the user again: you may just login in to the user again, and all the user's group will be updated.
Or you may try the this approach Legooolas has mentiones.
I hardly think the problem you mentioned is with the Vagrantfile, it's just the way it is. To update user's configurations, you need to re-login with the user. Still, if you wish to find a way, the above two might help you out.

Related

configuring docker to put files [duplicate]

This question already has answers here:
How to fix docker: Got permission denied issue
(33 answers)
Closed 1 year ago.
I was just getting started with docker, and I run this:
docker pull redis
and I get a permission denied error. It turns out, docker writes to /var/* directories, which requires permission to write. and so many other docker commands also require something like:
sudo docker ***
Now, I don't really like the notion of add root privileges to every docker command.(It might be because I just don't know docker much yet, but that's true with every program). Is this a requirement by docker?
If it is not required, then how do I configure it so that it is much like other programs, that only ask me privileges when they need to, all the pulling, running commands would just write to my normal directories or run from them, not from a system directory.
EDIT: my concern was, if docker was allowed access to system files, meaning, it has some embedded scipt that had a potential harm to the computer, and it executed when I ran the docker. Since, I give it root privileges, the script could do anything. Would adding it to the user group instead of sudo fix that?
By default Docker runs an always-on daemon on your system which requires root privileges (Experimental non-root Docker support exists though).
The common approach is to add your User to the docker group which allows you to run docker without having to sudo: https://docs.docker.com/engine/install/linux-postinstall/
sudo usermod -aG docker $USER
newgrp docker
If you are interested in non-root Docker the following might be interesting:
https://podman.io/
https://docs.docker.com/engine/security/rootless/
You are not probably part of docker group as user. You could try post-installations steps mentioned on here.
Create group docker:
sudo groupadd docker
Add user to the group
sudo usermod -aG docker $USER
Reload changes:
newgrp docker

How to reset couchbase docker container password

I have installed 3 couchbase nodes of docker containers. After a couple of weeks when i tried to log in i could not remember my admin password. After a research i can not find a way to reset password. I am a newcomer to docker world so maybe i missed something. There is a source below but i believe that does not compromise my problem. How can i reset admin password ?
source
The only way to reset your admin password that I'm aware of is to use couchbase-cli's reset-admin-password option, which must be run locally.
Since you are in docker, one option would be to execute bash inside of Docker, and run couchbase-cli there. For instance:
docker exec -it db /bin/bash
At that point, you should have a bash prompt, and you can run couchbase-cli there.
I found a solution and wanted to share you all. After i clicked docker dashboard via docker gui i went for the container's bash then executed codes below.
couchbase-cli reset-admin-password --new-password 123456
Above Mr. Matthew clues us in with a more sophisticated way of going for container's bash.

docker: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?

I've really tried tons of solvings but nothing work for me . Maybe because I use WSL for window (ubuntu 18.04) , but I'm not sure . Pls if someone solved this issue . let me know
My ubuntu data:
I've used this tutorial for installation, but also earlier I was using official tutorial , but it give me the same issue:
https://linuxize.com/post/how-to-install-and-use-docker-on-ubuntu-18-04/
The issue is most likely that you are trying to use docker as a standard user who doesn't belong to the docker group, instead as root.
First, check whether the service is indeed running with systemctl status docker.service.
If the service is running, try to run the same container, but as root.
If it's working as root, then just add your user to the docker group, and that's it. usermod -a -G docker andreyradkevich

Run docker without "sudo" in Fedora 24

Although this post is tempted to be closed for many I should ask what I am doing wrong since I am getting crazy and can't find a solution.
I have installed Docker in Fedora 24 and everything seems to be fine but I can't run docker command without sudo and that's annoying (at least for me).
I am logged as a normal user (non-root) and as soon as I run a command I can see this message:
$ docker ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
However if I run only docker I can see a list of possible commands :-\
I've followed this guide and I read also a lot (here is a small list):
http://bsaunder.github.io/2014/12/21/running-docker-without-sudo/
Running Docker as non-root user
How to run docker image as a non-root user?
But certainly I am missing something, can any illuminate me? What I am missing here? I know the problem become user has not permissions to /var/run/docker.sock but what's the fix?
Running docker to get the list of commands doesn't use a connection to the daemon, which is why you can run it as non-root.
Have you added your user to the docker group?
sudo usermod -aG docker <my-user>
If you do that, next time you log in you should be able to use the docker CLI without sudo. But beware that the docker group has root privileges, so this is a convenience but not a security improvement.

How to "start over" with Docker?

I am trying to run Tomcat in a Docker container with limited success. After I tried various things, I wanted to "reset" without completely deleting everything. I did stop and remove the virtual machine from the Virtualbox console. I then tried docker-machine create and docker-machine restart. My question is, if things reach a state in which the application appears to be hanging, what is the best procedure for starting from scratch that does not involve, for example, actually rebuilding the Docker container?
EDIT: All I am now asking is, given that "docker version" returns Client information but when it reaches the Server information I get the "An error occurred trying to connect" message, is what now needs to be done? What is it not connecting to? I tried with apparent success "docker-machine restart" but got no further with "docker version" after that.
First, don't delete the boot2docker VM itself (created by docker-machine)
If you want to reset, you might have to delete the container and image (quickly rebuilt with a docker build). But you can stay in the same docker-based boot2docker VM. No need for deletion.
Retrying a docker container session simply involve killing/removing the current container, and doing a new docker run.
Then, don't forget check what is not working: does a docker ps -a shows your container running? Can you access Tomcat from the boot2docker Linux host? From your actual OS host?
Based on that diagnostic and the exact content of your Dockerfile, you will be able to debug the issue.
The main issue might come from the fact docker command are executed from outside the VM.
That works only if the commands from docker-machine env <machine-name> are set.
See docker-machine env:
For cmd.exe:
$ docker-machine.exe env --shell cmd dev
set DOCKER_TLS_VERIFY=1
set DOCKER_HOST=tcp://192.168.99.101:2376
set DOCKER_CERT_PATH=C:\Users\captain\.docker\machine\machines\dev
set DOCKER_MACHINE_NAME=dev
# Run this command to configure your shell: copy and paste the above values into your command prompt.
(replace "dev" by the name of your docker machine here, probably "default")
But it is also perfectly fine to make all docker command from within the VM. No "env" to set.
Everything is on the VM (images, Dockerfile which can be on the Windows host as well, as long as it is under C:\Users\<yourLogin>, since that folder is automatically mounted as /c/Users/<yourLogin>)

Resources