You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

参考资料

https://www.runoob.com/docker/docker-container-usage.html

使用官方安装脚本自动安装

yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y

启动Docker

systemctl start docker

配置镜像源

mkdir -p /etc/docker

tee /etc/docker/daemon.json <<EOF
{
    "registry-mirrors": [
        "https://docker.m.daocloud.io",
        "https://huecker.io",
        "https://dockerhub.timeweb.cloud",
        "https://noohub.ru"
    ]
}
EOF

systemctl daemon-reload
systemctl restart docker

检查是否安装成功

docker run hello-world

卸载 docker

yum remove docker-ce

删除镜像、容器、配置文件等内容

rm -rf /var/lib/docker

下载Ununtu容器

 docker pull ubuntu

进入容器

docker run -it ubuntu /bin/bash
-i: 交互式操作。
-t: 终端。
ubuntu: ubuntu 镜像。
/bin/bash放在镜像名后的是命令这里我们希望有个交互式 Shell因此用的是 /bin/bash。

查看所有容器

 docker ps -a

启动容器

docker start e115386be6b4 

后台运行容器

docker run -itd --name ubuntu-test ubuntu /bin/bash

停止容器

docker stop 0651803d31f4

重启容器

docker restart 0651803d31f4

进入容器

docker exec -it 0651803d31f4 /bin/bash

查看可用版本

docker search tomcat

下载Tomcat镜像

docker pull tomcat

docker pull tomcat:9.0

docker pull tomcat:8.0

查看已有Tomcat镜像

docker images|grep tomcat

运行Tomcat镜像

docker run --name tomcat -p 8080:8080 -v $PWD/test:/usr/local/tomcat/webapps/test -d tomcat

命令说明:

-p 8080:8080将主机的 8080 端口映射到容器的 8080 端口。
-v $PWD/test:/usr/local/tomcat/webapps/test 将主机中当前目录下的 test 挂载到容器的 /test
cd /usr/local/tomcat/webapps.dist/
mv docs/ ../webapps/
mv examples/ ../webapps/
mv host-manager/ ../webapps/
mv manager/ ../webapps/
mv ROOT/ ../webapps/

通过浏览器访问

docker ps