CentOS7 installation and operation Docker

Keywords: Operation & Maintenance Docker Tomcat yum RPM

1. Confirm kernel version

CentOS7 kernel is generally 3.10, which meets the installation conditions (> = 3.8)

uname -r
//perhaps
uname -a

2. update pack

yum unpdate -y

This process may be a little slow. If there is a higher version of kernel, it will update back to 3.10

View the current default kernel

grub2-editenv list

Changed to newer kernel version

If you want to remove other kernels, reboot and reconnect

View all cores

rpm -qa | grep kernel
//perhaps
yum list installed | grep kernel

Delete kernel

rpm -e kernel-3.10.0-1062.el7.x86_64
//perhaps
yum -remove kernel-3.10.0-1062.el7.x86_64

3. Install relevant software

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

4. Set yum source

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

5. View all docker versions in the warehouse and select one to install

yum list docker-ce --showduplicates | sort -r

yum install docker-ce-18.03.1.ce -y

Verify installation succeeded

docker version

6. Start Docker and join in startup

systemctl start docker
systemctl enable docker

View startup status

systemctl status docker

7. Stop Docker

systemctl stop docker

8. operation

View docker default working directory

docker info | grep "Docker Root Dir"

Modify docker working directory

vim /etc/docker/daemon.json

Add the specified docker working directory

{ "data-root": "/xx/xx" }

Load restart

systemctl daemon-reload

systemctl restart docker

Add / modify docker image source

vim /etc/docker/daemon.json

//Content:

{ "registry-mirrors": ["https://91cntlkt.mirror.aliyuncs.com"] }

//Load restart

systemctl daemon-reload

systemctl restart docker

Grab Hello word from the warehouse

docker image pull library/hello-world
//perhaps
docker image pull hello-world
//perhaps
docker pull hello-world

View mirroring

docker images
//perhaps
docker image ls

Running mirroring

docker container run hello-world

Note: the docker container run command can automatically grab images from the warehouse

List containers that are running on this machine

docker container ls
//perhaps
docker ps

List all containers on this machine, including those that are terminated

docker container ls --all
//perhaps
docker ps -a

The container file that stops running will still occupy the hard disk space

You can use the docker container rm command to delete (id name is OK, container can be omitted)

docker container rm c3920c66c550

Export mirroring

docker save hello-world > /tmp/hello-world.tar.gz

delete mirror

docker rmi hello-world
//perhaps
docker image rm hello-world

Import mirroring

docker load < hello-world.tar.gz

Build tomcat service

docker pull tomcat

Start tomcat in the background

docker run -d --name mytomcat -p 8888:8080 tomcat

View long ID

docker inspect -f '{{.Id}}' mytomcat

Enter the container through an interactive interface

docker exec -it mytomcat /bin/bash

view log

docker logs mytomcat

Copy

docker cp mytomcat:/usr/local/bin /data/docker/tomcat

Stop tomcat

docker stop mytomcat

9. Problems encountered

9.1 unable to access the home page after starting tomcat (the original blog address was not found later)

docker exec -it mytomcat /bin/bash
root@0a48303e4cf0:/usr/local/tomcat# mv webapps webapps.old
root@0a48303e4cf0:/usr/local/tomcat# mv webapps.dist webapps

Restart tomcat and docker after modification

Release port 8080 or turn off firewall

9.2 No chain/target/match by that name

systemctl restart docker

https://blog.csdn.net/u013948858/article/details/83115388

9.3 the mytomcat path of the copy is actually a local path

For example, mytomcat:/usr/local/tomcat/webapps can't access tomcat from behind local, and no solution has been found.

10. reference

https://blog.csdn.net/u014069688/article/details/100532774

https://blog.csdn.net/wangganggelian/article/details/49848305

http://www.ruanyifeng.com/blog/2018/02/docker-tutorial.html

https://www.linuxidc.com/Linux/2019-05/158742.htm

https://www.cnblogs.com/ding2016/p/10884128.html

https://blog.csdn.net/u010588262/article/details/80432212

Posted by jameslloyd on Wed, 19 Feb 2020 06:38:38 -0800