Install Docker script error - permission denied - docker

I'm trying to install Docker for CentOS 7 from the documentation but I got permission denied right away:
sudo curl -sSL https://get.docker.com/ | sh
sh: line 241: /etc/yum.repos.d/docker-main.repo: Permission denied

With your command line, you are only executing curl with sudo, not sh. Try this:
su -c "curl -sSL https://get.docker.com/ | sh"
or, if it does not work, e.g. because no root password is set on your system:
sudo su -c "curl -sSL https://get.docker.com/ | sh"

the doc at https://docs.docker.com/installation/centos/ begins with "Log into your machine as a user with sudo or root privileges." I guess you should begin with a privileged user, only then you can do curl -sSL https://get.docker.com/ | sh

Related

AWS EC2 /usr/bin/docker-compose: cannot execute binary file

I created an EC2 instance and installed docker on it, now I need to install docker-compose using SSM send-command and to do that I'm running the following command:
aws ssm send-command --instance-ids "${INSTACES_ID}" \
--document-name "AWS-RunShellScript" \
--parameters "commands=[
sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose,
sudo mv /usr/local/bin/docker-compose /usr/bin/docker-compose,
sudo chmod +x /usr/bin/docker-compose,
docker-compose --version
]"
The commands are executed correctly but the command docker-compose --version raises the following exception
"StandardErrorContent": "... /usr/bin/docker-compose: cannot execute binary file\nfailed to run commands: exit status 126"
I entered in EC2 via ssh the problem is the same, I also tried to give all permissions to bin file
$ ls -la /usr/bin | grep docker-compose
-rwxrwxrwx 1 ec2-user ec2-user 6204149 27 set 15.10 docker-compose
$ docker-compose --version
-bash: /usr/bin/docker-compose: cannot execute binary file

Docker mounted volume GID mismatch causes error: dial unix /var/run/docker.sock: connect: permission denied

Using the official jenkins image, I have installed docker and docker-compose and added jenkins to the docker group (GID 999 in the container).
After that, I shared the /var/run/docker.sock of the host so enable jenkins create "siblings" containers. It happens that the original file have GID 134 and with this GID is mounted. I am getting the following error:
demo_1 | docker: Got permission denied while trying to connect to the
Docker daemon socket at unix:///var/run/docker.sock: Post
http://%2Fvar%2Frun%2Fdocker.sock/v1.32/containers/create: dial unix
/var/run/docker.sock: connect: permission denied. demo_1 | See 'docker
run --help'.
Any idea about how to solve this?
My minimal (and not optimized yet) Dockerfile is:
FROM jenkins/jenkins:lts
USER root
RUN apt-get update && apt-get install -y apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"
RUN apt-get update
RUN apt-get install -y docker-ce docker-compose
RUN usermod -aG docker jenkins
USER jenkins
RUN newgrp docker
I have also created a docker-compose to test it:
version: '2'
services:
demo:
build: .
ports:
- 8080:8080
- 50000:50000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: >
/bin/sh -c "
set -e
groups
docker -v
docker-compose -v
ls -ln /var/run/docker.sock
id jenkins
docker run hello-world
"
The output is:
demo_1 | jenkins staff docker
demo_1 | Docker version 17.09.0-ce, build afdb6d4
demo_1 | docker-compose version 1.8.0, build unknown
demo_1 | srw-rw---- 1 0 134 0 Sep 30 07:36 /var/run/docker.sock
demo_1 | uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins),50(staff),999(docker)
demo_1 | docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.32/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
demo_1 | See 'docker run --help'.
I gave the problem a dirty fix, so I am letting this question open to see if a better one appears.
As the /var/run/docker.sock file is owned by root, which have the same UID, I added jenkins to the list of sudoers without need to type password:
RUN adduser jenkins sudo
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
This solved the issue. I dislike it, but it works.
you can create a group in dockerfile with the same group id as docker
https://stackoverflow.com/a/71085404/4791684

Signatures couldn't be verified because the public key is not available error while installing docker

Unable to install docker with:
sudo sh -c "echo deb https://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
error log:
GPG error: https://get.docker.com docker Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D8576A8BA88D21E9
Seems like the getting started page has changed.
Aug 2017
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
https://docs.docker.com/engine/installation/linux/docker-ce/debian/#install-using-the-repository
Aug 2019
The link to the installation page has changed again
https://docs.docker.com/install/linux/docker-ce/debian
If don't want to use those commands from manual http://docs.docker.com/linux/step_one/:
$ sudo apt-get update
$ sudo apt-get install wget
$ wget -qO- https://get.docker.com/ | sh
there is what you need:
$ wget -qO- https://get.docker.com/gpg | sudo apt-key add -
PS:
https://docs.docker.com/installation/debian/
The apt has a set of trusted keys and sometimes we only need to add the one that is missing.
You could have added the key just by running the following command:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D8576A8BA88D21E9
Greetings.
Got the solution, I was trying to install docker 1.5 on a 32-bit Ubuntu, whereas the documentation says it needs 64 bit Ubuntu.
check here in Prerequisites section

connect to docker's running container

I downloaded centos/centos7.1.1503 from docker's official hub, and created my custom dockerfile as below.
FROM centos:centos7.1.1503
RUN yum install -y passwd
RUN echo -e “root\nroot” | (passwd --stdin root)
RUN yum update -y
RUN yum install -y git-core build-essential libssl-dev
CMD /var/tmp | git clone git://git.openwrt.org/14.07/openwrt.git
I then ran the following 3 commands
docker build -t centos:test
docker run centos:test
docker attach <containerid>
It asks me for a password. The password i set in the docker file doesn't work at all. Any idea?
An idea is to change this line
RUN echo -e “root\nroot” | (passwd --stdin root)
to this one:
RUN echo root | passwd root --stdin
Otherwise you are trying to set root\nroot as your root password (including that strange newline).
An other try would be this (if you have xargsavailable):
RUN echo root | xargs passwd root

Install grails as another user with sudo

I want to install grails in my vagrant provision bootstrap bash file (which is executed as root). I tried to change the installation like shown on the grails manual:
curl -s get.gvmtool.net | sudo -u vagrant -H bash
sudo -u vagrant -H bash "$HOME/.gvm/bin/gvm-init.sh"
sudo -u vagrant -H bash gvm install grails
But this gives errors:
bash: /root/.gvm/bin/gvm-init.sh: Permission denied
bash: gvm: No such file or directory
what am I doing wrong?
This could work:
curl -s get.sdkman.io | sudo -u vagrant -H bash -i
sudo -u vagrant -H bash -i 'source "$HOME/.sdkman/bin/sdkman-init.sh"; sdk install grails'
The -i (simulate initial login) option
... This means that login-specific resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for
execution.

Resources