Docker : Access to Container Services2020/12/14 |
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 exmaple, Use a Container image which has Nginx. |
# 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;" 9a70132c44430a0fe8c3836fb52591e95864bfc9b96f0ae763bf92048a3fbf37[root@dlp ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9a70132c4443 srv.world/centos-nginx "/usr/sbin/nginx -g …" 14 seconds ago Up 13 seconds 0.0.0.0:8081->80/tcp pedantic_kilby # create a test page [root@dlp ~]# docker exec 9a70132c4443 /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 |