Docker for Absolute beginners

Anvitha Jain
2 min readJun 7, 2020

--

docker

Hi Guys, if you are an absolute beginner and has no idea about docker, don’t worry!!!

I myself had never used docker and upon lots of research found this course on Udemy “Docker for the Absolute Beginner — Hands On — DevOpswhich is a great step to start.

Upon finishing the course here are a few things about Docker:

Why Docker?

→ Docker is used to package and containerize different things.

Note: There are compatibility issues when you try to run an application code on different systems, because of differences in underlying OS, libraries, infrastructure, etc. So, Docker is the solution.

What are images and containers?

Images: templates/packages used to create a container.

Containers: running instances of images. Containers have their own environment and set of processes.

One image can create any number of containers within the Docker.

Few basic docker commands:

docker.git

I will explain about “docker build .” and “docker run” command later.

Official pre-built docker images are found in docker hub . We can build our own images as well.

Example: say you have a simple python file — app.py which just prints “hello world”.
Generally, we follow few steps to run app.py like

  • install python
  • run app.py = python3 app.py

To build our own image we need to create Dockerfile (contains instruction to run the application)

Dockerfile

Dockerfile always starts with “FROM”

Now docker build . -t myApp will build and image named myApp and to run this image on the port you want docker run -p 8000:5000 myApp

  • -p is to explicitly set the port

docker run has other options like - -name to name a container, -i to let you enter an input in terminal, etc.

Finally to remove/delete images and containers from docker

Step 1: Stop all the running containers (Container id can be just first 2–3 letters/numbers) docker stop “containerId/containerName”

→ Step 2: remove all containers docker rm “containerId/containerName”

→ Step 3: remove images docker rmi “imageName/imageID”

Note: images can be removed after deleting the container where the image was used.

This article is just a gist and I will give you guys a detailed description in the next article.

--

--