I need to install docker and login to my repository in one script. I'm using ubuntu 16.04 but could also use 18.04.
docker_setup.sh:
sudo apt-get install -y docker.io
sudo service docker start
sudo usermod -a -G docker ubuntu
exec sudo su -l ubuntu
docker login -u $DOCKER_USER -p $DOCKER_PW
This does not work in a shell script because the sudo su
command opens up a subshell. I cannot do newgrp docker
for the same reason. Also, I cannot do something like
newgrp docker << DOCKERSUBHSELL
docker login -u $DOCKER_USER -p $DOCKER_PW
DOCKERSUBSHELL
because I am using the ray library, and a later part of the library (that works under the hood) also expects to be able to use docker commands. Is there a solution for this?