Docker - Basic Commands
Images
查詢images:
[root@localhost ~]# docker images Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. REPOSITORY TAG IMAGE ID CREATED SIZE localhost/http-sample_http-service latest f8dec1371ce9 9 hours ago 44.4 MB docker.io/library/nginx alpine 529b5644c430 2 months ago 44.4 MB刪除image:
docker rmi image_name
Containers
查詢所有containers(包含停止):
[root@localhost ~]# docker ps -a Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f81f36b9cee1 docker.io/library/nginx:alpine nginx -g daemon o... 9 hours ago Created 0.0.0.0:80->80/tcp http-sample_nginx_1 621e03be78a6 localhost/http-sample_http-service:latest nginx -g daemon o... 9 hours ago Exited (0) 9 hours ago http-sample_http-service_1停止、啟動、重啟container、刪除:
docker stop container_name_or_id
docker start container_name_or_id
docker restart container_name_or_id
docker rm container_name_or_id
查詢container log:
[root@localhost http-sample]# docker logs 41c242135b04 Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh /docker-entrypoint.sh: Configuration complete; ready for start up 2024/01/14 02:29:39 [notice] 1#1: using the "epoll" event method 2024/01/14 02:29:39 [notice] 1#1: nginx/1.25.3 2024/01/14 02:29:39 [notice] 1#1: built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10) 2024/01/14 02:29:39 [notice] 1#1: OS: Linux 5.14.0-284.11.1.el9_2.x86_64 2024/01/14 02:29:39 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576 2024/01/14 02:29:39 [notice] 1#1: start worker processes 2024/01/14 02:29:39 [notice] 1#1: start worker process 25 2024/01/14 02:29:39 [notice] 1#1: start worker process 26 2024/01/14 02:29:39 [notice] 1#1: start worker process 27 2024/01/14 02:29:39 [notice] 1#1: start worker process 28查詢詳細資訊:
docker inspect container_name_or_id進入container內使用shell:
docker exec -it container_name_or_id /bin/sh
Docker-Compose
在對應的目錄直接執行去啟動或停止docker-compose。
podman-compose up podman-compose down假如懷疑build container過程發生問題要看log,
podman-compose up -build