Docker installation, start tomcat and visit

docker installation

Environment centos7

1. Check the kernel version, it must be 3.10 and above
uname -r
2. Install docker
yum install docker
Insert picture description here
3. Start docker
[root@localhost ~]# systemctl start docker
4: Check the version number
[root@localhost ~]# docker -v
Insert picture description here
5. Set up docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service .
6. Stop docker
systemctl stop docker

Container operation

1. Search for the mirror
[root@localhost ~]# docker search tomcat
2. Pull the mirror
[root@localhost ~]# docker pull tomcat
Insert picture description here

3. Start the container according to the image
docker run --name mytomcat -d tomcat:latest

(–Name'The name of the window you take') -d means tomcat is running in the background: latest means which container is started, preferably id (IMAGE_ID)d5eef28cf41d

It is activated here and cannot be accessed by the host. First, there is no external port mapping, second, the firewall may not be closed, and third, the access may report 404.
So: stop

The correct way to start

docker run -d -p 8888:8080 tomcat

-p means to map port 8888 of the desired machine to port 8080 in the container

Note that if docker is started but the service (tomcat) in docker is not started, and the firewall is turned off in the middle, then docker must be restarted, otherwise an error will be reported when starting tomcat

Insert picture description here
Insert picture description here
Insert picture description here

The last visit reported 404:

Insert picture description here

the reason:

The port mentioned above may not be mapped or the firewall is not turned off.
View firewall status service firewalld status
Turn off service firewalld stop
Insert picture description here

I encountered another situation

Enter
the tomcat container id /bin/bash started by docker exec -it in the tomcat container
Insert picture description here

ls -l

Insert picture description here

Enter to view the webapps folder and it is empty

We need to delete the webapps directory and replace the webapps.dist directory with webapps
Insert picture description here
mv webapps.dist webapps

Then go to the Internet
http://xxxx:8080/ (xxxx enter the IP address)
Insert picture description here

reference

https://blog.csdn.net/whatday/article/details/86762264?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

https://blog.csdn.net/weixin_48558574/article/details/107062344

Guess you like

Origin blog.csdn.net/qq_26634873/article/details/108556253