When we think of virtualization today, we may think of Virtual Box, which abstracts away the system processes, and lets you run a completely system from another. Think of Docker as Virtual Box, but extremely lightweight (in terms of resource consumption). Obviously I'm over simplifying the explanation a little, and a whole of things are getting lost in simplification. But for now, this will do.
apt remove docker docker-engine docker.io
apt update && apt -y upgrade
apt install -y linux-image-extra-$(uname -r) linux-image-extra-virtual #FOR UBUNTU 18: apt install -y linux-image-$(uname -r) linux-image-extra-virtual
apt update && apt -y upgrade
apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" #FOR UBUNTU 18: instead of stable use edge (just for now, since they haven't released the stable version on 18.04 yet)
apt update && apt -y upgrade
apt install -y docker-ce
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose #use the latest docker-compose version, by looking at releases on github pages [https://github.com/docker/compose/releases]https://gist.githubusercontent.com/mamigot/1abdefc684f97d3476f177d85248ff36/raw/5f57b4918b237f8e0127b45984fa51a483218349/docker-compose.yml
chmod +x /usr/local/bin/docker-compose
Allow docker usage without sudo access
The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The docker daemon always runs as the root user. To prevent using sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
Images are read only We upload images to hub. Think of them as classes in an object oriented programming language terminology.
Containers boot up from images. Think of them as instances of a class.
You can think of this as versions
Unique ID assigned to every container or image respectively
A Dockerfile
can be used to build docker images
To list all images available on your system
docker images
docker ps -a
docker pull ubuntu
By default the latest
tag
is pulled. Consider tag
to be sort of like the version of the image you want.
tag
is 12.04
docker pull ubuntu:12.04
docker rmi ubuntu:latest
or
docker rmi IMAGE_ID
container
from an image
and run itdocker run -it ID /bin/bash
i
stands for interactivet
stands for pseudo tty. It is for specifying the path to the shell to be run.ID
can be an IMAGE-ID
or a CONTAINER-ID
obtained by listing all images, or containers respectively.Note: Every time you use docker run
using the IMAGE-ID, a new
container is created based on the image
Extra bits: If the argument --rm
is if passed, causes the container to automatically get deleted after exiting the shell.
exit
docker start CONTAINER_ID
docker stop CONTAINER_ID
docker rm CONTAINER_ID
Dockerfile
. Create a Dockerfile
and put it in a folder, and execute the following commanddocker build -t username/image_name:image_tag .
username
- as on hub.docker.com
image_name
- the name of the image you want to build
image_tag
- the tag you want to assign to the image
docker rmi $(docker images -f dangling=true -q)
docker commit CONTAINER_ID IMAGE_NAME:IMAGE_TAG
docker save IMAGE_ID -o file_name.tar