Docker : Access to Container Services2024/06/13 |
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/ubuntu-nginx latest f3f6605bb20c 2 minutes ago 123MB ubuntu latest 17c0145030df 13 days ago 76.2MB # 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;" 3b04351142ecb3892017984e720306956aa9bb50b1e3745c7d42fb94cb341783root@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3b04351142ec srv.world/ubuntu-nginx "/usr/sbin/nginx -g …" 13 seconds ago Up 13 seconds 0.0.0.0:8081->80/tcp, :::8081->80/tcp hungry_hypatia # create a test page root@dlp:~# docker exec 3b04351142ec /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 |