1. Intro

A while ago I wandered into docker. These are the notes I use to manage the containers and other stuff I find usable.

 

2. Notes

 

2.1. A great guide for installing and using Docker

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-compose-on-ubuntu-20-04

 

2.2. Other Docker guides

https://docker-curriculum.com/

 

2.3. Portainer

Portainer is very usable docker manager.

Find the install docs, requirements etc at https://documentation.portainer.io/.

 

2.3.1. Short Portainer install guide

Become root or run all commands with sudo.

# apt
update

# apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common

# curl
-fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# echo "deb [arch=amd64] https://download.docker.com/linux/debian buster stable" > /etc/apt/sources.list.d/docker-ce.list
# echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" > /etc/apt/sources.list.d/docker-ce.list

# apt
update

# apt
install docker-ce

# systemctl status docker

# usermod
-aG docker sorin

# docker volume create portainer_data

# docker volume ls

# docker run -d --name=Portainer --hostname=Portainer --network=host --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data -e TZ='Europe/Stockholm' portainer/portainer-ce

Upgrading to new versions # docker pull portainer/portainer-ce:latest

Run docker ps to find the old container's id
# docker ps
# docker stop <old portainer id>
# docker rm <old portainer id>

Now start the upgraded version instead # docker run -d --name=Portainer --hostname=Portainer --network=host --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data -e TZ='Europe/Stockholm' portainer/portainer-ce

When done, browse to http://serverip:9000 to confirm it works and to create your first user.
Choose Local when the instal wizard asks for the installation type.

2.3.2. Portainer templates repos

Some third party template repos for Portainer as well as the default one.

Copy and paste the repo url to left panel settings menu in the URL field at App Templates header.

 

https://raw.githubusercontent.com/Qballjos/portainer_templates/master/Template/template.json

https://raw.githubusercontent.com/SelfhostedPro/selfhosted_templates/portainer-2.0/Template/template.json

https://raw.githubusercontent.com/portainer/templates/master/templates.json

https://raw.githubusercontent.com/portainer/templates/master/templates-2.0.json

 

2.4. Backing up docker containers, volumes etc

https://www.thegeekdiary.com/how-to-backup-and-restore-docker-containers/

https://blog.ssdnodes.com/blog/docker-backup-volumes/

 

2.5. Docker Compose

Your goto solution when you start creating stacks instead.

https://docs.docker.com/compose/

https://github.com/docker/compose

 

 

2.6. Creating stuff with Docker Compose

https://linuxconfig.org/how-to-create-a-docker-based-lamp-stack-using-docker-compose-on-ubuntu-18-04-bionic-beaver-linux

https://www.digitalocean.com/community/tutorials/how-to-install-drupal-with-docker-compose

https://www.techrepublic.com/article/how-to-build-a-docker-compose-file/

 

2.7. Docker commands

2.7.1. Install busybox

# docker pull busybox

2.7.2. Run it

# docker run busybox

 

2.7.3. List containers

# docker ps -a
CONTAINER ID   IMAGE                                COMMAND        CREATED      STATUS        PORTS                                                               NAMES
a3b2c696a51d   jlesage/nginx-proxy-manager:latest   "/init"        4 days ago   Up 30 hours   0.0.0.0:443->4443/tcp, 0.0.0.0:80->8080/tcp, 0.0.0.0:81->8181/tcp   nginx-proxy-manager
5252b616bacc   portainer/portainer-ce               "/portainer"   5 days ago   Up 30 hours   0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp                      portainer

 

2.7.4. Run a web app

# docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce

 

2.7.5. List used ports for a particular container

# docker port portainer
8000/tcp -> 0.0.0.0:8000
9000/tcp -> 0.0.0.0:9000

 

2.7.6. Stop the container

# docker stop portainer

 

2.7.7. Show status inside the container

See the container ID from docker ps -a.

# docker top a3b2c696a51d

 

2.7.8. Container image managment

List container images
# docker image ls

Remove container images
# docker image rm <image ID>

Remove all container images
# docker image prune -a

Stop all containers
# docker stop $(docker ps -a -q)

Remove all containers
# docker rm $(docker ps -a -q)

 

2.7.9. Run, pull and remove a container

# docker run hello-world   
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete  
Digest: sha256:95ddb6c31407e84e91a986b004aee40975cb0bda14b5949f6faac5d2deadb4b9
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
   (amd64)
3. The Docker daemon created a new container from that image which runs the
   executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
   to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/



# docker ps -a
CONTAINER ID   IMAGE                                COMMAND        CREATED              STATUS                          PORTS                                                               NAMES
85f5701571cf   hello-world                          "/hello"       About a minute ago   Exited (0) About a minute ago                                                                       ecstatic_lamarr



# docker rm 85f5701571cf
85f5701571cf

 

2.7.10. Ssh to a container

# docker exec -it MYSQL2 /bin/bash

 

 

2.7.11. Build a container with docker-compose

Use eg this simple script to install Nginx Proxy Manager:
https://nginxproxymanager.com/#quick-setup

# cd /home/user/docker
# ll
-rw-r--r--  1 user user  850 Feb 12 14:35 docker-compose.yml
# docker-compose build

Restart the container with changes from above build # docker-compose up -d

 

 

 

3. References

https://www.danielmartingonzalez.com/en/docker-and-portainer-in-debian/

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04