docker / docker-install

Docker installation script
https://get.docker.com
Apache License 2.0
2.46k stars 783 forks source link

how to export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock using shell script automatically. #147

Open rt7055 opened 5 years ago

rt7055 commented 5 years ago

Hi,

I would like to automate these steps to install docker as the rootless user for that I've created shell script.but while doing echo "export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock" using shell script it is not working.on manual, it is working fine.

export USERID=$( id |grep uid | awk -F '[ ]' '{print $1}' | awk -F '[(]' '{print $1}'| awk -F '[=]' '{print $2}')
    sudo apt-get install -y uidmap
    curl -fsSL https://get.docker.com/rootless | sh
    echo "DOCKER_HOST=unix:///run/user/${USERID}/docker.sock">>~/.bashrc
    systemctl --user status docker
    systemctl --user start docker

Even though if I export this value to ~/.bashrc, it is not showing in system environment. Could you please let me know how I can automatically add this value as env on the ubuntu machine. Thanks Rohit Thakur.

AkihiroSuda commented 4 years ago

~/.bash_profile may work for you.

AkihiroSuda commented 4 years ago

Also, you don't need to grep/awk for the uid. id -u should work.

StableBoyNZ commented 3 years ago

Here's what I've done and wanting a solution:

  1. Created a user 'docker' on my CentOS 7.9.
  2. Ran the curl -fsSL https://get.docker.com/rootless | sh
  3. Created /etc/systemd/system/docker-rootless.service as root with below contents: `[Unit] Description=Docker Rootless Startup After=network.target

[Service] Type=simple ExecStart=/usr/bin/su -c /home/docker/bin/dockerd-rootless.sh - docker TimeoutStartSec=0

[Install] WantedBy=default.target`

  1. Ran systemctl daemon-reload
  2. Last but not least, systemctl enable docker-rootless.service which created the symlink.
  3. Reboot.

However, the dockerd-rootless.sh runs, gets a PID but when running docker ps it returns: Cannot connect to the Docker daemon at unix:///docker.sock. Is the docker daemon running?

I've tried adding: export DOCKER_HOST=unix:///run/user/1001/docker.sock export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock

to the .bashrc of the docker user.

Any help would be greatly appreciated. Cheers.