Hello everyone, in this article I would like to introduce and guide the basic practice of installing docker, learning images and launching containers from images. You can read through the basic concepts from other articles, here I started to practice.
Install Docker on ubuntu
Because the installation does not have much to say you just run the commands as below
1 2 3 4 5 6 7 8 |
sudo apt update sudo apt install apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" sudo apt update apt-cache policy docker-ce sudo apt install docker-ce |
that’s it installed, you can see the docker status by command
1 2 |
sudo systemctl status docker |
Or view version and info by command
1 2 3 |
docker --version docker info |
The installation is basically finished, now let’s move on to understanding which image
Learn about images
Concept: Image in docker is software packaged and managed by docker
- For example:
image packing ubuntu operating system => we have ubuntu image
image packing mysql database administration system => we have a mysql image
- Images can only be read, not modified
When the image is launched by the docker, the executable versions of the images are called containers, which can write data into them.
- In order to have the containers running the applications, we need the images first.
- To check which images docker has, run the command “docker images”
- .
The repository column is the image name, the tag column is the version, the latest version is the final version
These images are taken from the docker hub repository: https://hub.docker.com/
The hub images can be searched using the docker search name_image
command
- Download the image from docker Hub
Download the image with the command docker pull name_image:tag
example need to download image ubuntu version 16.04
use the command: docker pull ubuntu:16.04
check: docker images will see ubuntu image
- delete the image with the command
docker image rm ubuntu:16.04
or delete by ID image
docker image rm id_image
Run a container
for example, running the container from the ubuntu image
docker run -it ubuntu:latest
-it is the parameter, where the parameter i means the container can receive interactions, the parameter t is able to connect to the terminal
ubuntu: lastest: is the image we use to create the container
After running the command docker run -it ubuntu:latest
terminal has moved to the container created from the ubuntu image with the root account
Check this ubuntu container information using the cat /etc/*release
command
- We open another terminal to check which docker has running containers
We see the newly created ubuntu container above is running: the above information shows us the container with Id 0a46 … generated from ubuntu image: latest
- Back in the terminal in the container we try to exit this container with the command
exit
So we have turned off the newly created container and returned to the terminal on the current machine, using the docker ps
command to check but the container is running will no longer see the newly created container.
To relaunch that container, we first use the docker ps -a
command to see all the currently stopped containers
You can re-launch the container with the command
docker start id_container
! id_container we can write the first few characters to distinguish it from other ids. then run the docker ps
command to see the containers running
- To return to the command line of the container we are running, we use the docker attach command id_container
End
Above is the basic concept of image, how to create a container, next article we will learn more about docker knowledge. Thanks mn