Editing Docker

From Bebot Wiki 2
Jump to navigationJump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
<pre>
+
 
                    ##        .       
+
 
              ## ## ##      ==       
 
          ## ## ## ##      ===       
 
      /""""""""""""""""\___/ ===     
 
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
 
      \______ o          /           
 
        \    \        __/           
 
          \____\______/         
 
</pre>
 
 
===== Preamble =====
 
===== Preamble =====
  
Line 38: Line 30:
  
  
Also notice that we'll often refer to "console" below. This is a text command line prompt we'll often need.
+
Just make sure you're properly installed then continue to next section.
 
 
For Linux/Mac it should be available into your shortcuts.
 
 
 
For Windows you'd have to open menu and type "cmd" or "powershell".
 
 
 
 
 
Just make sure you're installed and ready to type, then continue to next section.
 
  
  
 
===== DB prep =====
 
===== DB prep =====
  
Now we have to determine how to manage our DataBase. For the SQL there are three possibilites :
+
Now we have to determine how to manage our DataBase. For the SQL there are 3 possibilites :
  
SQL1: you already have an external server ; just make sure it's reachable (eg : ping its ip) from your host, and check if its facial port (usually 3306) is correctly opened.
+
1: you already have an external server ; just make sure it's reachable (eg : ping its ip) from your host, and check if its facial port (usually 3306) is correctly opened.
  
SQL2: you opted for a local service on host ; so you'd usually go for usual SQL port (3306) but instead of 127.0.0.1 default ip we'd advice you default docker0 network ip 172.17.0.1
+
2: you opted for a local service on host ; so you'd usually go for usual SQL port (3306) but instead of 127.0.0.1 default ip we'd advice you default docker0 network ip 172.17.0.1
  
SQL3: you are about to run a container for that ; you can skip this part fully as we'll explain you how to set this up correctly later in "build" section, it's the simplest in fact !
+
3: you're about to run a container for that ; you can skip this part fully as we'll explain you how to set this up correctly later in "build" section, it's the simplest in fact !
  
  
Here some command or documentation to verify elements for cases SQL1/2 :
+
Here some command or documentation to verify elements for cases 1/2 :
  
 
- IP/Network on Linux/Mac (try from a console : ip a) and Windows (also in console : ipconfig)
 
- IP/Network on Linux/Mac (try from a console : ip a) and Windows (also in console : ipconfig)
Line 68: Line 53:
  
  
! <span style="color:#CC9900">ATTENTION</span> ! in upper cases SQL1/2 you will have to :
+
! ATTENTION ! in upper cases 1/2 you will have to :
  
 
- CREATE a DATABASE dedicated for the bot (you can name it as you like but remember it)
 
- CREATE a DATABASE dedicated for the bot (you can name it as you like but remember it)
Line 88: Line 73:
 
> CREATE USER 'bebotuzr'@'%' IDENTIFIED BY 'botpass';
 
> CREATE USER 'bebotuzr'@'%' IDENTIFIED BY 'botpass';
  
> GRANT ALL PRIVILEGES ON bebotdbname.* TO 'bebotuzr'@'%';
+
> GRANT ALL PRIVILEGES ON bebotdb.* TO 'bebotuzr'@'%';
  
  
If you ain't sure, you can verify your work is fine by doing :
+
If you ain't sure, you can verify you work is fine by doing :
  
 
> SHOW DATABASES; (should show the DB you created upper among list)
 
> SHOW DATABASES; (should show the DB you created upper among list)
Line 100: Line 85:
  
  
If all here is done (or if you're in upper case SQL3) let's move on forward.
+
If all here is done (or if you're in upper case 3) let's move on forward.
  
  
Line 107: Line 92:
 
Once the software is installed, you first have to build runnable images from Bebot Docker preset configs :
 
Once the software is installed, you first have to build runnable images from Bebot Docker preset configs :
  
Get them from https://github.com/bitnykk/DockerBeBot/ (download/decompress the .zip or use git clone)
+
Get them from https://github.com/bitnykk/DockerBeBot/ (download the .zip or use git clone)
 
 
 
 
Then in command line, enter (cd) into the folder corresponding to your situation. Their name have 3 parts :
 
 
 
1: "linux" or "windows", which depends on your host Operating System,
 
  
2: "official" to run latest stable bot, or "sandbox" for some dev/beta testing,
 
  
3: "botonly" (in upper cases SQL1/2) or "botplusdb" (in upper case SQL3).
+
Then in command line, enter wanted folder ("botonly" in upper cases 1/2, "botplusdb" in upper case 3).
  
 +
You could edit Dockerfile and change PHP version for whatever you'd like ; more details on the modules and config at https://www.php.net/docs.php
  
Once inside the folder meeting your requirements, you can check (ls or dir) its content :
+
In upper case 3, you'd also have to setup your SQL credentials within docker-compose.yml (4 values to modify under "environment" part).
 
 
You get those 3 files : docker-compose.yml | docker-entrypoint.sh | Dockerfile
 
 
 
Note : you could edit Dockerfile and change PHP version for whatever you like ; more details on its modules/config at https://www.php.net/docs.php
 
 
 
In upper case SQL3, you'd also have to setup your SQL credentials within docker-compose.yml (4 values to modify under "environment" part).
 
  
  
Line 135: Line 109:
  
  
When it's over you are almost ready for the most exciting part ... but we'll need few more actions first ...
+
When it's over you are almost ready for the most exciting part ... but we'll need few more actions first !
  
  
Line 144: Line 118:
 
For that reason we will extract some files within the image we built earlier, and save them at host level to protect them.
 
For that reason we will extract some files within the image we built earlier, and save them at host level to protect them.
  
To do this, we will now run this long line on Linux from within upper chosen folder to get bindable datas :
+
To do this, we will now run this long line on Linux from our chosen folder :
  
 
<pre>
 
<pre>
Line 150: Line 124:
 
</pre>
 
</pre>
  
On Windows this can't properly, so we will let Docker manage volumes for us that will soon be explorable at network location \\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\
+
On Windows a part of this shouldn't work at all, so we will only obtain compressed datas into our chosen folder :
  
https://stackoverflow.com/questions/61083772/where-are-docker-volumes-located-when-running-wsl-using-docker-desktop
+
<pre>
 +
docker run --rm --entrypoint tar bebot-image czf - Conf Custom Extras/Bank Extras/Scripts log Text > out.tar.gz
 +
</pre>
  
 +
(then we can use any Windows utility, as Winzip or 7-zip etc, to decompress these datas right in place)
  
In any case we'll get 5 new folders ("Conf" "Custom" "Extras" "log" "Text") in chosen folder - where our 3 Docker config files are also.
 
  
Note : in upper case SQL3 we'll also soon have a "db" folder later at the same place, once we'll have our DB container started for first time.
+
In any case we end up with several new folders ("Conf", "Custom", "Extras", "log" and "Text") in chosen folder.
  
Windows only : possibly set permissive rights on those folders/files (select all, right-click > Properties > Security) so our container access them.
+
Windows only : possibly set permissive rights on those folders/files (select all, right-click > Properties > Security) so our container acces them.
  
  
Line 170: Line 146:
 
</pre>
 
</pre>
  
Your bot should now load (after launching its DB if some), check its updates then show its ip within Docker network.
+
Your bot should now load (after launching its DB) and, as it's our first run, ask to fill up credentials informations.
  
As it's our first run, bot will then ask us to fill up credentials informations.
+
So give him account name, pass, character, server and also owner and superadmin(s) plus few more question.
 
 
So give him account name, pass, character, server and also owner and superadmin(s) plus few more questions.
 
 
 
Then you're asked for the SQL part. In upper cases SQL1/2 you should already have everything needed here.
 
 
 
For upper case SQL3 you db ip should but the same than bot but end in .2 (as .1 should be host and .3 the bot itself).
 
  
 +
Then you're asked for the SQL part. In upper cases 1/2 you should already have everything needed here.
 +
For case 3 you are just missing one information (SQL server ip) obtainable by 2 ways :
 +
- either you open a second console in command line (if you can do this)
 +
- or you do Ctrl+p then Ctlr+q to detach off container view and be back to prompt
 +
In both cases you will do these 2 commands in order :
 +
<pre>
 +
docker ps
 +
</pre> (to see bebotdb's name or id, any if fine as both can be used below)
 +
<pre>
 +
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' bebotdb_name_or_id
 +
</pre>
 +
Once you got that, you can go back into bot's view (first console if you have 2, or use "docker attach bebot" command if you detached).
  
Finish the setting up, then bot will create all his DB entries, and endly come online !
 
  
NB : expect some deep caching at very first run keeping the bot busy for a minute or two. If anything goes wrong, restart containers (see below).
+
After finishing up its setting, the bot will start and create all his DB entries, then come online !
  
  
 
===== Control =====
 
===== Control =====
  
Now to check if your container(s) run properly, you have a set of commands :
+
Now to check if your container(s) run properly, and to control things, you have a set of commands.
 
 
To obtain a list of created image(s) : docker image ls
 
  
 
To show a list of running container(s) : docker ps (can use -a parameter to also see stopped ones)
 
To show a list of running container(s) : docker ps (can use -a parameter to also see stopped ones)
  
To see realtime stats of container(s) : docker stats (Ctrl+c to exit)
+
To see realtime log of the Bebot : docker logs -f <full-containername> (Ctrl+c to exit which will NOT shutdown bot/container)
 
 
To passively check realtime log of a container : docker logs -f container_name_or_id (Ctrl+c to exit which will NOT shutdown bot/container)
 
 
 
To enter container thread interactively : docker attach container_name_or_id (Ctrl+p Ctrl+q to exit without shutting down)
 
 
 
To execute container interactively : docker exec -it container_name_or_id sh (Ctrl+p Ctrl+q for the same result that upper)
 
 
 
To copy from a running container : docker cp container_name_or_id:/path/to/stuff.ext .
 
 
 
The same towards a running container : docker cp stuff.ext container_name_or_id:/path/to/copy/to
 
  
 +
To enter a given container interactively : docker exec -it <full-containername> sh (Ctrl+p Ctrl+q to exit without shutting down neither)
  
If you need to stop (and then restart) some container(s) :
+
To stop a given container : docker stop <full-containername> (bot should go offline as expected)
  
To stop a given container : docker stop container_name_or_id
+
To start again a previously stopped container : docker start <full-containername> (otherwise daemon may throw run error of "already in use")
  
To stop all containers together : docker stop $(docker ps -q)
+
To delete a buggy container : docker rm -f <full-containername> (means full data loss, not undoable, so beware !)
  
To restart stopped bot : docker compose run -d bebot (-d so it stays in background)
 
  
 +
If Bebot git code was patched, you simply restart container and it should auto-update : docker restart <full-containername>
  
If Bebot git code was patched, such container restart upper should quickfix to auto-update it.
+
Alternative manual way : enter the container, do "git pull" then exit and !restart the bot from ingame, which should provide same result.
 
 
For best reliability you also can delete bot image (its container once stopped/removed) and rebuild it with --no-cache parameter added :
 
 
 
- stop all (docker compose down ; docker stop containername)
 
 
 
- find & delete the bot container (docker ps -a ; docker rm fullid)
 
 
 
- find & delete the bot image (docker image ls ; docker image rm imagename)
 
 
 
- rebuild the bot image (docker compose build servicename --no-cache)
 
 
 
- restart the whole network (docker compose run -d servicename)
 
  
  
Line 238: Line 196:
  
 
Source : https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html
 
Source : https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html
 
 
===== Maintenance =====
 
 
Before anything, you can troubleshoot most common mistakes verifying in order :
 
 
- correct software installation (Docker ahead of any other)
 
 
- your various elements ip, port, state and availability
 
 
- you credentials (check bot's Conf folder in all cases, Docker's compose for case SQL3)
 
 
 
If needed to make house cleaning (assuming you've made <span style="color:#BB0000">BACKUPS</span> of sensible datas you could lose below !) :
 
 
To stop the containers : docker compose down (possibly --volumes param added)
 
 
To delete the recent containers : docker rm $(docker ps -a -q)
 
 
To clear a given image : docker image rm -f image_name
 
 
To remove all unused images : docker image prune -a
 
 
To trash all useless networks : docker network prune
 
 
For all upper cleans + cache : docker system prune -a
 
 
 
Again, any of the upper could make you lose datas, so cover yourself with some previous <span style="color:#BB0000">BACKUPS</span> (or do not blame your poor computer).
 
  
  

Please note that all contributions to Bebot Wiki 2 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Bebot Wiki 2:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)