Introduction To Docker
Virtual Machines
β Isolates applications and allocates resources to run that application
β VMs can be shared as images
β Arenβt dependent on the Host OS
β Multiple VMs can be run simultaneously using a hypervisor
Docker Containers
β Standard unit of software
β Packages code and dependencies
β Can be shared as Docker Images
β Multiple containers can be run simultaneously
β Portable - Can be used with any OS
β Lightweight - Uses the host operating system
β Secure - Strong default isolation features
β Sometimes used with VMs
Microservices
β Breaks large applications down into smaller executable components
β Easy to maintain and test
β Loosely coupled and can be deployed independently
β Can be combined with serverless architecture (AWS Fargate)
Why Use Docker
β Develop applications that work on any OS
β Easy to share applications among teams
β Easy to scale across multiple servers
β Large applications can be broken into multiple containers - one for each microservice
β Great solution for Cloud Computing
β Big community and library of Docker Images
Serverless
β Removes Dependency on Infrastructure
β Allows developers to focus on application development
β Microservices can be decoupled with different cloud services
β Usually more cost effective
β Probably covered in more depth in a Cloud Computing class
Install Docker Engine
You can create an Ubuntu EC2 Instance on AWS and run the below commands to install docker.
sudo apt update
sudo apt install docker.io -y
Start Docker daemon
You use the below command to verify if the docker daemon is actually started and Active
sudo systemctl status docker
sudo systemctl start docker
Grant Access to your user to run docker commands
To grant access to your user to run the docker command, you should add the user to the Docker Linux group. Docker group is create by default when docker is installed.
sudo usermod -aG docker $USER
Docker is Installed, up and running π₯³π₯³
Use the same command again, to verify that docker is up and running.
docker run hello-world
Output should look like
....
....
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
...
Pull An Image
There are many publicly available images that we can use to work with Docker. The example below pulls a hello-world image using the docker pull command:
[ ~ ]docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest:sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
[ ~ ]docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 12 months ago 13.3kB
Create A Container
To create a container from an image we can use the docker create command
[ ~ ]docker create hello-world
2ffd5f2c5a7562fbf1d7b89a14c11a52e5843dd7938f380a8cd53f3952da99de
Run A Container
To run a container we can use the docker container start command to start a container. The -i runs the container interactively and allows us to see the output
[ ~ ] docker container start -i 2ffd5f2c5a7562fbf1d7β¦
Hello from Docker!
This message shows that your installation appears to be working correctly.
Run An Image
There is a shortcut for building a container from an image and running it with the docker run
command. This will create a new container for an image and run it:
[ ~ ] docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
List Images
To see what images are already installed on your machine you can use the docker image
ls command. We can see our hello-world image below:
[ ~ ]docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest f63181f19b2f 13 hours ago 72.9MB
hello-world latest bf756fb1ae65 12 months ago 13.3kB
List Containers
To list the containers that we have built, we can use the docker container ls
command. The -a flag allows us to see both stopped and running containers. There are two containers below, one that was built with the docker create command and the other that was built with docker run:
[ ~ ]docker container ls βa
List Running Processes
To see what containers are currently running, we can use the docker ps command. This is useful when you are running containers in the background.
[ ~ ]docker ps
That's a wrap.......
Subscribe to my newsletter
Read articles from Ketan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by