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.
-
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.
Do the optional procedure configuration to work better with Docker.
To create the docker group and add your user:
- Create the docker group.
sudo groupadd docker
- Add your user to the docker group.
sudo usermod -aG docker $USER
- Activate the changes to groups:
newgrp docker
- Verify that you can run docker commands without sudo.
docker images
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.
To find the installed docker version Command:
docker --version
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
Note: You may find 1000s of docker images in Docker Hub
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
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 access 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
Note: You can use Ctrl+D to come out from the docker image.
Create a new file called Dockerfile and then paste the below content
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
You may check the image you created using docker images
command
Run the simple_python image you created
docket run -ti simple_python