Jump to content

creating your own docker containers - howto


Recommended Posts

I have been trying to figure out how to add my own containers to Unraid and I couldn't find all the docs in one place.  These instructions include creating a docker image, using your own docker registry instead of dockerhub, and incorporating your image into the private apps section of Community Apps where it can be installed and maintained like any other docker container.  I hope this helps someone.

 

The example used here is a QR code generator I made.  It takes a string and when you submit the form it just shows the qrcode image in the browser.  I use the letsencrypt docker to proxy to it.

 

Set up your docker image.  I just use a Dockerfile, I think docker-compose is the more modern way.

Here is the Dockerfile:

FROM node:12.9.1
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY server.js .
EXPOSE 3016
CMD [ "node", "server.js" ]

Here is package.json:

{
  "name": "qrcode",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "qrcode": "^1.4.4"
  }
}

Here is server.js:

const express = require('express')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.urlencoded({ extended: false }))
const QRCode = require('qrcode')

app.post('/qr/qrpost', (req, res) => {
        QRCode.toDataURL(req.body.qrstring, (err, image) => {
                const arr = image.split(/,/);
                const buf = Buffer.from(arr[1], 'base64');

                res.set({ 'Content-Type': 'image/png'});
                res.send(buf);
        });
});

app.listen(3016);

Create a docker image for this:

docker build -t yourname/qrcode .

If you wanted to run it and test it you would do:

docker run --net=yourprivatenet -h qrcode --name qrcode -d yourname/qrcode

At this point you could just be done.  The container will work fine, and you can see it in the Docker tab in Unraid.  You just can't do much with it from there.  I wanted to have my own containers controlled through the Unraid interface just like containers installed from Community Apps.

 

If you continue make sure you get the container id from docker ps and then:

docker stop $id && docker rm $id

I wanted to maintain my own docker registry instead of using dockerhub.  If your image is on dockerhub then you can skip this part:

 

Save this xml into a file called registry.xml.  (The icon is bogus, sorry.  I am too lazy to put the right one.)

<?xml version="1.0" encoding="utf-8"?>
<Container>
<Beta>False</Beta>
<Category>HomeAutomation:</Category>
<Date>2020-04-01</Date>
<Changes>
[b]1.APR.2020:[/b]Added[br]
</Changes>
<Support>https://docs.docker.com/registry/</Support>
<Name>Docker Registry Docker</Name>
<Description>
The Registry is a stateless, highly scalable server side application that stores and lets you distribute Docker images.[br][br]
This is the from the Docker team - I just created the template.[br][br]
</Description>
<Registry>https://docs.docker.com/registry/</Registry>
<GitHub>https://github.com/</GitHub>
<Repository>registry:2</Repository>
<BindTime>true</BindTime>
<Privileged>false</Privileged>
<Networking>
  <Mode>bridge</Mode>
  <Publish>
    <Port>
      <HostPort>5000</HostPort>
      <ContainerPort>5000</ContainerPort>
      <Protocol>tcp</Protocol>
    </Port>
  </Publish>
</Networking>
<Data>
  <Volume>
    <HostDir>/mnt/cache/appdata/DockerRegistry</HostDir>
    <ContainerDir>/var/lib/registry</ContainerDir>
    <Mode>rw</Mode>
  </Volume>
</Data>
<Banner>http://i.imgur.com/zXpacAF.png</Banner>
<Icon>http://i.imgur.com/zXpacAF.png</Icon>
</Container>

