docker命令

构建容器
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 @ 2023-05-02 00:19  艾特-天空之海  阅读(8)  评论(0编辑  收藏  举报