Docker installation and simple use in Centos7.x system

Introduction to Docker

  • Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable container, and then publish it to any popular Linux machine or Windows machine. It can also be virtualized. The container is completely Using the sandbox mechanism, there will be no interface to each other.
  • A complete Docker consists of four parts: Docker Client (client), Docker Daemon (daemon), Docker Image (mirror) and Docker Container (container).
  • Docker uses a client-server (C/S) architecture pattern and uses remote APIs to manage and create Docker containers. Docker containers are created from Docker images. The relationship between containers and images is similar to objects and classes in object-oriented programming.


Environmental requirements

1、只能是64位的系统;
2、要求centos7以上系统的内核版本不低于3.10。

installation steps

1. Remove the old version of docker

yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

2. Install dependent packages

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

3. Add yum software source
unofficial source (such as Alibaba Cloud)

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

official source

yum-config-manager  --add-repo https://download.docker.com/linux/centos/docker-ce.repo

4. Update the yum software source cache

yum makecache fast

5. Install docker

yum  -y install  docker-ce

During installation, if an error is reported that the rpm package cannot be found, first download the rpm package manually through wget, and then execute the installation command again.


Simple commands for using Docker images and containers

1. Check the docker version: docker version
2. Query the image: docker search imageName [image name: such as centos]
3. Obtain the image: docker pull imageName [image name: such as centos]
4. List the image: docker image ls
5. Query Image volume: docker system df
6. Delete image: docker image rm imagesID
7. Start container: docker run --name *** -p port:port -d [image name] or docker start [containerID/containerName]
8. Exit Container: exit/docker stop containerID
9. Enter the container: docker attach containerID or docker exec -it containerID
10. Delete the container:
1) Delete the terminated state: docker container rm [ID]
2) Delete the running state: docker container rm -f [ID]
3) Delete all terminated: docker container prune


Docker install Tomcat instance

1. Obtain the tomcat image:

docker  pull  tomcat

2. Create and run the tomcat container:

docker run  --name  tomcat  -p 127.0.0.1:8080:8080    -d  tomcat
docker run  --name  tomcat  -p 127.0.0.1:8080:8080    -d  tomcat --restart=always
--name:容器名 
-p:后面接IP地址(可以不设):接宿主机端口:容器端口  
-d:后台运行

3. Enter the container:

docker   exec/attach  -it  tomcat  bash
exec进入容器后使用exit命令退出容器,只会退出容器,让容器在后台继续运行
attach进入容器后使用exit命令退出容器,会直接关闭容器
-it:交互模式进入容器

4. Exit the tomcat container: exit
5. Stop the tomcat container: docker stop tomcat
6. Start the tomcat container: docker start tomcat
7. Delete the tomcat container: docker container rm -f tomcat

Guess you like

Origin blog.csdn.net/crossoverpptx/article/details/129601197