Record a use of virtualbox and vagrant to install docker in centos environment and solve the problem of tomcat image 404

1. The built centos7environment

1. Initialize a Vagrantfilefile

command

mkdir centos7
cd centos7
vagrant init

2. Go to Vagrantfilethe directory of the file

command

cd centos7

Diagram

Insert picture description here

3. Startvagrant

command

vagrant up

Diagram

Insert picture description here
During the startup process, you may be 1) en0asked to choose the network card, as shown in the picture above , because I use Wi-Fi, I choose 1.

4. View vagrantthe status

command

vagrant status

Diagram

Insert picture description here

5. Entercentos7

command

vagrant ssh

Diagram

Insert picture description here

6. Switch to rootpermission

command

sudo -i

Diagram

Insert picture description here

7. Change the password and use the terminal to connect

command

vi /etc/ssh/sshd_config  # 修改PasswordAuthentication yes
passwd  # 修改密码,要输入两次
systemctl restart sshd # 重启sshd服务,让修改的生效

2. Installation dockerenvironment

1. Before uninstallingdocker

command

	sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

Diagram

Insert picture description here

2. Install the necessary dependencies

command

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

Diagram

Insert picture description here

3. Set up the dockerwarehouse

command

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

Diagram

Insert picture description here

4. Installationdocker

command

sudo yum install -y docker-ce docker-ce-cli containerd.io

Diagram

Insert picture description here

5. Startdocker

command

sudo systemctl start docker

Diagram

Insert picture description here

6. Set to start automatically after booting

command

sudo systemctl enable docker

Diagram

Insert picture description here

7. Test dockerwhether the installation is successful

command

sudo docker run hello-world

Diagram

Insert picture description here

8. Viewed dockerversion

command

[[email protected] ~]# docker version

Diagram

Insert picture description here

Three, solve the problem of tomcatmirroring404

1. Pull the tomcatimage to the local

command

docker pull tomcat

Diagram

Insert picture description here

2. View the local mirror

command

[[email protected] ~]# docker image ls

Diagram

Insert picture description here

4. Run local mirrortomcat

command

docker run -d --name my-tomcat -p 9091:8080 tomcat
  • docker run creates a container based on a certain image
  • -d Let the container run in the background, which is actually a process
  • --Name assign a name to the container
  • -p maps the port of the container to the port of the host

Diagram

Insert picture description here

5. View the running container

command

docker ps

Diagram

Insert picture description here

6. Viewip

command

ip a

Diagram

Insert picture description here

7, local access to tomcatthe 9090port

Insert picture description here
Unfortunately failed

8. Enter the container

command

docker exec -it a1bce6e206da /bin/bash

Diagram

Insert picture description here

9. Viewed tomcatdirectory

command

ls

Diagram

Insert picture description here

10. Go to the webappsfolder

command

cd webapps

Diagram

Insert picture description here

11. View webappsthe contents of the folder

command

ls -a

Diagram

Insert picture description here
Found that there is nothing under the changed folder

12. Delete the webappsfolder and copy webapps.disttowebapps

command

cd ..
rm -rf webapps
 cp -r webapps.dist webapps

Diagram

Insert picture description here

13, view webappsthe contents of the folder

command

ls

Diagram

Insert picture description here
See that there is content under the webapps folder

14. Visit againtomcat

Insert picture description here
The visit is successful! ! ! Roar roar, 😄😫😢