docker
Docker is the way I run mostly everything. If it’s PHP, I might turn to CloudPanel, but otherwise, Docker it is. Small caveat : I've been switching to Podman for containerisation, so this page will move to the legacy section at some time.
First of all, a bit of light configuration, namely running docker without the pesky sudo requirement. Once you have your server up and running and docker installed, enter the following :
sudo usermod -aG docker $USER
where $USER is the user you want to use docker. Then logout/login and check that everything is running fine :
docker run hello-world
You should be greeted by the standard Hello from Docker !
Docker compose¶
Unless otherwise specified, the files on this website are meant to be run using docker compose, which should already be installed. A quick docker compose version should confirm that.
docker-compose.yml and .env¶
You’ll usually find at least a docker compose file and a environment in the various services presented on this website.
The minimal file/folder hierarchy is the following :
- project folder
- docker-compose.yml
- .env I say minimal here because, of course, you can do more.
Note : The docker compose files found on this site do not start with version: because it’s been deprecated.
running docker compose¶
The hard part was creating all the needed folders and setting the permissions. The easy part is running it :
docker compose up
There. It’s done. You’ll see the whole process running, and stay attached to the log. Once you confirm that everything is proper and dandy, you can stop the whole affair by Ctrl-C, and retype the command, this time with a -d to run it detached. That’s it.
update containers¶
Pull latest images:
docker compose pull
Restart containers:
docker compose up -d --remove-orphans
Optionally, remove obsolete images:
docker image prune
quick digression : folders, files, permissions¶
NOTE : this is highly taste dependant. If you want to keep it simple, and are running a single user, just dump everything in /home/$USER and you'll be fine.
Regarding the where to put the project folder, this is very well an open question. If you follow the Linux Filesystem Hierarchy, /srv/something is okay-ish. I use /srv/docker as the main directory, and each service gets its own folder. You can create /srv/docker by entering the following commands :
sudo mkdir /srv/docker
sudo chgrp docker /srv/docker/
sudo chmod g+ws /srv/docker/
sudo setfacl -dm u::rwx,g::rwx,o::r /srv/docker/
This way, any user in the docker group can access and create folders in /srv/docker. The chmod g+ws ensure that every new file created in this folder belongs to the docker group. The setfacl -dm u::rwx,g::rwx,o::r /srv/docker/ is a modification to ACLs to ensure that new files and folders are created with the right permissions.
File, permissions and inheritance of said permissions is another rabbit hole. Don’t go there. Preserve your sanity. (More information)