Skip to content

Latest commit

 

History

History
124 lines (98 loc) · 3.33 KB

introduction_to_docker.md

File metadata and controls

124 lines (98 loc) · 3.33 KB

Introduction to Docker.

Video : Introduction to Docker and Containers

Docker is a container management service. The keywords of Docker are develop, ship and run anywhere. The whole idea of Docker is for developers to easily develop applications, ship them into containers which can then be deployed anywhere.

Video : Introduction to Docker and Containers


Features of Docker

  • Docker has the ability to reduce the size of development by providing a smaller footprint of the operating system via containers.

  • With containers, it becomes easier for teams across different units, such as development, QA and Operations to work seamlessly across applications.

  • You can deploy Docker containers anywhere, on any physical and virtual machines and even on the cloud.

  • Since Docker containers are pretty lightweight, they are very easily scalable.


Docker post-installation setup

Do the optional procedure configuration to work better with Docker.

Run Docker as non-root user

To create the docker group and add your user:

  1. Create the docker group.
sudo groupadd docker
  1. Add your user to the docker group.
sudo usermod -aG docker $USER
  1. Activate the changes to groups:
newgrp docker 
  1. Verify that you can run docker commands without sudo.
docker images

Docker Commands

Docker is a containerization system which packages and runs the application with its dependencies inside a container. There are several docker commands you must know when working with Docker.

1. Docker version

To find the installed docker version Command:

docker  --version

Example:

docker --version
Docker version 20.10.12, build e91ed57

2. Downloading image

To work with any ocker image we need to download the docker image first.
Command:

docker pull <IMAGE>

Example of pulling alpine:latest image

docker pull alpine:latest

3. List all the docker images

To list all the images that is locallt available in the host machine, simply run the below command. This will list all the docker images in the local system.
Command:

docker images
Example:
REPOSITORY  TAG  IMAGE ID       CREATED      SIZE
alpine     latest  c059bfaa849c 6 weeks ago  5.59MB

4. Run docker image

The docker run command first creates a writeable container layer over the specified image, and then starts it using the specified command.
Command:

docker run [options] <IMAGE>

Explore here: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04

Example of running alpine:latest image, the options -t allows us to acces the terminal and -i gets stdin stream added. Basicaly using -ti adds the terminal driver.

docker run -t -i alpine:latest
or
docker run -ti alpine:latest

Create docker image for python:3.10.2-alpine3.15

Create a dockerfile

FROM python:3.10.2-alpine3.15
# Create directories  
RUN mkdir -p /root/workspace/src
# Switch to project directory
WORKDIR /root/workspace/src

Goto the directory where you created Dockerfile

docker build ./ -t simple_python