Jump to content

HOWTO: Access docker remotely

Featured Replies

Posted

I'd like to move my development off of my unraid server. Has anyone worked through setting up TLS on the daemon, so that you connect remotely?

 

Edit: I figured it out, so I'll edit this top post to be a HOWTO.

 

First, I didn't bother setting up security because docker is only exposed on my LAN. If you want security, check out the Docker docs.

 

[*]On your unraid sever, edit /boot/config/docker.cfg, adding two -H options:[br]

DOCKER_OPTS="--storage-driver=btrfs -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375"

 

[*]On your remote machine, install the docker client. Then either add the -H tcp://tower:2375 option to your docker command, or put export DOCKER_HOST=tcp://tower:2375 into your ~/.bashrc.

 

When you're done, you can run "docker ps", "docker build" or whatever from your dev machine, with all the action happening on your unraid server. I like this better because I'm on my normal dev machine, with github credentials, my favorite GUI editor, etc.

How do you build the Dockers in this fashion?

 

I create a repo in Github, start with a similar dockerfile and add anything needed. I then create a new Auto Build repo in dockerhub. There is a lot of trial and error... If there is a better work flow, I would love to know about it.

How do you build the Dockers in this fashion?

 

I create a repo in Github, start with a similar dockerfile and add anything needed. I then create a new Auto Build repo in dockerhub. There is a lot of trial and error... If there is a better work flow, I would love to know about it.

 

for me, i have a ubuntu 14.04 VM that i've installed docker in, following the instructions on the docker website.

 

then i write a dockerfile (got enough now that a lot of it is copy paste, dependant on type) and build it on the VM.

 

that's 1 way, if it's a tougher docker, i fire up a container with just bash and try to build from straight linux commands, then play them back to create the dockerfile once i've found what works.

  • Author

Do you literally build and run them in the VM, or have you set DOCKER_OPTS="-H tcp://tower..." so that the containers run in unraid? That's what I was planning to do, since I have one or two containers that I may not share on Docker hub.

Do you literally build and run them in the VM, or have you set DOCKER_OPTS="-H tcp://tower..." so that the containers run in unraid? That's what I was planning to do, since I have one or two containers that I may not share on Docker hub.

 

 

manually create the container on the unraid box itself and you can stop/start it from the dashboard like any other container. only thing i found doing it like that (or at least the last time i did) is that you get an orphan image for the base build that isn't easily deletable because unraid thinks it's in use by other dockers that may use the same base image.

  • 5 years later...
On 6/23/2015 at 6:09 AM, coppit said:

*]On your unraid sever, edit /boot/config/docker.cfg, adding two -H options:[br]

DOCKER_OPTS="--storage-driver=btrfs -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375"

Is this still the right way to do it? I haven't been able to find any other information about it and this thread is 5 years old. So I'm worried the solution is outdated.

 

The description above seems to suggest that DOCKER_OPTS is already defined in docker.cfg. However, my docker.cfg for Unraid version 6.9.0-beta35 does not define it. So I figured it was best to define it with only the two -H options:

DOCKER_OPTS="-H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375"

Is this the right approach today?

 

Also, are these kinds of edits to the config files preserved when upgrading Unraid?

 

After investigating a bit more I have figured out that a better way to access the Unraid docker host is via SSH. This requires no extra docker configuration on the Unraid side. You just need to use SSH key-based authentication and then connect either using the -H option to the docker command or setting the DOCKER_HOST environment variable in your local shell.

 

For example:

docker -H ssh://your-unraid-server ps

Or using DOCKER_HOST:

export DOCKER_HOST=ssh://your-unraid-server

docker ps

 

I just edited the script rc.docker
 

I didn't add to the $DOCKER_OPTS variable but I did change the line that starts docker to hardcode the -H parameters, like this:

nohup $UNSHARE --propagation slave -- $DOCKER -p $DOCKER_PIDFILE $DOCKER_OPTS -H unix:///var/run/docker.sock -H tcp://IP_ADDRESS:PORT_NUMBER>>$DOCKER_LOG 2>&1 &

 

IP_ADDRESS being the ip of the unraid server

 

I changed this for all of my unraid servers and they all listen on port PORT_NUMBER

 

This works great and my code can now access and manage all the docker hosts and the containers within

 

I was thinking of changing  the script to read "DOCKER_OPTS" from the cfg file, but never got around to it.

 

It would be extremely helpful if the "DOCKER_OPTS" setting was supported by default.

Edited by piyper

  • 4 weeks later...
On 11/27/2020 at 9:57 PM, piyper said:

I just edited the script rc.docker
 

I didn't add to the $DOCKER_OPTS variable but I did change the line that starts docker to hardcode the -H parameters, like this:

nohup $UNSHARE --propagation slave -- $DOCKER -p $DOCKER_PIDFILE $DOCKER_OPTS -H unix:///var/run/docker.sock -H tcp://IP_ADDRESS:PORT_NUMBER>>$DOCKER_LOG 2>&1 &

 

IP_ADDRESS being the ip of the unraid server

 

I changed this for all of my unraid servers and they all listen on port PORT_NUMBER

 

This works great and my code can now access and manage all the docker hosts and the containers within

 

I was thinking of changing  the script to read "DOCKER_OPTS" from the cfg file, but never got around to it.

 

It would be extremely helpful if the "DOCKER_OPTS" setting was supported by default.

Thank you! Seems like there's not a lot of information on how to do this around, so I was glad to find your solution. It worked for me on Unraid 6.8.3.

On 6/23/2015 at 6:09 AM, coppit said:

[...]

[*]On your unraid sever, edit /boot/config/docker.cfg, adding two -H options:[br]

DOCKER_OPTS="--storage-driver=btrfs -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375"

 

[...]

 

Thanks for that. That almost worked for me, all I had to do differently is to switch to port 2376.

  • 2 years later...

To monitor my docker containers on my second Unraid server with Uptime Kuma, I added

DOCKER_OPTS="-H unix:///var/run/docker.sock -H tcp://192.168.0.14:2375"

To my /boot/config/docker.cfg file.

(It also worked with 0.0.0.0, what's the difference?)

  • 3 months later...

When I add this to my docker.cfg docker fails to start. I haven't had time to look into it yet, but does this method still work?

This topic is helpful.

This is still the right approach today.

①Add it to config file  /boot/config/docker.cfg

DOCKER_OPTS="--storage-driver=btrfs -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375"

②restart dockerd service in terminal.

/etc/rc.d/rc.docker restart

 

  • 4 months later...

Its not working unfourtunately. Something wrong?

 

1.png

2.png

  • 2 weeks later...

Someone can have a quick look?

  • 3 weeks later...
On 2/11/2024 at 5:10 AM, PlanetDyna said:

Someone can have a quick look?

I believe you are missing the storage-drive option:

DOCKER_OPTS="--storage-driver=btrfs -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375"

 

Thank you. I will test it next days!
Working! I missed change connection-type to "TCP/HTTP".

Edited by PlanetDyna

  • 8 months later...

This post was helpful thank all! 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...