sudo apt-get install apt-transport-https curl gnupg-agent ca-certificates software-properties-common -y<\/pre>\nNext is to add the GPGK key:<\/p>\n
curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo apt-key add -<\/pre>\nOnce the GPGK key is added, we need to add the repo because it is not included in the Ubuntu 22.04:<\/p>\n
sudo add-apt-repository \"deb [arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu focal stable\"<\/pre>\nAfter adding the key and repo, you can install Docker with the following commands:<\/p>\n
sudo apt-get install docker-ce docker-ce-cli containerd.io -y<\/pre>\nAfter successful installation, start and enable the docker service:<\/p>\n
sudo systemctl enable docker && sudo systemctl start docker<\/pre>\nTo check the status of the service, execute the following command:<\/p>\n
sudo systemctl status docker<\/pre>\nYou should receive the following output:<\/p>\n
root@vps:~# systemctl status docker\r\n\u25cf docker.service - Docker Application Container Engine\r\n Loaded: loaded (\/lib\/systemd\/system\/docker.service; enabled; vendor preset: enabled)\r\n Active: active (running) since Tue 2022-12-06 15:13:24 CST; 10min ago\r\nTriggeredBy: \u25cf docker.socket\r\n Docs: https:\/\/docs.docker.com\r\n Main PID: 120228 (dockerd)\r\n Tasks: 9\r\n Memory: 21.1M\r\n CPU: 2.326s\r\n CGroup: \/system.slice\/docker.service\r\n \u2514\u2500120228 \/usr\/bin\/dockerd -H fd:\/\/ --containerd=\/run\/containerd\/containerd.sock\r\n<\/pre>\nNow, when the Docker service is installed, we can start with the docker<\/b> commands.<\/p>\n<\/span>1. Check the Docker version<\/span><\/h2>\nTo check the installed Docker version, execute the command docker –version<\/b>. You should receive output similar to this:<\/p>\nroot@host:~# docker --version\r\nDocker version 20.10.21, build baeda1f\r\n<\/pre>\n<\/span>2. Search package<\/span><\/h2>\nTo search for some software that can be installed with Docker, execute the following command:<\/p>\n
docker search wordpress<\/pre>\nYou will receive a list of available WordPress packages:<\/p>\n
root@host:~# docker search wordpress\r\nNAME DESCRIPTION STARS OFFICIAL AUTOMATED\r\nwordpress The WordPress rich content management system\u2026 5012 [OK]\r\nbitnami\/wordpress Bitnami container image for WordPress 208 [OK]\r\nbitnami\/wordpress-nginx Bitnami Docker Image for WordPress with NGINX 67 [OK]\r\n<\/pre>\n<\/span>3. Docker pull<\/span><\/h2>\nDocker pull is used for taking the application from the official Docker Hub. Let’s pull the WordPress package we searched for in the previous step.<\/p>\n
docker pull wordpress<\/pre>\nAfter a successful pull, you should receive the following output:<\/p>\n
root@host:~# docker pull wordpress\r\nUsing default tag: latest\r\nlatest: Pulling from library\/wordpress\r\na603fa5e3b41: Pull complete\r\nc428f1a49423: Pull complete\r\n156740b07ef8: Pull complete\r\nfb5a4c8af82f: Pull complete\r\n25f85b498fd5: Pull complete\r\n9b233e420ac7: Pull complete\r\nfe42347c4ecf: Pull complete\r\n9a7bf1523229: Pull complete\r\na0b541d575c5: Pull complete\r\nc0e75b0cc4dc: Pull complete\r\na97a86207955: Pull complete\r\nf88820a52a78: Pull complete\r\n81ebcb8aedf6: Pull complete\r\n265e9160e272: Pull complete\r\nadbaf7c3bb9d: Pull complete\r\n1b8e3ff1537e: Pull complete\r\nbc197583e391: Pull complete\r\nf89eb7cb30b3: Pull complete\r\nfa90bc2f4db7: Pull complete\r\n1ca7d72233c9: Pull complete\r\nc68df4c97ee8: Pull complete\r\nDigest: sha256:fd08649a97d2cb6967fb0a5cd8a710e2b6075502eb18f6c3f841a4d986c0700b\r\nStatus: Downloaded newer image for wordpress:latest\r\ndocker.io\/library\/wordpress:latest\r\n<\/pre>\n<\/span>4. Docker run<\/span><\/h2>\nThe Docker run command is used for creating a container from an image.<\/p>\n
docker run hello-world<\/pre>\nYou should receive output similar to this:<\/p>\n
root@host:~# docker run hello-world\r\n\r\nHello from Docker!\r\nThis message shows that your installation appears to be working correctly.\r\n\r\nTo generate this message, Docker took the following steps:\r\n 1. The Docker client contacted the Docker daemon.\r\n 2. The Docker daemon pulled the \"hello-world\" image from the Docker Hub.\r\n (amd64)\r\n 3. The Docker daemon created a new container from that image which runs the\r\n executable that produces the output you are currently reading.\r\n 4. The Docker daemon streamed that output to the Docker client, which sent it\r\n to your terminal.\r\n<\/pre>\n<\/span>5. Docker ps<\/span><\/h2>\nThe docker ps<\/b> command is used for listing the running containers. Let’s execute this command: docker ps<\/b><\/p>\nroot@host:~# docker ps\r\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\r\nd2a01e103a5d wordpress \"docker-entrypoint.s\u2026\" 6 minutes ago Up 6 minutes 0.0.0.0:80->80\/tcp, :::80->80\/tcp wordpress\r\n3ac6a4cf7b0c mariadb:latest \"docker-entrypoint.s\u2026\" 8 minutes ago Up 8 minutes 3306\/tcp wordpressdb\r\n<\/pre>\nAs you can see, there are two running containers on our system.<\/p>\n
<\/span>6. Docker start<\/span><\/h2>\nDocker start is used for starting the stopped containers. Let’s first list the stopped containers:<\/p>\n
docker ps -a<\/pre>\nYou will receive an output similar to this:<\/p>\n
root@host:~# docker ps -a\r\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\r\nd2a01e103a5d wordpress \"docker-entrypoint.s\u2026\" 25 minutes ago Exited (0) About a minute ago wordpress\r\n3ac6a4cf7b0c mariadb:latest \"docker-entrypoint.s\u2026\" 28 minutes ago Exited (0) About a minute ago wordpressdb\r\n<\/pre>\nRemember that we start the containers using their IDs. To start both containers, execute the following commands:<\/p>\n
docker start 3ac6a4cf7b0c\r\n\r\ndocker start d2a01e103a5d\r\n<\/pre>\n