When I was studying microservices, the words container and Docker came up, and it seemed a little interesting, so I put Docker in Ubuntu. It is a memo at that time. Please have a look. By the way, when you put it in Windows, you need to be careful because the things to prepare differ depending on the version of Windows. How to do it is in docker docs (Reference 2). I would like to do this at a later date.
What is a container? Quoting from the Docker website (Reference 6)
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.
In short, it's a mechanism that allows software to run stably and quickly in multiple environments. w If the conventional virtual environment technology is a hypervisor, what is the difference from the container type virtual environment technology? Let's look at the figure below. Both the hypervisor and the container are layers for virtualization. Let's look at the layer above each layer. The OS (guest) is listed on the hypervisor. From the OS (guest) perspective, the hypervisor should seem to play the role of hardware. Next is the container, but the application is on top. From the application's point of view, the container should appear to play the role of the OS. I think the big difference is what role the virtualization layer plays in place of what. Each hypervisor type has an OS in the virtual environment and allocates CPU and memory. The container type contains only applications and shares CPU and memory. Somehow, the container type seems to be lighter and more flexible. w It is said that the Open Container Initiative (Reference 3) is part of the Linux Foundation that determines the specifications of containers/Docker. By the way, it is CLOUD NATIVE COMPUTING FOUNDATION (Reference 4) that determines the specifications of the orchestration tool Kubernetes, which also seems to be part of the Linux Foundation.
Next, let's see how to install it.
We will install based on the official Docker documentation. (Reference 7) This time, install using the repository. This is the method as of January 07, 2021.
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
Install the required packages so that the repository can be used over HTTPS.
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Install the official Doker GPG key.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Check the hash value (fingerprint) to see if the installed GPG key is correct. This key and hash value are subject to change, so it is recommended that you check the hash value in the official documentation (Reference 7) when doing this. At the time of writing this article, it was 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, so check the key with the last 8 digits.
sudo apt-key fingerprint 0EBFCD88
Finally set up the repository Here we will set up a stable version of x86_64/amd64.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
It's finished. Thank you for your hard work.
It is like this to check the version of Docker.
It looks like this to show the running container. If you add -a to the bottom, all containers will be displayed.
sudo docker ps
Display a list of images.
sudo docker image ls
Let's try the hello-world image.
sudo docker run hello-world
When executing for the first time, get the image from docker hub (Ref. 8), create a container, and start it. After this, if you display the container list and image list, it will look like this.
Let's add one more ubutu. I named the container Ubuntu1.
docker run --name="Ubuntu1" ubuntu
You can use the shell by starting ubuntu with the following command. However, a new container will be created instead of the container named Ubuntu1. ww
docker run -it ubuntu
How to delete a container
docker rm container ID
How to delete an image
docker rmi image ID
How to uninstall Docker
sudo apt-get purge docker-ce docker-ce-cli containerd.io
I tried to delete the images and containers under/var/lib/docker, so if you want to delete them cleanly, it seems that you also delete the files here.
sudo rm -rf /var/lib/docker
I don't know the cause, but after uninstalling it cleanly, I installed it again and got an error. I got a crash report, but ... I didn't see it. I'm sorry, I'm sorry, I'm sorry.
I would like to post about how to manage containers in the next and subsequent posts. Thank you very much.
2021/01/08 Addendum immediately w While docker run creates and executes an image, docker start seems to execute a container. Syntax docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...] docker start [OPTIONS] CONTAINER [CONTAINER...] If you already have a container created with an Ubuntu image
docker start container ID or container name docker exec -it container ID or container name bash docker stop container ID or container name
If you do, you can start the container → connect to the container (execute the bash shell) → stop the container. If you named the container yourself, I would like to find out that this was not the case. Even if it starts, it stops immediately.