Docker : Access to Container Services2023/04/27 |
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/ubuntu-nginx /usr/sbin/nginx -g "daemon off;" 5f4ccfba0a2e3f37ec2cd7c332fb1ee41f303ca2cdcd6db40cb823af795e7e63root@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5f4ccfba0a2e srv.world/ubuntu-nginx "/usr/sbin/nginx -g …" 12 seconds ago Up 11 seconds 0.0.0.0:8081->80/tcp, :::8081->80/tcp fervent_austin # create a test page root@dlp:~# docker exec 5f4ccfba0a2e /bin/bash -c 'echo "Nginx on Docker Container" > /var/www/html/index.html'
# verify it works normally root@dlp:~# curl localhost:8081 Nginx on Docker Container |
Sponsored Link |
|