RWDevCon 2017 Vault - Bundle | Ray Wenderlich


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4250-rwdevcon-2017-vault-tutorials/lessons/22

Hello Mic,

First, thanks to you and Ray for the great example of the Perfect/Docker presentation. These kind of presentations allow me to learn from home :blush:

I have a question but I am not sure if it is going to sound like a stupid question, so please bare with me.

I have a home web server (apache2/php/mysql set up running on Ubuntu) and I built a simple App which talks to the server to function similarly to how the Acronym web-app works. For example, the App receives JSON file from a PHP page on my server to load data from MySQL database. It also sends CRUD operation via PHP scripts back to the server to modify the database. I can do this locally and also over the internet.

After seeing how swift Package and Docker can simplify this process, I was wondering if I can do this using swift Package/Docker instead. For example code/build it on my Mac then deploy the Docker image/container on an ubuntu home server and “expose it” so my iPhone application can send/receive data locally and externally? (i.e HTTPRequests/Responses, JSON files etc…). That would be awesome if this can be done!!

Thank you.

Hello again,

I had a feeling this question was stupid hehe… So after digging around I realised this is pretty much what was built! all I had to do is forward the ports so I can access it externally. I guess its time to learn more about Perfect, Mustache and Docker and if I can introduce security to my web app.

So can I open the acronyms database and see what is in it? I just couldn’t find it in the data folder!

Thank you :ok_hand:

Nice work @hazman! :thumbsup:

Apologies I wasn’t able to reply sooner. Feel free to ask any other questions you may have about Docker.

Thanks for the reply,

Actually I do have a question, in the .env file you placed the data in: PGDATA=/var/lib/postgresql/data/acronyms which created the data folder.

so we have the db name, username, and password, but how do I access the actual database? for example I wanted to open it in Liya to see what is in the acronym database. I tried to find it in the data folder but I couldn’t find an: acronym database…

You would need to expose the port PostgreSQL is running on, which by default is 5432, and then connect to it using localhost as the host, and 5432 as the port. The username, password, and database would be the same as what’s in the .env file.

Thanks Mic,

I will give this a go and see how I go. Sorry about all these questions but I am new to Docker.

I tried to build another application and when I tried to deploy it using Docker it complained that port 80 was already being used by the til project. So I am guessing I can’t deploy more than one app to localhost:80?

I was able to deploy it to localhost:81. Does Docker has anyway of allowing multiple containers on the same port?

Thanks.

Hi @hazman—this isn’t a Docker limitation, this is a restriction imposed by your OS. If more than one service or application was able to listen on the same port, how would the OS know where to direct the messages? :]

If you want to use port 80 then you could always stop the til container running using docker stop <container name> before starting another container that wants to use the same port.

HI @micpringle,

Thanks for the quick reply. I was hoping there was a magic fix for this problem lol. So now I am just reading on how I can deploy the container on different ports then use reverse proxy. I hope it work.

Thanks.

@hazman I can vouch for this approach, since it’s exactly what we use at raywenderlich.com. We have an nginx container listening on 80, which proxies the request to the correct container based on the domain of the request.

1 Like

@micpringle

The article I found also explained how to do it using Nginx. I tried with Apache on my first attempt failed (as usual) So I am going to keep trying to figure it out. Otherwise I may swap Apache with Nginx.

It would be great if raywenderlich.com do a Docker course for those kind of things :smirk: