Skip to content

Instantly share code, notes, and snippets.

@moylop260
Last active November 22, 2020 19:04
Show Gist options
  • Save moylop260/e30def315524e96c8021e1623593391e to your computer and use it in GitHub Desktop.
Save moylop260/e30def315524e96c8021e1623593391e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Create a docker-machine in the client side
# Before install docker-maching https://docs.docker.com/machine/install-machine/
export SERVER_IP=192.168.1.X
export SSH_USER=hbto
export MACHINE_NAME=${USER}pc
export SSH_PORT=22
export DOCKER_PORT=2376
echo '${SERVER_IP} ${MACHINE_NAME}' | sudo tee -a /etc/hosts # Si cambia esta IP, hay que actualizar este archivo también
docker-machine create --driver generic --generic-ip-address=${MACHINE_NAME} --generic-ssh-user=${SSH_USER} --generic-ssh-port=${SSH_PORT} --generic-engine-port=${DOCKER_PORT} ${MACHINE_NAME}
#!/bin/bash
# Enable docker daemon to run in one PORT in the server side
# More info:
# https://github.com/moby/moby/issues/22339#issuecomment-225437878
# Before install docker: https://docs.docker.com/engine/install/ubuntu/
cat """
{
"hosts": [
"tcp://0.0.0.0:2376",
"unix:///var/run/docker.sock"
]
}
""" | sudo tee /etc/docker/daemon.json
sudo mkdir /etc/systemd/system/docker.service.d && \
cat """
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd
""" | sudo tee /etc/systemd/system/docker.service.d/docker.conf
# Fix error if user is not sudoer to use docker-machine as daemon
# https://github.com/alexellis/k3sup/issues/100#issuecomment-719095037
sudo usermod -aG docker $USER
echo '$USER ALL = (ALL) NOPASSWD: ALL' | sudo tee /etc/sudoers.d/$USER
sudo chmod 0440 /etc/sudoers.d/$USER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment