docker命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
构建容器
docker build -t getting-started .
(getting-started:容器名字;  .:当前目录; )
 
运行容器
docker run -dp 3000:3000 getting-started
(-dp 3000:3000 主机到容器之间的端口映射3000到3000)
 
查看容器:
docker ps
 
停止运行
docker stop <the-container-id>
 
移除容器
docker rm <the-container-id>
 
停止并移除
docker rm -f <the-container-id>
 
登录
docker login -u shajazy1
 
修改发布的镜像的REPOSITORY为自己的账户名+镜像,比如我的用户名是123456。
docker tag  getting-started  shajazy1/getting-started:1.0
然后发布镜像
docker push shajazy1/getting-started:1.0
 
创建卷
docker volume create todo-db
 
数据库的路径
在etc/todos里 todo.db
 
使用数据库
docker run -dp 3000:3000 --mount type=volume,src=todo-db,target=/etc/todos getting-started
 
 
此目录和docker容器目录的文件相同(用PowerShell执行, 在容器的app
目录(D:\data\code\docker_source\getting-started1\app)下):
docker run -it --mount type=bind,src="$(pwd)",target=/src ubuntu bash
 
创建文件
touch myfile.txt
 
删除文件
rm myfile.txt
 
 
If you are using Windows, then use the following command in PowerShell.
    docker run -dp 3000:3000 `
    -w /app --mount type=bind,src="$(pwd)",target=/app `
    node:18-alpine `
    sh -c "yarn install && yarn run dev"
    即( )
    即( docker run -dp 3000:3000 -wdocker run -dp 3000:3000 -w /app --mount type=bind,src="$(pwd)",target=/app node:18-alpine sh -c "yarn install && yarn run dev"/app --mount type=bind,src="$(123456wst)",target=/app node:18-alpine sh -c "yarn install && yarn run dev")
    即( docker run -dp 3000:3000 '-w /app --mount type=bind,src="$(pwd)",target=/app' 'node:18-alpine ' sh -c "yarn install && yarn run dev")
     
    -dp 3000:3000 - same as before. Run in detached (background) mode and create a port mapping
    -w /app - sets the “working directory” or the current directory that the command will run from
    --mount type=bind,src="$(pwd)",target=/app - bind mount the current directory from the host into the /app directory in the container
    node:18-alpine - the image to use. Note that this is the base image for our app from the Dockerfile
    sh -c "yarn install && yarn run dev" - the command. We’re starting a shell using sh (alpine doesn’t have bash) and running
    yarn install to install packages and then running yarn run dev to start the development server. If we look in the package.json,
    we’ll see that the dev script starts nodemon.
 
 
Create the network.
    docker network create todo-app
 
 
安装mysql(In Windows, run this command in PowerShell.)
docker run -d --network todo-app --network-alias mysql -v todo-mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=todos mysql:8.0
 
检查sql的链接
docker exec -it <mysql-container-id> mysql -u root -p

  

posted @   二维一加零  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示