Sunday, 20 September 2020

Simple way to deploy docker app on production machine

Small software house house/freelancer life isn't easy. Reading HN post about fancy new tech is amusing but as much as it is nice to read as much it's often not reachable for team counting one person.
So whenever I read something new I ask myself this simple question.

Is that new thingy/tech single dev scalable ?

Let's consider a docker application deployment problem. It's hard to do it both: quick and good enough (production ready).

Later, when the app matures/goes bigger you can create a proper CI but at this very beginning you need something simple. Here is how I do deal with it.

First deploy a local registry server push your app image there, next create ssh tunnel and do remote port forward. Finally fetch image from registry and run the app.

Let's try it out line by line. I do assume you have a docker build image named my-image-app (either created with docker build or docker compose) and want to deploy it to customer's customer-server.address.net on port 8888 over ssh.

First create a new local docker registry server. As docker docs claims it's as simple as:

docker run -d -p 5000:5000 --restart=always --name registry registry:2
Ok your registry server is up and running. Next push your app image to this new registry.
To do that you need to tag my-image-app with a correct name including registry address  ( ie. localhost:5000).

docker tag my-image-app localhost:5000/my-image-app
and then push it to the registry server

docker push localhost:5000/my-image-app
Next connect to remote server via ssh with remote port forwarding

ssh -R 5001:localhost:5000 customer-server.address.net -p 8888
Now you are logged into remote server and your local machine's port 5000 is visible on the remote machine on port 5001.

Finally run your app on the remote machine:

remote-prompt: docker run -d --name my-app localhost:5001/my-image-app

App is running. We are done.

What we can do even better here, is to write you customer server settings into your local .ssh/config file:


host customer-server
 HostName customer-server.address.net
 Port 8888
 User user
 RemoteForward 5001 localhost:5000

Then connecting to remote server is as simple as:

ssh customer-server

You may also consider adding your public key to  .ssh/authorized_keys  on the remote server.

UPDATE: one crucial command connect via ssh was missing when published this first time
UPDATE1: fixed authorized_keys entry

12 comments:

  1. This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! Wicked woman

    ReplyDelete
  2. I found your this post while searching for some related information on blog search...This is a wonderful post,.. keep posting and update the information. AT&T Software is one of the leading web and mobile app development company

    Hire Wordpress Developer

    ReplyDelete
  3. Very useful and knowledgeable. Really its Great Article. Keep it up. A complete APP solution for dokan marketplace for your customer, vendor, and Driver.

    Dokan Apps

    ReplyDelete
  4. It is the kind of information I have been trying to find. Thank you for writing this information. It has proved utmost beneficial for me. Best sculpting machine

    ReplyDelete
  5. This may be the appropriate blog for everyone who is would like to find out about this topic. You realize a whole lot its virtually tricky to argue on hand (not that I personally would want…HaHa). You definitely put a fresh spin on the topic thats been revealed for a long time. Wonderful stuff, just great! get more details

    ReplyDelete
  6. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. Flutter App Development Company

    ReplyDelete
  7. Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging.. ajp150

    ReplyDelete
  8. China Longwell is a professional China EPS Machine, EPS moulding machine Supplier. We offer kinds of EPS machines, EPS moulding machine, EPS molds, 3D panel machines, sandwich panel machines, assistant facilities and all kinds of EPS machine spare parts Semi-Auto Shape Molding Machine

    ReplyDelete
  9. If the machine is beyond immediate repair, most rental companies will provide an equivalent replacement, so downtime for the organization is minimized. renting impresoras mallorca

    ReplyDelete
  10. China JIALITE is one of the leading Automatic pre-coating laminating machine, Water Base Oil Coating Machine, automatic coating machine Manufacturers,Factory and Suppliers, Our product quality has passed international certification, and the price is affordable, welcome to call and order our products wholesale. High Speed Automatic Thermal Laminating Machine

    ReplyDelete
  11. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work! flutter App Development Company in bangalore

    ReplyDelete
  12. Castle plaza is a real estate company from where you can take apartments for rent for short or long term.
    https://castlesplaza.com/apartment-for-rent-dubai/

    ReplyDelete

Simple way to deploy docker app on production machine

Small software house house/freelancer life isn't easy. Reading HN post about fancy new tech is amusing but as much as it is nice to read...