[Docker] ‘s Basic Usage

Get

bash 复制代码
# Mac
brew install docker-desktop

Image

Docker Hub

sh 复制代码
# pull(specific platform)
docker pull [--platform=xxx][image]

# query
docker images

# remove image
docker rmi [ID/NAME]

Container

sh 复制代码
# run
docker run 
[-d, detached mode] 
[-p xx:xx, port mapping] 
[-v /xx/xx:/xx/xx, volume mapping] 
[-e, environment]
[--name xx, specify the name]
[-it --rm, enter container and remove it automatically after use]
[--restart always/unless-stopped, always restart & restart contrainer that were unexpected stopped but do not restart contatiner that were manually stopped]
[--network {host} xx]
[ID/NAME]

# process status (only running)
docker ps [-a, all containers]

# remove container
docker rm [-f, --force] [ID/NAME]

# volume
docker volume list
docker volume rm [NAME]
docker volume prune -a	# remove all local volumes not used by containers

# option
docker start [ID/NAME]
docker stop [ID/NAME]

# inspect, view container information. 
docker inspect [ID/NAME]

# logs
docker logs [-f, --follow ] [ID/NAME]

# enter the interior of the container
docker exec -it [ID/NAME] /bin/sh

# run command on the interior of the container 
docker exec [ID/NAME] [CMD]

P.S.

The usage of docker run -v

  1. Bind Mount, synchronous update
    -v /host:/container[:ro, read-only]
  2. Named volume, local data persistent
    -v myvolume:/container

Docker file

sh 复制代码
# Docker file
FROM [basic image]

WORKDIR [change a dir as the woking dir]

COPY [relative local dir] [relative image dir]

RUN [commands to install dependencies]

EXPOSE [port]

CMD [ ["xx", "xx"], the default command executed when the container start]
sh 复制代码
# Build 
docker build [-t {username/}xx{:version}, named image] [build dir]

# Push image to Docker Hub
docker login
docker push [username/imageName]

Network

sh 复制代码
# Create Subnet
docker network create [NAME]

# remove 
docker network rm

# list
docker network list

Docker Compose

sh 复制代码
# docker-compose.yaml
services:
	serviceA:
		image: xx
		environment:
			xx: xx
		volumes:
			- /datadir:/data/db
	
	serviceB:
		iamge: xx
		ports:
			- 8081: 8081

# Start
docker compose [-f /dir/file, file] up [-d, detached mode]  
相关推荐
程序员老赵6 小时前
10 分钟部署 OpenCode:Docker 一键安装,浏览器打开就能用 AI 写代码(附完整命令与排错)
docker·容器·ai编程
WangMingHua11111 小时前
LM Studio Docker 部署——本地大模型一键启动
docker
曲幽2 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate
武子康3 天前
调查研究-183 Apple container:Mac 上用轻量 VM 跑 Linux 容器,Swift 会改写本地容器体验吗?
docker·容器·apple
Alsn866 天前
等待学习-学习目录:Docker 容器安全攻防
学习·安全·docker
JLWcai202510096 天前
铸造领域树脂砂轮|金利威多场景解决方案,20 + 配方覆盖全需求
mongodb·zookeeper·eureka·spark·rabbitmq·memcached·storm
2601_961875246 天前
决战申论100题2026|最新|范文
linux·容器·centos·debian·ssh·fabric·vagrant
java_cj6 天前
深入kube-apiserver认证机制:从Bearer Token到mTLS的完整认证链解析
linux·运维·服务器·云原生·容器·kubernetes
程序员老赵6 天前
服务器没有桌面?Docker 跑个 Chrome,浏览器就能远程用
docker·容器·devops
杨浦老苏6 天前
轻量级Docker仪表板Servedash
运维·docker·监控·群晖·仪表板