[命令] Docker Command

docker常用命令:映射端口、映射目录自行更改

国内源

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
mkdir -p /etc/docker 

vim /etc/docker/daemon.json

{"registry-mirrors": ["https://1197heba.mirror.aliyuncs.com"]}

systemctl daemon-reload

systemctl restart docker

systemctl enable docker

mysql56

1
2
3
4
5
6
7
8
9
docker run \
--name mysql56 \
--privileged=true \
--restart=always \
-v /disk/home/mysql/data:/var/lib/mysql \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=system \
-d mysql:5.6 \
--lower_case_table_names=1

tomcat9_jdk8

1
2
3
4
5
6
7
8
docker run -d -p ${war_backend_port}:8080 \
--name t-${docker_name} \
--privileged=true \
--restart=always \
-v /disk/home/${docker_name}/tomcat/webapps:/usr/local/soft/tomcat/webapps/ \
-v /disk/home/${docker_name}/uploadPath:/home/${docker_name}/uploadPath \
-v /disk/home/${docker_name}/ureport2:/home/${docker_name}/ureport2 \
-e TZ=Asia/Shanghai docker.io/donglsheng/tomcat9_jdk8

nginx

1
2
3
4
5
6
7
8
docker run -d -p ${frontend_port}:80 \
--name n-${docker_name} \
--privileged=true \
--restart=always \
-v /disk/home/${docker_name}/nginx/www:/usr/share/nginx/html \
-v /disk/home/${docker_name}/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /disk/home/${docker_name}/nginx/logs:/var/log/nginx \
-e TZ=Asia/Shanghai nginx:latest

jar1.8

1
2
3
4
5
6
7
docker run -dit -p ${jar_backend_port}:8080 \
--name j-${docker_name} \
--privileged=true \
--restart=always \
-v /disk/home/${docker_name}/jar:/opt/jar \
-v /disk/home/${docker_name}/uploadPath:/home/${docker_name}/uploadPath \
-v /disk/home/${docker_name}/ureport2:/home/${docker_name}/ureport2 15588855251/jar1.8:3.0

redis

1
2
3
docker run -d --name redis -p 6379:6379 redis:latest \
--restart=always \
--requirepass "system" --appendonly yes

portainer

1
2
3
4
docker run -d -p 9000:9000 \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
--name prtainer docker.io/portainer/portainer

获取容器/镜像的元数据

1
docker inspect [容器名]

拷贝文件到容器内

1
2
拷贝文件到容器内
docker cp [宿主机]/dir/file [虚拟机]:/dir/file

从容器内拷贝文件

1
2
从容器内拷贝文件
docker cp [虚拟机]:/dir/file [宿主机]

开启容器自启动

1
docker update --restart=always [容器名]
updatedupdated2022-04-272022-04-27