Docker setup and how to manage it from GUI.
Docker it’s a service running at an operating system level. In this case our virtual environment is stored in containers, not in separate virtual machines, using the same kernel from the OS.
You can create application packages containing everything you need to run that app on any server. Docker can be installed on Windows, Linux or MacOS but running Windows containers on Linux is not possible as it requires a Windows kernel on host operating system. Linux containers can be run on Windows with the help of WSL (Windows Subsystem for Linux).
Steps for installing docker
In order to install docker, on our demo machine, we will use Ubuntu Server. At this point in time the latest version available that hasn’t reached end of life is Ubuntu Bionic 18.04 (LTS). Our version is Ubuntu 21.04.
Even if we have a fresh install it’s better to check for updates and install packages to allow
apt to use a repository over HTTPS:
sudo apt update
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y
Next, we need to add docker GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
To use the stable repository use the following command:
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Now that we have everything ready is time to install Docker
sudo apt-get install docker-ce docker-ce-cli containerd.io
After everything has been installed, we can check it by
sudo docker run hello-world
If the result is this one, than everything should work fine:
sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51 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/
You can find the same steps in the official docker documentation at this link.
Docker GUI manager
For GUI administration of a docker server we can use Portainer. To install it we need to follow the steps bellow:
- Docker containers can store data outside the container so every time we update our container we will not lose data. To have everything saved outside the container we need to create a volume
docker volume create portainer_data
2. Download and install Portainer
sudo docker run -d -p 8000:8000 -p 9443:9443 --name portainer \ --restart=always \ -v /var/run/docker.sock:/var/run/docker.sock \ -v portainer_data:/data \ portainer/portainer-ce:latest
–name – The container name
-p 8000:8000 & -p 9443:9443 – What ports are to be mapped on the container. It means that if we access the docker server IP and port it will be redirected to our container.
— restart = always – Always restart the container if it stops
-v /var/run/docker.sock:/var/run/docker.sock – docker.sock will be accessible inside the container
-v portainer_data:/data – The content of data folder inside the containter will be stored in the volume we previously created
portainer/portainer-ce:latest – We download the latest image of portainer
After this command is issued, docker will pull the latest version of portainer from the repositories. Now we are ready to access our GUI administration. To login go to https://docker.server.ip:9443 and setup your username and password. You should be able to see your docker server like this:
That’s all, follow me for more fun stuff.