Create a directory on the usb stick that community apps will use (I'm actually not sure if this persists through reboots and Unraid upgrades):

mkdir -p /boot/config/plugins/community.applications/private/myrepo

Then copy that xml there:

cp registry.xml /boot/config/plugins/community.applications/private/myrepo

Now when you go to the Apps tab in Unraid you will see Private Apps on the left side.  Install the registry you set up there with defaults.  You can change the port from 5000 if you are already using it for something else.  Just remember to change 5000 in later instructions to that port.

 

Tag your qrcode (or whatever) image and push it to your registry:

docker image tag yourname/qrcode localhost:5000/qrcode
docker push localhost:5000/qrcode

(I think it is probably safe to docker rmi $imageid to remove the image you created earlier since it is now in your own registry.  I didn't test that yet.)

 

In the rest of the instructions that is how you refer to the image.  So if you had it uploaded to dockerhub it would be yourname/qrcode but if you have it in your own registry it would be localhost:5000/qrcode.

 

Now you create an xml file for your app, qrcode.xml or whatever.  Edit it for your app:  (Again, the icon is bogus.  Use a proper icon.)

<?xml version="1.0" encoding="utf-8"?>
<Container>
<Beta>False</Beta>
<Category>HomeAutomation:</Category>
<Date>2020-04-01</Date>
<Changes>
[b]1.APR.2020:[/b]Added[br]
</Changes>
<Support>http://forums.unraid.net</Support>
<Name>QRcode</Name>
<Description>
QRcode will take a string and return the QRcode image[br][br]
QRcode will run on port 3016.[br][br]
</Description>
<Registry>http://unraid:5000/qrcode/</Registry>
<GitHub>https://github.com/</GitHub>
<Repository>localhost:5000/qrcode</Repository>
<BindTime>true</BindTime>
<Privileged>false</Privileged>
<Networking>
  <Mode>bridge</Mode>
  <Publish>
    <Port>
      <HostPort>3016</HostPort>
      <ContainerPort>3016</ContainerPort>
      <Protocol>tcp</Protocol>
    </Port>
  </Publish>
</Networking>
<WebUI>http://[IP]:[PORT:3016]</WebUI>
<Banner>http://i.imgur.com/zXpacAF.png</Banner>
<Icon>http://i.imgur.com/zXpacAF.png</Icon>
</Container>

Copy that xml to where Community Apps can find it:

cp qrcode.xml /boot/config/plugins/community.applications/private/myrepo

Reload that tab.  Install your app (set the network to your private net).  Done.  Whew.  So much hassle, haha.  Good luck!

 

And I'm already back.  I forgot, if you actually want to try out the qrcode app you will need this qrcode.html:

<html><head></head><body>
Enter string to qrencode:<br>
<form action='/qr/qrpost' method='POST'>
  <input type='text' name='qrstring' id='qrstring'/>
</form>
</body></html>

Copy that to your letsencrypt nginx document root:

cp qrcode.html /mnt/user/appdata/letsencrypt/www

And the qrcode.subfolder.conf

location ^~ /qr/qrpost {
    include /config/nginx/proxy.conf;
    resolver 127.0.0.11 valid=30s;
    proxy_pass http://QRcode:3016;
}

Copy that to your letsencrypt nginx proxy-confs:

cp qrcode.subfolder.conf /mnt/user/appdata/letsencrypt/nginx/proxy-confs

And restart your letsencrypt docker.  Go to yoursite.com/qrcode.html, type in some words and hit enter to submit.  Voila!

 

I apologize for any mistakes.  Let me know so I can fix them.

Edited by uek2wooF
made first paragraph more descriptive. fixed port number
  • Like 1
  • Thanks 1
Link to comment
  • 4 weeks later...
  • 2 years later...

are you still working on figuring it out? Ive been wondering as well, since some apps just have badly updated containers in the CA.

On 4/30/2020 at 7:04 AM, uek2wooF said:

So the question now is how to do updates to the app.  I did a new image build with docker build, did the tag and push so it is in the repo, but I don't know what to do so it can be upgraded with community applications.  Any ideas?

 

Link to comment

Is your registry container running? Should just work. What happens if you switch the docker page to advanced and click force update? That'll pop the docker output so may give some hints about what goes wrong

 

Notes for others reading this, the Docker registry is in CA, no (more?) need to make your own template for it. 

Link to comment

I use the "DockerRegistryDocker" and yes it is running.  After "force update" the commands run successfully and it says up-to-date, but then if I check for updates it says "not available" again.  I am not sure what is going on behind the scenes so it is hard to troubleshoot this.

 

When you say a template is not needed, are you talking about that registry.xml?  Without it I don't get my repo in the private repositories in community apps (6.9.2).

Link to comment
16 minutes ago, uek2wooF said:

When you say a template is not needed, are you talking about that registry.xml?  Without it I don't get my repo in the private repositories in community apps

Correct. You would obviously want your qrcode.xml in there but registry isn't needed since it's available in CA, at least on 6.10.

Link to comment
  • 1 year later...

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.

×
×
  • Create New...