Jan 5, 2022

QuickStart on Docker 2

Here is how I setup docker (for Ubuntu) in Lab21.

First, I update package repository at my Ubuntu server, and follow by installing 4 prerequisite packages and installing docker.io package. Finally, I setup Docker to start automatic.

$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common 

$ sudo apt install docker.io

$ sudo systemctl start docker.service
$ sudo systemctl enable docker.service


Optionally, you can add the official Docker repository by, and install from the Docker repo (instead of the default Ubuntu repo):

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

$ sudo apt install docker-ce


Verify and gather Docker version:

$ sudo docker version

 

Quickly show information about Docker client/server with how many containers are running:

$ sudo docker info


To run Docker without root

$ sudo usermod -aG docker $USER

$ reboot


Search, Install and run a Docker image [nginx, hello-world] 

$ docker search nginx

$ docker pull hello-world

$ docker run hello-world
 
$ docker pull ubuntu
$ docker run -it ubuntu
root@d9b100f2f636:/# 
root@d9b100f2f636:/# apt update
root@d9b100f2f636:/# apt install nodejs
root@d9b100f2f636:/# nodejs -v
 

 

List  installed images and Monitor Docker (CPU, RAM, network)

$ docker images

$ docker container ls

$ docker stats

$ docker network ls

 

Managing Docker images:

$ docker ps
$ docker ps -a
$ docker ps -l
$ docker start <container_id>
$ docker stop [ <container_id> | <name> ]
$ docker rm [ <container_id | <name> ]

 

Committing changes in a Container to a Docker image:

$ docker commit -m "installing nodejs" -a "xx" <container_id>
$ docker images

 

Pushing Docker image to Docker repository:

$ docker login -u <login>
$ docker tag <repo>/<image> <login>/<image>
$ docker push <login>/<image>
$ docker push <repo>/<image>
$ docker pull <repo>/<image>

 

Links:

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