First, download and install
1, the server checks whether there docker
yum list installed | grep docker
2, installation
Here we must mention, CentOS-Extras repository centos 7 system has brought Docker, therefore has installed:
(1)yum install -y yum-utils device-mapper-persistent-data lvm2 (2)yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo (2)yum makecache fast (3)yum install -y docker-ce
3, View docker version
Version docker # docker after installation docker info # after docker start using
For example: use the command docker version, echo information is as follows:
Here docker installation is successful.
4, the next start docker
daemon-reload systemctl # reload service profile systemctl enable docker # boot docker automatically systemctl Start docker # start docker systemctl Status docker docker # View status
Two, Docker tomcat and deploy applications
1. Check local service mirroring resources
For example: I want to find a mirror resource tomcat, the command is as follows:
docker search tomcat
Echo information:
2, to pull the local mirror
docker pull tomcat
Because here mirror source and network problems that may be a bit slow. . . .
3, the mirror successfully pulled, using the following command to view
docker images
Echo information is as follows:
4, using the docker run command to run tomcat container
docker run -di --name=tomcat_t -p 8080:8080 tomcat:latest
Here are the parameters:
5, using a browser to access tomcat service
(1) Depending on the server version of the system image, two methods are given open firewall ports
The first: firewall
The second: iptables
(2) because I was with Ali cloud server, where the need to open ports in the security group of ECS console
As long as the direction of the inlet is provided, to access external
(3) In the browser enter the server outside the network IP + port is specified, you can enter to access tomcat welcome page
6, if I copy the file from the host to the container inside, how to operate:
docker cp /root/soft/docker/war/index.html tomcat_t: / usr / local / tomcat / webapps / ROOT # docker cp to copy the file path name of the container: a path inside the container to be copied to the corresponding
文件源路径:/root/soft/docker/war/index.html
容器名称:tomcat_t
容器对应路径:/usr/local/tomcat/webapps/ROOT
7、那么从容器里面拷文件到宿主机呢?
docker cp tomcat_t:/usr/local/tomcat/webapps/ROOT/js/index.html /root/soft/docker/war # docker cp 容器名:要拷贝的文件在容器里面的路径 要拷贝到宿主机的相应路径
文件指定路径(宿主机):/root/soft/docker/war/index.html
容器名称:tomcat_t
容器文件源路径:/usr/local/tomcat/webapps/ROOT