查看docker容器映射的端口号和目录

sudo docker inspect my-nginx

my-nginx是容器的名字,也可以用容器id, 可以使用sudo docker ps -a查看

sudo docker run --name my-nginx -v /var/www/html:/usr/share/nginx/html -d -p 8080:80 nginx
➜ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS            PORTS     NAMES
98ecfd3429be nginx "/docker-entrypoint.…" 20 seconds ago Up 20 seconds 0.0.0.0:8080->80/tcp my-nginx

下例是本地主机的8080端口映射到容器的80端口

本地主机目录/var/www/html:容器目录/usr/share/nginx/html
sudo docker inspect my-nginx
"HostConfig": {
            "Binds": [
                "/var/www/html:/usr/share/nginx/html"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "8080"
                    }
                ]
            },
posted @ 2020-12-18 21:51  船长博客  阅读(13326)  评论(0编辑  收藏  举报
永远相信美好的事情即将发生!