Linux installation Docker

1. Install dependencies

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

 

2. Set Ali cloud mirror source

Because docker default mirroring the official source address is abroad, very slow, there will be a data source to Ali cloud image. Of course, there are other domestic mirroring source, which is not introduced one by one.

sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

3. Installation Docker-CE

Docker CE (Community Edition) free community version, is docker engine.

sudo yum install docker-ce

 

4. Start Docker-CE

Adding start Docker Service

sudo systemctl enable docker

sudo systemctl start docker

 

5. establish user groups Docker

User, but the user can have access to UnixSocket only user root and docker user group to be able to carry out communication between the engine and docker command Docker by UnixSocket visit, so we need to build a docker user group, and will need to access the docker to add among this group to a user.

1. Set up a user group Docker

sudo groupadd docker

2. Add the current user group to docker

sudo usermod -aG docker $USER

6.GUI Management Configuration (optional )

gui management tools need to install, you can use, not mandatory.

Portainer 

Official Address: https://portainer.io/install.html (if foreign address can not access the recommendations over the wall)

Installation command:

docker volume create portainer_data

docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

  

Then through their own IP + 9000 Port Access

 

Here you can see your containers, mirrors and so on.

 

7.Docker basic concepts

镜像 (Image)

This kept inside the application and required dependencies and runtime environment such as running a webapp

Why do we need more mirrors? When developing, building and running of container applications, we often have different priorities. By providing different mirror for these separate task 

 

Container (Container)

Examples of mirroring. A representative of a container application running, process or service. It is mirrored by Docker, the execution environment and the standard instruction set composition. When the need to expand the service, I 

To really run up mirroring something, mirrored inside the container. It can be seen as a completely isolated case.

Mirroring a container instance represents a separate process.

Hub

Remote storage mirroring platform, has a lot to make a good mirror for example redis mongodb on the hub.

Warehouse (repository)

Warehouse to save local mirror.

After the image is built, it can run directly on the current host, but if you need to use this image on another server, you need a centralized storage, distribution mirroring service. Warehouse is one such service.

8.Docker commonly used commands

PS Docker - All vessels -a view the currently running show has been stopped, including container

pull Docker  - pulling mirror

docker rmi --删除镜像 后面可以直接根据镜像 名称或者tag 前首字母匹配

docker start  container_id --打开容器 (这里可以是容器id或名称)

docker stop container_id --停止容器 (这里可以是容器id或名称)

docker rm --删除容器(只有停止的容器才可以删除)

docker build --使用 Dockerfile 创建镜像

docker exec --容器中执行命令,例如:docker exec -it  container_id(容器名或id) /bin/bash  (bin/bash要执行的命令或工具)

docker logs --查看 容器日志 ,例如:docker logs -f -t --tail 10 container_id (容器名或id) 

 

运行容器

docker run -it --rm -p 8000:80 --name aspnet_sample microsoft/dotnet__

--name 容器名称 ,后面跟着是镜像路径或名称

--rm 运行完后删除该容器 

-p  端口映射 8000 外部端口 80镜像里面运行的端口 将8000映射到镜像里面的80

-it  输出容器命令行的内容 即容器的自身的程序输出在控制台 有点类似前台运行

-d 和it相反  隐藏后台运行

Guess you like

Origin www.linuxidc.com/Linux/2019-12/161823.htm