31
linuxxx
132d

"Let's create a docker-swarm cluster thingy for this application with horizontal scaling to learn docker and run this application better!"

This stuff is so overwhelming and I don't understand half of how to possibly set this up 😅

Comments
  • 3
    I tried dockerizing my Laravel site and couldn't get it to work after multiple days. :(
    Eventually just gave up.
  • 3
    @PrivateGER Yeah I'm already seeing that as a viable option as well 😅
  • 1
    I have a semi-popular open source project that is deployed using docker-compose... When it doesn't break its nicer than having to set up gunicorn and nginx and god knows what else just to test, but Holy hell is it a nightmare to maintain
  • 3
    @PrivateGER Just found this: https://katacoda.com/courses/docker

    Seems very useful to me!
  • 0
    @linuxxx I'll take a look, thanks.
  • 2
    But once it works...

    You'll never want to go back to the old days again :3
  • 4
    Once you get it ull enjoy it, especially for deployment, it's a matter of running docker compose file and it will setup rest of requirements.

    Consider learning docker as one of ur bash scripts u wrote that does routine stuff for you? You spend time writing it but saves u hours of useless routine.

    And the best of all, in real world, u stop currently running stable version and push new version to live server, of new one sucked? Stop it, run older container and system back online in no time (assuming it takes little time to start up)
  • 3
    @gitpush Fun thing is that I'm already stuck on getting my project running through php with specific extensions; pecl compilation seems to fail with a non descriptive error rendering it useless already 😅
  • 3
    For PHP, you can take a look at https://github.com/thecodingmachine... ex. Use them as base image...

    For an example docker-compose setup, https://phpdocker.io/generator might be of interest
  • 2
    @Wack Interesting! I just built an image thinking it was going well but apparently I'm doing something wrong and I don't understand the online explanations a single bit 😅
  • 0
    There are free IBM courses for docker, I liked then so far. Since I did them I use docker for everything 😂
  • 1
    📌
  • 0
    @linuxxx I'll throw in another wrench in the cog here... You need something to set up your swarm nodes as well. Check out Terraform. Infrastructure as Code, total sweetnes. If you use VMware vCenter, AWS, Open Stack, Virtual Box or what ever, they have an adapter for hooking up to their respective APIs. Just define what you need resourcse wise, how many instances of each, networking and what ever you need.

    Happy trails! 😊
  • 2
    @RagingCodeChimp For now I just need a few containers running my application 😄😅
  • 0
    @linuxxx Turtles all the way down 😉
  • 2
    @RagingCodeChimp I still haven't figured it out. Got a simple php application and need to fucking dockerize it but I just don't see what I'm doing wrong.
  • 0
    @linuxxx You copied in the code into the correct folder for nginx to find?
  • 1
    @RagingCodeChimp Yup, and its mounted well in the docker-compose file
  • 0
    @linuxxx the base image is prebuild php-fpm on nginx with sockets? Or homebrew?
  • 1
    @RagingCodeChimp Prebuilt php-fpm, listening on a port (or, supposed to), yeah
  • 2
    @linuxxx are you doing port forwarding from Host to the container?

    If you feel like, how about posting your docker-compose.yml file?
  • 2
    To get to the commandline within a container:

    `docker ps` (to see all currently running containers)
    `docker exec -it <id> /bin/bash` the I'd you get from docker ps, I think the first value for each. If your image is based in alpine, there usually is no bash, but you can use /bin/sh usually...

    If you don't see all containers you're expecting in the docker ps, try to Find out, why some aren't showing up.
  • 2
    @linuxxx yeah, like @Wack said. Time to show teh codez 😝🤓
  • 1
    @RagingCodeChimp I can't easily put those online without showing the entire project too badly.

    Managed to get stuff to run! Two issues/questions left:

    - application directory is mounted to the right local folder; will git pulls also make the container run the newly pulled code right away?

    - how on earth would I let the application image access the hosts databases?
  • 2
    To pull updated images from the registry, use `docker-compose pull` (note this will update ALL images, if you use ex. MariaDB:latest it will get updated too! Either specify the version or specify in the docker-compose pull, which images to pull, or use `docker pull` and pull only those you want)

    Next you'll need to restart to apply the update. The simplest solution would be `docker-compose down; docker-compose up -d`, however this will have a small downtime. You can use rolling updates with swarm: https://docs.docker.com/engine/...

    About your question of passing a host DB to the container. The simplest answer is to simply mount the socket from Host to container... Ex. `/var/run/mysqld:/var/run/mysqld` and call it a Day.

    Another option is to use IP based access: https://nickjanetakis.com/blog/... note: starting with docker 18.03 you can also use `host.docker.internal` as special domain, which will resolve to the hosts ip (https://stackoverflow.com/a/...)... Since you're using swarm, I'm not sure if this is what you want as there are potentially multiple hosts...
  • 1
    @Wack i would strongly advise against those two db suggestions. The former may expose you to runtime issues, and the latter defeats the whole purpose of microservice architecture. In my opinion, the best and most secure way to do this would be to include a mysql service container (here's the official one: https://hub.docker.com/_/mysql) and then follow their directions on how to mount JUST YOUR DATA directory into the container, make a new user with access only to that dir, and then make calls to that service inside the swarm. This way you have an isolated service with your data in tact and you're not running the db as root.

    Let me know if you have any questions, but this is pretty standard procedure. If you wanted to make the mysql image more secure i would grab an apparmor profile for it or/and an SElinux policy for it, but not running in the container as root should be sufficient.
  • 1
    @arcsector I didn't say they're best practice and agree with your suggestion, however this is how I'd so it with the restriction that the DB has to run on the host and not in a container.
  • 1
    @Wack my bad; i didnt get the impression from the thread that they were in the position that they just couldn't migrate to a db container backend... Is that true @linuxxx?
  • 1
    @arcsector I could, but I'm hardly familiar with docker yet so the chance of fucking something up is high for me right now.

    Also, I just prefer the database to be on the host system as for now as many more applications depend on this and I don't have time to reconfigure the mongo part at the moment.
  • 1
    @linuxxx if you've already got your configs, you can import a my.cnf file...
  • 0
    @arcsector why'd I need a my.cnf?
  • 0
    🌲🏕️
Add Comment