Microservices 101-I tried putting Docker on Ubuntu-

Introduction

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.

Difference between container type virtual environment and hypervisor type virtual environment

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. スクリーンショット 2021-01-07 20-10-07.png 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.

Installation

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.

  1. First, delete the old version if it is included.

sudo apt-get remove docker docker-engine docker.io containerd runc

  1. Set up the repository. Okimari's magic. w

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 スクリーンショット 2021-01-07 22-45-38.png

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"

  1. Install Docker Engine. I'm sorry again. w

sudo apt-get update

And install

sudo apt-get install docker-ce docker-ce-cli containerd.io

It's finished. Thank you for your hard work.

Play a little

It is like this to check the version of Docker.

docker --version

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. スクリーンショット 2021-01-07 23-24-32.png After this, if you display the container list and image list, it will look like this. スクリーンショット 2021-01-07 23-46-26.png

Let's add one more ubutu. I named the container Ubuntu1.

docker run --name="Ubuntu1" ubuntu

スクリーンショット 2021-01-07 23-54-37.png 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 スクリーンショット 2021-01-08 00-08-50.png

How to delete a container

docker rm container ID

How to delete an image

docker rmi image ID

Uninstall

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.

Finally summary

I would like to post about how to manage containers in the next and subsequent posts. Thank you very much.

reference

  1. Explain what Docker is for beginners! Basic commands are also https://udemy.benesse.co.jp/development/system/docker.html 2.docker docs、https://docs.docker.com/ 3.Open Container Initiative、https://opencontainers.org/about/overview/# 4.CLOUD NATIVE COMPUTING FOUNDATION、https://www.cncf.io/ 5.THE LINUX FOUNDATION、https://linuxfoundation.org/ 6.What is a Container?、https://www.docker.com/resources/what-container 7.Install Docker Engine on Ubuntu、https://docs.docker.com/engine/install/ubuntu/ 8.docker hub、https://hub.docker.com/

Relation

Change / update

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.

Recommended Posts

Microservices 101-I tried putting Docker on Ubuntu-
Try putting Docker in ubuntu on WSL
I tried putting Java on my Mac easily
I tried running Ansible on a Docker container
I tried installing docker on an EC2 instance
Install Docker on Ubuntu Server 20.04
Oracle Java 8 on Docker Ubuntu
I tried using YOLO v4 on Ubuntu and ROS
I tried the Docker tutorial!
I tried using Docker Desktop for Windows on Windows 10 Home
I tried putting XcodeGen + SwiftPM
I tried BIND with Docker
I tried to create React.js × TypeScript × Material-UI on docker environment
I tried running a Docker container on AWS IoT Greengrass 2.0
I tried running WordPress with docker preview on M1 Mac.
I tried installing CentOS 8 on ESXi 6.7
I tried deploying a Docker container on Lambda with Serverless Framework
I tried backing up MSX programs from cassette tape on Ubuntu
Run NordVPN on Docker (Windows) Ubuntu container
I tried using Scalar DL with Docker
I installed Docker on my Raspberry Pi 3
Use docker in proxy environment on ubuntu 20.04.1
I want to install PHP 7.2 on Ubuntu 20.04.
I tried to build AdoptOpenjdk 11 on CentOS 7
What is Docker? I tried to summarize
Until you run apache on ubuntu on docker
Run Ubuntu + ROS with Docker on Mac
I tried migrating the portfolio created on Vagrant to the Docker development environment
I tried using Docker for the first time
I tried using Junit on Mac VScode Maven
Liberty on Docker
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
I installed Docker on EC2 and started it
I tried OmniSci on CentOS 7 + GeForce RTX 2080 Ti.
I tried Spring.
I tried touching Docker for the first time
I tried tomcat
I tried youtubeDataApi.
I tried refactoring ①
I tried FizzBuzz.
tmux on Ubuntu
I tried running Java on a Mac terminal
I tried JHipster 5.1
Redmine on Docker
I tried Getting Started with Gradle on Heroku
Bad Gateway came out when I tried to connect Grafana and InfluxDB on Docker
Systemctl cannot be used on Ubuntu inside Docker container
I built an Ubuntu environment on Windows 10 using WSL2.
I tried to summarize the state transition of docker
I tried installing the Docker Integration plugin in IntelliJ
I tried using Log4j2 on a Java EE server
Rails6 I tried to introduce Docker to an existing application
What I stumbled upon when installing Ruby on Ubuntu
[WIP] I tried the configuration of Docker + Streama + NFS
I tried to build an environment using Docker (beginner)
Web Bluetooth on Ubuntu20.04
[I tried] Spring tutorial
Reinstall Kubernetes on Ubuntu 19.10
Docker installation on CentOS 6
I tried using Gson