IT/Software/Docker
Docker
General notes
Natively docker doesn't come with a web UI, but there are several projects that can offer that functionality, e.g.
- Portainer (so far the "go to" for docker UI's)
- Dockge (a quite new project)
Nonetheless some basics are recommended :)
docker run vs docker compose run
- containers can be run "just" with a simple cli command, e.g.
docker run hello-world
- this is nice for quick tests
- but will get overwhelming as soon as more containers and parameters are involved
- docker compose uses yaml files (docker-compose.yml / compose.yml)
cd
to the folder where the compose file lies and run withsudo docker compose up -d
(-d to run in background)- all applications/services are defined in these compose files
- this allows for reproducible containers on any host
- if a host dies, just use the same compose file to spin the service up on another host and it will have the same settings
- persistent volumes/data still need to be copied/backuped
Where to put the compose file and persistent data?
If you search the web, there are several opinions about this :)
Generally it doesn't matter that much where you put those, as long the file permissions are set correctly.
Some mentioned locations are: home directory, /opt/docker, /srv/docker
Preference:
/srv/docker/[SERVICE-STACK_NAME]
Most important is, that the compose files and persistent data are backuped, as it should be the case for any other application.
Persistent vs Non-Persistent
In a gist:
- non-persistent containers/services don't have any data (files, internal config) that need to be kept
- e.g. they can be completely defined just by the parameters in the compose file
- examples are redis,
Common CLI Commands
Some useful commands (use sudo
depending on how docker was installed)
Check status of containers
sudo docker ps
sudo docker ps -a
(also shows stopped containers)
Check logs of a specific container
sudo docker logs -f [CONTAINER_ID/NAME]
(-f to follow new lines)
Installation
Manually
Ansible Playbook
- how to run playbooks
- ssh enabled on host
sudo apt update && sudo apt install openssh-server -y
- https://github.com/stefannyffenegger/automation/blob/main/ansible/pb_prompt_install-docker.yml
Offline Manually
Install docker and docker-compose:
If you always want to automatically get the latest version of Docker on Ubuntu, you must add its official repository to Ubuntu system. To do that, run the commands below to install prerequisite packages:
sudo apt update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Next, run the commands below to download and install Docker’s official GPG key. The key is used to validate packages installed from Docker’s repository making sure they’re trusted.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
Now that the official GPG key is installed, run the commands below to add its stable repository to Ubuntu. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
After this command, Docker’s official GPG and repository should be installed on Ubuntu.
If you have older versions of Docker, run the commands below to remove them:
sudo apt-get remove docker docker-engine docker.io containerd runc
When you have removed all the previous versions of Docker, run the commands below to install the latest and current stable version of Docker:
sudo apt-get install docker-ce docker-ce-cli containerd.io
This will install Docker software on Ubuntu.
Add your account, for most cases it will be ubuntu, to Docker group and restart:
sudo usermod -aG docker $USER
Reboot your instance:
sudo reboot
To verify that Docker CE is installed correctly you can run the hello-world image:
sudo docker run hello-world
If Docker is installed correctly you will see the following response: Response: Hello from Docker! This message shows that your installation appears to be working correctly.
Then you need to install docker-compose. This makes it easier for you to install containers on docker.
To install it, run the commands below to download version 1.26.0. As of this writing, this was the current version.
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
After downloading it, run the commands below to apply executable permissions to the binary file and create a symbolic link to /usr/binary
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Now, Docker Compose should work. To test it, we will run the command below:
docker-compose --version
You should see similar output as below: Response: docker-compose version 1.24.0, build 0aa59064
Source: https://docs.fuga.cloud/how-to-install-portainer-docker-ui-manager-on-ubuntu-20.04-18.04-16.04
Containers
In use
- Portainer: Wiki article
- Octoprint: Wiki article
Potentially useful
- Interesting Docker projects: Wiki article