環境
- VMware Workstation Pro
- ubuntu-23.04
常用命令
- 拉去容器映象
docker pull image-name
- 啟動容器
docker run CONTAINER-ID
- 停止容器
docker stop CONTAINER-ID
- 執行容器命令
docker exec nginx nginx -t
root@ubuntufordocker:/etc/docker# docker exec 0f355428a2f0 nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
- 對映本地埠
docker run -d -p 8080:80 nginx
將容器內的80埠對映為宿主機的8080埠
docker run -d -p 80 nginx
將容器內的80埠對映為宿主機隨機埠,透過docker ps可以檢視對映的具體埠。
- 連線容器命令列
docker exec -it CONTAINER-ID bash