HOWTO: Access docker remotely


Recommended Posts

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.

  • Thanks 2
Link to comment

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.

Link to comment

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.

Link to comment

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.

Link to comment

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.

Link to comment
  • 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?

 

Link to comment

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

 

Link to comment

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
Link to comment
  • 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.

Link to comment
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.

Link to comment

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.