Docker : Access to Container Services2025/08/08 |
|
If you'd like to access to services like HTTP or SSH which is running in Containers as a daemon, Configure like follows. |
|
| [1] | For example, Use a Container image which has Nginx. |
|
[root@dlp ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/centos-nginx latest b587aa926cbf 5 minutes ago 345MB quay.io/centos/centos stream10 02ae49ff109e 7 weeks ago 306MB # start a Container and also run Nginx # map the port of Host and the port of Container with [-p xxx:xxx] [root@dlp ~]# docker run -t -d -p 8081:80 srv.world/centos-nginx /usr/sbin/nginx -g "daemon off;" 508cc982a1136482d8aeac6f98c1ec996401b0c803d9d87a00f5d5ef2bbff14a[root@dlp ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 508cc982a113 srv.world/centos-nginx "/usr/sbin/nginx -g ..." 16 seconds ago Up 16 seconds 0.0.0.0:8081->80/tcp, [::]:8081->80/tcp competent_albattani # create a test page [root@dlp ~]# docker exec 508cc982a113 /bin/bash -c 'echo "Nginx on Docker Container" > /usr/share/nginx/html/index.html'
# verify it works normally [root@dlp ~]# curl localhost:8081 Nginx on Docker Container |
| Sponsored Link |
|
|