Installing docker in ubuntu and running some commands to deploy your first docker container!!
What is Docker?
Docker is a platform for developers and sysadmins to build, run, and share applications with containers. The use of containers to deploy applications is called containerization. Containers are not new, but their use for easily deploying applications is.
Containerization is increasingly popular because containers are:
- Flexible: Even the most complex applications can be containerized.
- Lightweight: Containers leverage and share the host kernel, making them much more efficient in terms of system resources than virtual machines.
- Portable: You can build locally, deploy to the cloud, and run anywhere.
- Loosely coupled: Containers are highly self-sufficient and encapsulated, allowing you to replace or upgrade one without disrupting others.
- Scalable: You can increase and automatically distribute container replicas across a datacenter.
- Secure: Containers apply aggressive constraints and isolations to processes without any configuration required on the part of the user.
What is a Container?
Fundamentally, a container is nothing but a running process, with some added encapsulation features applied to it in order to keep it isolated from the host and from other containers. One of the most important aspects of container isolation is that each container interacts with its own private filesystem; this filesystem is provided by a Docker image. An image includes everything needed to run an application — the code or binary, runtimes, dependencies, and any other filesystem objects required.
Installing docker in Ubuntu:
1) First, in order to ensure the downloads are valid, add the GPG key for the official Docker repository to your system
using the command below:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
2) Add the Docker repository to APT sources
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
3) Next, update the package database with the Docker packages from the newly added repo
$ sudo apt-get update
4) Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo
$ apt-cache policy docker-ce
5) Finally, install your Docker
$ sudo apt-get install -y docker-ce
6) To Check whether it’s in running condition or not
$ sudo systemctl status docker
7) Check yourdocker version after installation
$ docker --version
CONGRATULATIONs YOU HAVE SUCCESSFULLY INSTALLED DOCKER IN YOUR SYSTEM !!!
Now its time to know how to deploy your first docker container?
Deploy your first docker container?
STEP 1) For example purpose we will be deploying container of “redis” docker image:
search for the docker image “redis”
docker search redis
This command will Search the Docker Hub for images
You can also cross check it by searching it on dockerhub
STEP 2) Pull docker image
docker pull redis
This command will Pull an image or a repository from a registry
STEP 3) Start the container using
this command automatically pull the image and start the container
docker run -d redis
docker runcommand must specify an IMAGE to derive the container from. An image developer can define image defaults related to:
- detached or foreground running
- container identification
- network settings
- runtime constraints on CPU and memory
docker run [OPTIONS]an operator can add to or override the image defaults set by a developer. And, additionally, operators can override nearly all the defaults set by the Docker runtime itself. The operator’s ability to override image and Docker runtime defaults is why run has more options than any other
Detached (-d): To start a container in detached mode, you use
-doption. By design, containers started in detached mode exit when the root process used to run the container exits, unless you also specify the
--rmoption. If you use
--rm, the container is removed when it exits or when the daemon exits, whichever happens first.
You can check for list of containers and there status using but this will just give you 2 linked containers
to see all the containers you can use
docker ps -a
You can also inspect the container using the command this will Return low-level information on Docker objects
docker inspect <container id | friendly name>
output using container id
output using container name
You can also see container log using
docker logs <container id | friendly name>
Congratulations!! you have successfully learned how to install Docker in Ubuntu and deploy your first Docker Container.
👋 Join FAUN today and receive similar stories each week in your inbox! ️ Get your weekly dose of the must-read tech stories, news, and tutorials.