【Azure】 I've participated in hands-on introductory practices from Docker to kubernetes
Participating Events
- Azure Antenna:https://azure.connpass.com/event/77515/
Purpose of Participation
- I was interested in Docker and kubernetes, but didn't touch them much.
- Join to take the first step in handling containers
- If possible, I would like to make good use of containers in the future.
Event Summary
Flow of the day
First half: Overview of containers and Docker Second half: kubernetes
While listening to the explanation, it was a flow to try it hands-on every time.
data
Since it is published, please refer to here for details.
Hands-on content (excerpts from the knowledgeable aspects)
Containers overview
- Containers are the small foundation on which applications run, not virtualization
- Even if you run a container in the centos or ubuntu environment, the actual thing that runs is the host's kernel
- The container ps 1 is the init process. It runs on a completely different pid from the host's point of view.
- Only one container, one type of process should work
merit
-
High portability
- Improved business continuity
- Can be staged, developed, and put into production, in the same environment (eliminating environmental differences)
- ⇒ Paas, a little different from serverless (easy development etc.)
-
Efficient use of computer resources
- Load balancing, even redundancy (k8s)
-
Easy to DevOps ready
- Infrastructure configuration can also be code-managed
- How GitHub works with
Easy to make and erase
Main usage scenarios
- Get the application up and running
- Application servers, Web servers, etc.
- Make tools and other utilities work
- Azure's CLI tools are also Docker images, and Python or the right version is packed.
★ The de facto standard for containers is Docker
Docker
Docker commands
The important thing is /var/run/docker.sock Only users with permissions can run docker commands
Docker installation
Note that docker.io Packages # are completely different from docker packages
$ sudo apt update && sudo apt install docker.io -y
Find a Docker image
$ docker search ***
STARS: Like-like metrics
OFFICIAL : / The lack of one is something that the developer put out
: Tag Name
Tags are also important for management If nothing is added, latest is auto-completed
Assign a port for the Docker container on the host
For example, bind host 80 to 80 in the container. This port forwarding is provided by iptables(nat)
Key Docker Commands
$ docker run ****
$ docker ps
$ docker ps -a
$ docker images
$ docker pull ****
$ docker stop [UUID]
Docker Lifecycle
- build
- pull / build
- commit
- rm / rmi
- ship
- push # Register in registry
- run
- run / stop / kill
docker run
$ docker run -it *****
Shell interactive: -it option
If the name and tag match, use the image if it is local.
If you don't have an image, take it from the remote
docker exec
$ docker exec -it [id] sh
Can be in motion as a daemon
Often used in debug etc.
Create your own container
FROM alphine
MAINTENER なくてもいい
RUN コマンド ex) apt install python2 apache2
CMD ["command"] # メインプロセス docker 起動時の最後のコマンド
ex) CMD [ "httpd -DFOREGROUND" ]
$ docker build -t myapache2 ./
Cache is used when doing the same work
Build a Dockerfile after you change it.
Notes to keep in mind
- Changes in the container are not saved [immutable]
- It should not be used as a database server (it should not be stored in a container)
- Containers and images remain if they are not erased
$ docker stop
# The docker process disappears$ docker ps -a
What you can see is that there are still containers that have not been started- Stopped containers remain as they are. The image also remains. Each remains in the path below
/var/lib/docker/
/var/lib/docker/image/aufs
- When building a container, the cache is used
- changes may not be reflected unintentionally
- When the host is restarted, the container will not start without permission.
- When docker run, you can run it with the --restart=always option
- The log you want to output is standard output / error output
- Do not put it in the log file
- Run the process you want to run in the main on foreground and not terminate it
- Leave the command prompt in a state where it does not return, do not daemonize
- ⇒ k8s is also designed with this in mind
- To see standard output and standard error output
$ docker logs -f [uuid]
alpine linux
Ultra-lightweight Linux optimized for containers Package management tools are apk
# apk update
# apk add
# apk search
Compared to Ubuntu and the like, the size is much smaller The one that came with -alpine when searching for tags is a lighter version. Alpine-based
Docker structure
Docker works with linux 2.6.32-431 and above Use cgroups, namespace, chroot, etc.
Read/write area |
---|
Diff Image |
Diff Image |
Base image |
I have a base image (like ubuntu) By building, the differencing image is layered on top of each other, When I run, I feel like I'm sticking the literacy layers together.
kubernetes
I'll write about it on a separate page.
impressions
It was a great opportunity to introduce Docker and Kubernetes. There was a lot of content, and I got the impression that it took a little time. The lecturer's explanation was easy to understand and easy to understand. From now on, I will create my own environment and verify various things.