Docker is a tool for running application in an isolated environment.
Some reasons you might want to use Docker:
- Same environment: Same environment in developers machines and production servers. Acts the same.
- Sandbox projects: Eliminates the risk of getting conflicts while working on different projects on same machine.
- Easy working without setup hassle: Start working directly on others projects without setting all of the environments.
- Debug your app, not your environment: Securely build and share any application, anywhere.
Container, Image, Dockerfile, Docker Hub:
Container is a running instance of an image. An image is a template for creating the environment you want to snapshot out of a system at a particular time. An image includes:
- Operating system
- Application Code
Images are defined by a Dockerfile. Dockerfile is a text file with the steps to perform to create that image. It includes the following ordered instructions:
- Configure the operating system
- Install the necessary software
- Copy the project file in right places
Building the Dockerfile will create the image which is run in the container.
Docker Hub: The world’s leading service for finding and sharing container images with your team and the Docker community.
- Operating System : Ubuntu 18.04.4 LTS (64-bit)
- Processor : Intel® Core™ i7-8750H CPU @ 2.20GHz × 12
- Memory : 15.3 GiB
Docker Installation Procedure in Ubuntu 18.04 LTS
The following steps showed the step by step installation guideline. This instructions shows the way of installing Docker using the Docker repository.
Set up the repository
sudo apt-get update
Uninstall old versions: Older versions of Docker were called
docker-engine. If these are installed, uninstall them:
sudo apt-get remove docker docker-engine docker.io containerd runc
Install packages to allow
aptto use a repository over HTTPS:
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
Add Docker’s official GPG key: GPG is the GNU PGP encryption program. PGP is an identification key system people use to sign files or emails so the receiver can check the authenticity of them.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify that you have the key with the fingerprint
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88by searching for the last 8 characters of the fingerprint
sudo apt-key fingerprint 0EBFCD88
It should some information about the key file:
pub 4096R/0EBFCD88 2017-02-22 Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid Docker Release (CE deb) <email@example.com> sub 4096R/F273FCD8 2017-02-22
Set up the stable repository. The following command is for
sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
Install Docker Community Edition (CE)
sudo apt-get update
Install the latest version of Docker Engine - Community and containered:
sudo apt-get install docker-ce docker-ce-cli containerd.io
Verify that Docker CE is installed correctly by running the
sudo docker run hello-world
It downloads a a test image and runs it in a container. When the container runs, it prints informational messages and exits.
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751 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://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
Post-installation steps for Linux
This section contains optional procedures for configuring Linux hosts to work better with Docker.
Manage Docker as a non-root user
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.
If you don’t want to use
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
Warning: The docker group grants privileges equivalent to the root user.
Create the docker group:
sudo groupadd docker
You may get that
dockergroup already exists:
groupadd: group 'docker' already exists
Add your user to the docker group:
sudo usermod -aG docker $USER
Log out and log back in so that your group membership is re-evaluated.
Activate the changes to groups:
Verify that the current user is added to
getent group docker
Verify that you can run docker commands without
docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.